]> source.dussan.org Git - nextcloud-server.git/commitdiff
remember volume and playback time in the media player
authorRobin Appelman <icewind1991@gmail.com>
Mon, 1 Aug 2011 14:43:02 +0000 (16:43 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Mon, 1 Aug 2011 14:43:02 +0000 (16:43 +0200)
apps/media/ajax/api.php
apps/media/js/player.js

index e0183ff05de8f7cab45c210699c8e3d5c647f132..bf1ebd8e4d1dac497e0cf47b767d2b4ca41d23fb 100644 (file)
@@ -132,6 +132,7 @@ if($arguments['action']){
                        header('Expires: 0');
                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                        header('Pragma: public');
+                       header('Accept-Ranges: bytes');
                        header('Content-Length: '.OC_Filesystem::filesize($arguments['path']));
                        
                        OC_Filesystem::readfile($arguments['path']);
index 369d3e389c3f84fb4bcd027aad5b8d90d4160050..b6d3bc01ddbe1989d2a89c4ad4f4f7cafd011c72 100644 (file)
@@ -3,6 +3,7 @@ var PlayList={
        current:-1,
        items:[],
        player:null,
+       volume:0.8,
        next:function(){
                var next=PlayList.current+1;
                if(next>=PlayList.items.length){
@@ -19,7 +20,7 @@ var PlayList={
                PlayList.play(next);
                PlayList.render();
        },
-       play:function(index,ready){
+       play:function(index,time,ready){
                if(index==null){
                        index=PlayList.current;
                }
@@ -28,11 +29,11 @@ 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,function(){PlayList.play(null,ready)});
+                                       PlayList.init(PlayList.items[index].type,function(){PlayList.play(null,time,eady)});
                                }else{
                                        PlayList.player.jPlayer("setMedia", PlayList.items[PlayList.current]);
                                        PlayList.items[index].playcount++;
-                                       PlayList.player.jPlayer("play");
+                                       PlayList.player.jPlayer("play",time);
                                        localStorage.setItem(oc_current_user+'oc_playlist_current',index);
                                        if(index>0){
                                                var previous=index-1;
@@ -82,6 +83,14 @@ var PlayList={
                        play:function(){
                                localStorage.setItem(oc_current_user+'oc_playlist_playing','true');
                        },
+                       timeupdate:function(){
+                               var time=Math.round(PlayList.player.data('jPlayer').status.currentTime);
+                               localStorage.setItem(oc_current_user+'oc_playlist_time',time);
+                       },
+                       volumechange:function(){
+                               var volume=PlayList.player.data('jPlayer').options.volume*100;
+                               localStorage.setItem(oc_current_user+'oc_playlist_volume',volume);
+                       },
                        supplied:type,
                        ready:function(){
                                PlayList.load();
@@ -89,6 +98,7 @@ var PlayList={
                                        ready();
                                }
                        },
+                       volume:PlayList.volume,
                        cssSelectorAncestor:'#jp-interface',
                        swfPath:OC.linkTo('media','js'),
                });
@@ -150,11 +160,20 @@ var PlayList={
                if(typeof localStorage !== 'undefined'){
                        if(localStorage.hasOwnProperty(oc_current_user+'oc_playlist_items')){
                                PlayList.items=JSON.parse(localStorage.getItem(oc_current_user+'oc_playlist_items'));
-                               PlayList.current=parseInt((localStorage.getItem(oc_current_user+'oc_playlist_current')));
+                               PlayList.current=parseInt(localStorage.getItem(oc_current_user+'oc_playlist_current'));
+                               var time=parseInt(localStorage.getItem(oc_current_user+'oc_playlist_time'));
+                               if(localStorage.hasOwnProperty(oc_current_user+'oc_playlist_volume')){
+                                       var volume=localStorage.getItem(oc_current_user+'oc_playlist_volume');
+                                       PlayList.volume=volume/100;
+                                       $('.jp-volume-bar-value').css('width',volume+'%');
+                                       if(PlayList.player.data('jPlayer')){
+                                               PlayList.player.jPlayer("option",'volume',volume/100);
+                                       }
+                               }
                                if(JSON.parse(localStorage.getItem(oc_current_user+'oc_playlist_playing'))){
-                                       PlayList.play();
+                                       PlayList.play(null,time);
                                }else{
-                                       PlayList.play(null,function(){
+                                       PlayList.play(null,time,function(){
                                                PlayList.player.jPlayer("pause");
                                        });
                                }