1

I am working on a media player, and I want to be able to queue local files in an array, play it, and even export it as a playlist (for later import).

I found this question, with a lot of helpful information: Using local file for Web Audio API in Javascript However, the Base64 method would make the playlist too big, and the other solution creates a sandboxed file link (which are deleted from the browser when the session is closed).

Is there any good way to do this?

EDIT: Here's an example of what I want:

var playlist = {'file:///home/user/music/track1.mp3','file:///home/user/music/track2.mp3','file:///home/user/music/track3.mp3'};

It doesn't have to look like this, i just want something similar.

Community
  • 1
  • 1
Jacob Pedersen
  • 347
  • 2
  • 4
  • 12

1 Answers1

0

Why not try localstorage feature on html5. Its helps store data even after the session is expired.

http://www.w3schools.com/html/html5_webstorage.asp

http://diveintohtml5.info/storage.html

What i did in my music player,was store the file data path in the localstorage. And whenever i needed it ,i retrieved it and replaced the current song with the one i wanted.

// Store localStorage.setItem("Path","file:///home/user/music/track1.mp3'");

//Retrieve
currentSong=localStorage.getItem('Path');

For multiple songs,u could create objects and do similar to this: Storing Objects in HTML5 localStorage

Community
  • 1
  • 1
Nevin Madhukar K
  • 3,031
  • 2
  • 25
  • 52
  • Will test this out when I get home! Can i export the full localStorage to a file? I could use this to store the whole playlist. – Jacob Pedersen Feb 21 '14 at 11:08
  • You can transfer the entire object file stored in localStorage as JSON format into a file. Do check the last link i provided. That helped me do my project. :) And do accept my answer if it helped you out. :) – Nevin Madhukar K Feb 21 '14 at 11:09
  • I tried your method ( http://jsfiddle.net/Tv8Cm/56/ ), but I get error "`Not allowed to load local resource: file:///file.mp3`" When trying to load the file. Is there issues with my code? – Jacob Pedersen Feb 21 '14 at 11:38
  • I think you should check this : http://stackoverflow.com/questions/10813408/html5-video-not-playing Am 100% sure,the methode i told will work. Just google when u have future doubts. Its all there. – Nevin Madhukar K Feb 21 '14 at 11:40
  • By the way,if you have further doubts,accept the answer if it helped and create a new question,cause it will be tough answering here in the comments.. – Nevin Madhukar K Feb 21 '14 at 11:49
  • I guess it helped, so have your check :) – Jacob Pedersen Feb 21 '14 at 11:51
  • 1
    Hi there, can you provide working fiddle or link to your player? As i am pretty sure that you can not really reuse saved file path – Max Yari Mar 01 '16 at 22:45