]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix persistent playlist for media player
authorRobin Appelman <icewind1991@gmail.com>
Wed, 28 Sep 2011 20:20:26 +0000 (22:20 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Wed, 28 Sep 2011 20:21:06 +0000 (22:21 +0200)
apps/media/css/player.css [new file with mode: 0644]
apps/media/js/loader.js
apps/media/js/player.js
apps/media/js/playlist.js
apps/media/templates/music.php
apps/media/templates/player.php [new file with mode: 0644]
files/js/fileactions.js

diff --git a/apps/media/css/player.css b/apps/media/css/player.css
new file mode 100644 (file)
index 0000000..265b305
--- /dev/null
@@ -0,0 +1,19 @@
+#playercontrols{
+       display:inline;
+       width:7em;
+       height:1em;
+       position:fixed;
+       top:auto;
+       left:auto;
+       background:transparent;
+       box-shadow:none;
+       -webkit-box-shadow:none;
+}
+#playercontrols li{
+       float:left;
+}
+#playercontrols a, #playercontrols li{
+       margin:0px;
+       padding:0;
+       left:0;
+}
\ No newline at end of file
index c6c834d3a31007ac500c7ce987730a60d2d0aa27..dff4163897f29c643dd9dc4f0582683162327e06 100644 (file)
@@ -22,16 +22,17 @@ function addAudio(filename){
 
 function loadPlayer(type,ready){
        if(!loadPlayer.done){
+               loadPlayer.done=true;
+               OC.addStyle('media','player');
                OC.addScript('media','jquery.jplayer.min',function(){
                        OC.addScript('media','player',function(){
-                               $('body').append($('<div id="playerPlaceholder"/>'))
-                               $('#playerPlaceholder').append($('<div/>')).load(OC.filePath('media','templates','player.php'),function(){
-                                       loadPlayer.done=true;
+                               var navItem=$('#apps a[href="'+OC.linkTo('media','index.php')+'"]');
+                               navItem.height(navItem.height());
+                               navItem.load(OC.filePath('media','templates','player.php'),function(){
                                        PlayList.init(type,ready);
                                });
                        });
                });
-               OC.addStyle('media','player');
        }else{
                ready();
        }
index 693bf2d70bf6c41caa2e33a559509e82ee74da15..b3eb527870552d458cf6e90ee4de57149dd32619 100644 (file)
@@ -28,18 +28,19 @@ var PlayList={
                if(index==null){
                        index=PlayList.current;
                }
+               PlayList.save();
                if(index>-1 && index<items.length){
                        PlayList.current=index;
                        if(PlayList.player){
                                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);
-                    localStorage.setItem(oc_current_user+'oc_playlist_time',time);
+                                       localStorage.setItem(oc_current_user+'oc_playlist_time',time);
                                        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
                                }else{
                                        PlayList.player.jPlayer("setMedia", items[PlayList.current]);
-                                        $(".jp-current-song").text(items[PlayList.current].name);
+                                       $(".jp-current-song").text(items[PlayList.current].name);
                                        items[index].playcount++;
                                        PlayList.player.jPlayer("play",time);
                                        if(index>0){
@@ -57,6 +58,7 @@ var PlayList={
                                        if (typeof Collection !== 'undefined') {
                                                Collection.registerPlay();
                                        }
+                                       PlayList.render();
                                        if(ready){
                                                ready();
                                        }
@@ -64,12 +66,12 @@ var PlayList={
                        }else{
                                localStorage.setItem(oc_current_user+'oc_playlist_time',time);
                                localStorage.setItem(oc_current_user+'oc_playlist_playing','true');
-                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
                        }
                }
-                $(".song").removeClass("collection_playing");
-                $(".jp-playlist-" + index).addClass("collection_playing");
+               $(".song").removeClass("collection_playing");
+               $(".jp-playlist-" + index).addClass("collection_playing");
        },
        init:function(type,ready){
                if(!PlayList.player){
@@ -85,7 +87,7 @@ var PlayList={
                                PlayList.render();
                                return false;
                        });
-                       PlayList.player=$('#controls div.player');
+                       PlayList.player=$('#jp-player');
                }
                $(PlayList.player).jPlayer({
                        ended:PlayList.next,
@@ -103,7 +105,7 @@ var PlayList={
                                }
                        },
                        volume:PlayList.volume,
-                       cssSelectorAncestor:'#controls',
+                       cssSelectorAncestor:'.player-controls',
                        swfPath:OC.linkTo('media','js'),
                });
        },
@@ -130,7 +132,7 @@ var PlayList={
                        var type=musicTypeFromFile(song.path);
                        var item={name:song.name,type:type,artist:song.artist,album:song.album,length:song.length,playcount:song.playCount};
                        item[type]=PlayList.urlBase+encodeURIComponent(song.path);
-            PlayList.items.push(item);
+                       PlayList.items.push(item);
                }
        },
        addFile:function(path){
@@ -160,14 +162,14 @@ var PlayList={
                if(typeof localStorage !== 'undefined' && localStorage){
                        localStorage.setItem(oc_current_user+'oc_playlist_items',JSON.stringify(PlayList.items));
                        localStorage.setItem(oc_current_user+'oc_playlist_current',PlayList.current);
-            if(PlayList.player) {
-                if(PlayList.player.data('jPlayer')) {
-                    var time=Math.round(PlayList.player.data('jPlayer').status.currentTime);
-                    localStorage.setItem(oc_current_user+'oc_playlist_time',time);
-                    var volume=PlayList.player.data('jPlayer').options.volume*100;
-                    localStorage.setItem(oc_current_user+'oc_playlist_volume',volume);
-                }
-            }
+                       if(PlayList.player) {
+                               if(PlayList.player.data('jPlayer')) {
+                                       var time=Math.round(PlayList.player.data('jPlayer').status.currentTime);
+                                       localStorage.setItem(oc_current_user+'oc_playlist_time',time);
+                                       var volume=PlayList.player.data('jPlayer').options.volume*100;
+                                       localStorage.setItem(oc_current_user+'oc_playlist_volume',volume);
+                               }
+                       }
                        if(PlayList.active){
                                localStorage.setItem(oc_current_user+'oc_playlist_active','false');
                        }
index c6dc3db2dd40c3b75b9d7eb5e1ff0b0d3dd84aa9..57180b3be7b6323742105a896ad0e043f58e35fe 100644 (file)
@@ -30,6 +30,7 @@ PlayList.hide=function(){
 
 $(document).ready(function(){
        PlayList.parent=$('#leftcontent');
+       PlayList.init();
        $('#selectAll').click(function(){
                if($(this).attr('checked')){
                        // Check all
index 2af18fb03c9f1ea27302b85237426ca789d44ae9..7764a315a8f43c1b55eebb7385cefc9e98275726 100644 (file)
@@ -1,4 +1,4 @@
-<div id="controls">
+<div class='player-controls' id="controls">
        <ul class="jp-controls">
                <li><a href="#" class="jp-play action"><img class="svg" alt="<?php echo $l->t('Play');?>" src="<?php echo image_path('core', 'actions/play-big.svg'); ?>" /></a></li>
                <li><a href="#" class="jp-pause action"><img class="svg" alt="<?php echo $l->t('Pause');?>" src="<?php echo image_path('core', 'actions/pause-big.svg'); ?>" /></a></li>
diff --git a/apps/media/templates/player.php b/apps/media/templates/player.php
new file mode 100644 (file)
index 0000000..342efb8
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+if(!isset($_)){//allow the template to be loaded standalone
+       require_once '../../../lib/base.php';
+       $tmpl = new OC_Template( 'media', 'player');
+       $tmpl->printPage();
+       exit;
+}
+?>
+<div class='player-controls' id="playercontrols">
+       <div class="player" id="jp-player"></div>
+       <ul class="jp-controls">
+               <li><a href="#" class="jp-play action"><img class="svg" alt="<?php echo $l->t('Play');?>" src="<?php echo image_path('core', 'actions/play.svg'); ?>" /></a></li>
+               <li><a href="#" class="jp-pause action"><img class="svg" alt="<?php echo $l->t('Pause');?>" src="<?php echo image_path('core', 'actions/pause.svg'); ?>" /></a></li>
+               <li><a href="#" class="jp-next action"><img class="svg" alt="<?php echo $l->t('Next');?>" src="<?php echo image_path('core', 'actions/play-next.svg'); ?>" /></a></li>
+       </ul>
+</div>
\ No newline at end of file
index 4ff8562fef3bcbf3af21f0b6bced2d8bf8042ee5..ddb16ecd5fd4391fbb8f6dba369c418b6ed45ffc 100644 (file)
@@ -53,7 +53,7 @@ FileActions={
        },
        display:function(parent){
                FileActions.currentFile=parent;
-               $('.action').remove();
+               $('#fileList .action').remove();
                var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType());
                var file=FileActions.getCurrentFile();
                if($('tr[data-file="'+file+'"]').data('renaming')){
@@ -104,12 +104,12 @@ FileActions={
                        });
                        parent.parent().children().last().append(element);
                }
-               $('.action').hide();
-               $('.action').fadeIn(200);
+               $('#fileList .action').hide();
+               $('#fileList .action').fadeIn(200);
                return false;
        },
        hide:function(){
-               $('.action').fadeOut(200,function(){
+               $('#fileList .action').fadeOut(200,function(){
                        $(this).remove();
                });
        },