]> source.dussan.org Git - nextcloud-server.git/commitdiff
persistent playlist for the media player
authorRobin Appelman <icewind1991@gmail.com>
Sun, 31 Jul 2011 23:12:28 +0000 (01:12 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Sun, 31 Jul 2011 23:12:28 +0000 (01:12 +0200)
apps/media/js/files.js
apps/media/js/music.js
apps/media/js/player.js

index 307c6012a263c2ba008a418f5fdfdc7cb25291e9..79741e197036d0bd90a744056d08e6dcde61b40f 100644 (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();
+               }
+       }
 });
\ No newline at end of file
index 3dee87744fe79e5bbb3fd7f7c92b97eef9029c8e..90b5a098002e6b86b4fce72bb53af6a90330bcfe 100644 (file)
@@ -41,6 +41,7 @@ $(document).ready(function(){
                });
                row.find('div.name').append(button);
        }
+       PlayList.init();
 });
 
 
index 1243f20b8ed5d972bc7d0eee580fe9e2c635b67f..d79d6135df2e20a7ac76b05a7ee043855f290671 100644 (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();
+                       }
+               }
        }
 }