persistent playlist for the media player

This commit is contained in:
Robin Appelman 2011-08-01 01:12:28 +02:00
parent cbf8f822de
commit 76a2f5b547
3 changed files with 28 additions and 1 deletions

View File

@ -47,4 +47,9 @@ $(document).ready(function() {
FileActions.register('application/ogg','','Play',playAudio); FileActions.register('application/ogg','','Play',playAudio);
FileActions.setDefault('audio','Play'); FileActions.setDefault('audio','Play');
FileActions.setDefault('application/ogg','Play'); FileActions.setDefault('application/ogg','Play');
if(typeof localStorage !== 'undefined'){
if(localStorage.hasOwnProperty('oc_playlist_items')){
loadPlayer();
}
}
}); });

View File

@ -41,6 +41,7 @@ $(document).ready(function(){
}); });
row.find('div.name').append(button); row.find('div.name').append(button);
} }
PlayList.init();
}); });

View File

@ -33,11 +33,13 @@ var PlayList={
PlayList.player.jPlayer("setMedia", PlayList.items[PlayList.current]); PlayList.player.jPlayer("setMedia", PlayList.items[PlayList.current]);
PlayList.items[index].playcount++; PlayList.items[index].playcount++;
PlayList.player.jPlayer("play"); PlayList.player.jPlayer("play");
if(Collection){ if (typeof Collection !== 'undefined') {
Collection.registerPlay(); Collection.registerPlay();
} }
} }
}else{ }else{
localStorage.setItem('oc_playlist_current',PlayList.current);
localStorage.setItem('oc_playlist_playing','true');
PlayList.init(PlayList.items[index].type,PlayList.play); PlayList.init(PlayList.items[index].type,PlayList.play);
} }
} }
@ -62,6 +64,7 @@ var PlayList={
ended:PlayList.next, ended:PlayList.next,
supplied:type, supplied:type,
ready:function(){ ready:function(){
PlayList.load();
if(ready){ if(ready){
ready(); ready();
} }
@ -93,6 +96,7 @@ var PlayList={
item[type]=PlayList.urlBase+encodeURIComponent(song.song_path); item[type]=PlayList.urlBase+encodeURIComponent(song.song_path);
PlayList.items.push(item); PlayList.items.push(item);
} }
PlayList.save();
}, },
addFile:function(path){ addFile:function(path){
var type=musicTypeFromFile(path); var type=musicTypeFromFile(path);
@ -116,5 +120,22 @@ var PlayList={
}else{ }else{
return !PlayList.player.data("jPlayer").status.paused; return !PlayList.player.data("jPlayer").status.paused;
} }
},
save:function(){
if(typeof localStorage !== 'undefined'){
localStorage.setItem('oc_playlist_items',JSON.stringify(PlayList.items));
}
},
load:function(){
if(typeof localStorage !== 'undefined'){
if(localStorage.hasOwnProperty('oc_playlist_items')){
PlayList.items=JSON.parse(localStorage.getItem('oc_playlist_items'));
PlayList.current=parseInt((localStorage.getItem('oc_playlist_current')));
if(JSON.parse(localStorage.getItem('oc_playlist_playing'))){
PlayList.play();
}
PlayList.render();
}
}
} }
} }