I'm using jPlayer with the playlist addon. I've been trying to figure out how to share playlists in various ways. Passing the values in a URL seems to be the easiest. Since playlist values are stored in JSON arrays that look, in my case, like this (for 3 tracks):
[{"title":"Name of Song 1","artist":"the artist","mp3":"http//file1.mp3"},{"title":"Name of Song 2","artist":"the artist","mp3":http//file2.mp3"},{"title":"Name of Song 3","artist":"the artist","mp3":"http//file3.mp3"}]
I was wondering if there was a way take this information and encode it into a URL which I could then email to someone. Naturally when the page is loaded jPlayer would have to detect whether or not there was playlist information included in the URL and load the playlist if there was, or load the default/blank plalist if not.
In my attempts to figure this out I discovered that items need to be JSON.stringifyed in order to have them not appear as [object,object] so storing a playlist looks like this:
var savedPlaylist = JSON.stringify(myPlaylist.playlist);
This will give me a variable containing what jPlayer needs to load the playlist.
further tinkering with this lead me to testing it with localStorage whereby playlists could be stored in html5 localStorage by a method like:
$(#playlist-save").click(function(){
localStorage.setItem(JSON.stringify(myPlaylist.playlist);
});
and loaded from localStorage (parsing the JSON back) with:
$("#playlist-load").click(function(){
myPlaylist.setPlaylist(JSON.parse(myPlaylist.playlist);
});
Again, the localStorage is not really what I'm after I just used it to learn more about what the playlists save and load. I can't figure out how to get this functionality to work with a URL.
EDIT: I will not be using a database for this project!!