prevent multiply owncloud instances on the same domain intefering with each others playlists

This commit is contained in:
Robin Appelman 2012-01-15 19:25:55 +01:00
parent a883fcca3c
commit 15ea83834d
2 changed files with 38 additions and 45 deletions

View File

@ -52,10 +52,8 @@ $(document).ready(function() {
} }
var oc_current_user=OC.currentUser; var oc_current_user=OC.currentUser;
if(typeof PlayList==='undefined'){ if(typeof PlayList==='undefined'){
if(typeof localStorage !== 'undefined' && localStorage){ if(OC.localStorage.getItem('playlist_items') && OC.localStorage.getItem('playlist_items').length && OC.localStorage.getItem('playlist_active')!=true){
if(localStorage.getItem(oc_current_user+'oc_playlist_items') && localStorage.getItem(oc_current_user+'oc_playlist_items')!='[]' && localStorage.getItem(oc_current_user+'oc_playlist_active')!='true'){ loadPlayer();
loadPlayer();
}
} }
} }
}); });

View File

@ -34,7 +34,7 @@ var PlayList={
if(PlayList.player){ if(PlayList.player){
if(PlayList.player.data('jPlayer').options.supplied!=items[index].type){//the the audio type changes we need to reinitialize jplayer if(PlayList.player.data('jPlayer').options.supplied!=items[index].type){//the the audio type changes we need to reinitialize jplayer
PlayList.player.jPlayer("play",time); PlayList.player.jPlayer("play",time);
localStorage.setItem(oc_current_user+'oc_playlist_time',time); OC.localStorage.setItem('playlist_time',time);
PlayList.player.jPlayer("destroy"); PlayList.player.jPlayer("destroy");
// PlayList.save(); // so that the init don't lose the playlist // PlayList.save(); // so that the init don't lose the playlist
PlayList.init(items[index].type,null); // init calls load that calls play PlayList.init(items[index].type,null); // init calls load that calls play
@ -64,9 +64,8 @@ var PlayList={
} }
} }
}else{ }else{
localStorage.setItem(oc_current_user+'oc_playlist_time',time); OC.localStorage.setItem('playlist_time',time);
localStorage.setItem(oc_current_user+'oc_playlist_playing','true'); OC.localStorage.setItem('playlist_playing',true);
// PlayList.save(); // so that the init don't lose the playlist
PlayList.init(items[index].type,null); // init calls load that calls play PlayList.init(items[index].type,null); // init calls load that calls play
} }
} }
@ -92,11 +91,11 @@ var PlayList={
$(PlayList.player).jPlayer({ $(PlayList.player).jPlayer({
ended:PlayList.next, ended:PlayList.next,
pause:function(){ pause:function(){
localStorage.setItem(oc_current_user+'oc_playlist_playing','false'); OC.localStorage.setItem('playlist_playing',false);
document.title = "ownCloud"; document.title = "ownCloud";
}, },
play:function(event){ play:function(event){
localStorage.setItem(oc_current_user+'oc_playlist_playing','true'); OC.localStorage.setItem('playlist_playing',true);
document.title = "\u25b8 " + event.jPlayer.status.media.name + " - " + event.jPlayer.status.media.artist + " - ownCloud"; document.title = "\u25b8 " + event.jPlayer.status.media.name + " - " + event.jPlayer.status.media.artist + " - ownCloud";
}, },
supplied:type, supplied:type,
@ -161,46 +160,42 @@ var PlayList={
} }
}, },
save:function(){ save:function(){
if(typeof localStorage !== 'undefined' && localStorage){ OC.localStorage.setItem('playlist_items',PlayList.items);
localStorage.setItem(oc_current_user+'oc_playlist_items',JSON.stringify(PlayList.items)); OC.localStorage.setItem('playlist_current',PlayList.current);
localStorage.setItem(oc_current_user+'oc_playlist_current',PlayList.current); if(PlayList.player) {
if(PlayList.player) { if(PlayList.player.data('jPlayer')) {
if(PlayList.player.data('jPlayer')) { var time=Math.round(PlayList.player.data('jPlayer').status.currentTime);
var time=Math.round(PlayList.player.data('jPlayer').status.currentTime); OC.localStorage.setItem('playlist_time',time);
localStorage.setItem(oc_current_user+'oc_playlist_time',time); var volume=PlayList.player.data('jPlayer').options.volume*100;
var volume=PlayList.player.data('jPlayer').options.volume*100; OC.localStorage.setItem('playlist_volume',volume);
localStorage.setItem(oc_current_user+'oc_playlist_volume',volume);
}
} }
localStorage.setItem(oc_current_user+'oc_playlist_active','true');
} }
OC.localStorage.setItem('playlist_active',true);
}, },
load:function(){ load:function(){
if(typeof localStorage !== 'undefined' && localStorage){ PlayList.active=true;
PlayList.active=true; OC.localStorage.setItem('playlist_active',true);
localStorage.setItem(oc_current_user+'oc_playlist_active','true'); if(OC.localStorage.hasItem('playlist_items')){
if(localStorage.hasOwnProperty(oc_current_user+'oc_playlist_items')){ PlayList.items=OC.localStorage.getItem('playlist_items');
PlayList.items=JSON.parse(localStorage.getItem(oc_current_user+'oc_playlist_items')); if(PlayList.items && PlayList.items.length>0){
if(PlayList.items.length>0){ PlayList.current=OC.localStorage.getItem('playlist_current');
PlayList.current=parseInt(localStorage.getItem(oc_current_user+'oc_playlist_current')); var time=OC.localStorage.getItem('playlist_time');
var time=parseInt(localStorage.getItem(oc_current_user+'oc_playlist_time')); if(OC.localStorage.hasItem('playlist_volume')){
if(localStorage.hasOwnProperty(oc_current_user+'oc_playlist_volume')){ var volume=OC.localStorage.getItem('playlist_volume');
var volume=localStorage.getItem(oc_current_user+'oc_playlist_volume'); PlayList.volume=volume/100;
PlayList.volume=volume/100; $('.jp-volume-bar-value').css('width',volume+'%');
$('.jp-volume-bar-value').css('width',volume+'%'); if(PlayList.player.data('jPlayer')){
if(PlayList.player.data('jPlayer')){ PlayList.player.jPlayer("option",'volume',volume/100);
PlayList.player.jPlayer("option",'volume',volume/100);
}
} }
if(JSON.parse(localStorage.getItem(oc_current_user+'oc_playlist_playing'))){
PlayList.play(null,time);
}else{
PlayList.play(null,time,function(){
PlayList.player.jPlayer("pause");
});
}
PlayList.render();
} }
if(OC.localStorage.getItem('playlist_playing')){
PlayList.play(null,time);
}else{
PlayList.play(null,time,function(){
PlayList.player.jPlayer("pause");
});
}
PlayList.render();
} }
} }
} }
@ -210,7 +205,7 @@ $(document).ready(function(){
$(window).bind('beforeunload', function (){ $(window).bind('beforeunload', function (){
PlayList.save(); PlayList.save();
if(PlayList.active){ if(PlayList.active){
localStorage.setItem(oc_current_user+'oc_playlist_active','false'); OC.localStorage.setItem('playlist_active',false);
} }
}); });