]> source.dussan.org Git - nextcloud-server.git/commitdiff
properly save play/pause state of media player
authorRobin Appelman <icewind1991@gmail.com>
Mon, 1 Aug 2011 14:19:51 +0000 (16:19 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Mon, 1 Aug 2011 14:20:15 +0000 (16:20 +0200)
apps/media/js/player.js

index 8ef85f4848e3a17eacbba0e8213d523ba22eadd4..369d3e389c3f84fb4bcd027aad5b8d90d4160050 100644 (file)
@@ -19,7 +19,7 @@ var PlayList={
                PlayList.play(next);
                PlayList.render();
        },
-       play:function(index){
+       play:function(index,ready){
                if(index==null){
                        index=PlayList.current;
                }
@@ -28,13 +28,12 @@ var PlayList={
                        if(PlayList.player){
                                if(PlayList.player.data('jPlayer').options.supplied!=PlayList.items[index].type){//the the audio type changes we need to reinitialize jplayer
                                        PlayList.player.jPlayer("destroy");
-                                       PlayList.init(PlayList.items[index].type,PlayList.play);
+                                       PlayList.init(PlayList.items[index].type,function(){PlayList.play(null,ready)});
                                }else{
                                        PlayList.player.jPlayer("setMedia", PlayList.items[PlayList.current]);
                                        PlayList.items[index].playcount++;
                                        PlayList.player.jPlayer("play");
                                        localStorage.setItem(oc_current_user+'oc_playlist_current',index);
-                                       localStorage.setItem(oc_current_user+'oc_playlist_playing','true');
                                        if(index>0){
                                                var previous=index-1;
                                        }else{
@@ -50,6 +49,9 @@ var PlayList={
                                        if (typeof Collection !== 'undefined') {
                                                Collection.registerPlay();
                                        }
+                                       if(ready){
+                                               ready();
+                                       }
                                }
                        }else{
                                PlayList.init(PlayList.items[index].type,PlayList.play);
@@ -74,6 +76,12 @@ var PlayList={
                }
                $(PlayList.player).jPlayer({
                        ended:PlayList.next,
+                       pause:function(){
+                               localStorage.setItem(oc_current_user+'oc_playlist_playing','false');
+                       },
+                       play:function(){
+                               localStorage.setItem(oc_current_user+'oc_playlist_playing','true');
+                       },
                        supplied:type,
                        ready:function(){
                                PlayList.load();
@@ -145,6 +153,10 @@ var PlayList={
                                PlayList.current=parseInt((localStorage.getItem(oc_current_user+'oc_playlist_current')));
                                if(JSON.parse(localStorage.getItem(oc_current_user+'oc_playlist_playing'))){
                                        PlayList.play();
+                               }else{
+                                       PlayList.play(null,function(){
+                                               PlayList.player.jPlayer("pause");
+                                       });
                                }
                                PlayList.render();
                        }