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.setDefault('audio','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);
}
PlayList.init();
});

View File

@ -33,11 +33,13 @@ var PlayList={
PlayList.player.jPlayer("setMedia", PlayList.items[PlayList.current]);
PlayList.items[index].playcount++;
PlayList.player.jPlayer("play");
if(Collection){
if (typeof Collection !== 'undefined') {
Collection.registerPlay();
}
}
}else{
localStorage.setItem('oc_playlist_current',PlayList.current);
localStorage.setItem('oc_playlist_playing','true');
PlayList.init(PlayList.items[index].type,PlayList.play);
}
}
@ -62,6 +64,7 @@ var PlayList={
ended:PlayList.next,
supplied:type,
ready:function(){
PlayList.load();
if(ready){
ready();
}
@ -93,6 +96,7 @@ var PlayList={
item[type]=PlayList.urlBase+encodeURIComponent(song.song_path);
PlayList.items.push(item);
}
PlayList.save();
},
addFile:function(path){
var type=musicTypeFromFile(path);
@ -116,5 +120,22 @@ var PlayList={
}else{
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();
}
}
}
}