[vlc-commits] commit: http-interface: - changed logic so playlist is only downloaded initially and on modification of playlist (Mark Hassman )

git at videolan.org git at videolan.org
Wed Jul 28 20:01:30 CEST 2010


vlc | branch: master | Mark Hassman <mark at hassman.org> | Wed Jul 28 13:08:53 2010 -0400| [8c2137907018ca0ae441a1d0e12b736cc3542d2d] | committer: Ilkka Ollakka 

http-interface: - changed logic so playlist is only downloaded initially and on modification of playlist

no longer re-downloads playlist on each item change (this was causing
significant delays (>10sec) in the http service with large playlists).. now,
the playlist UI is updated locally based on information returned from
status.xml

Signed-off-by: Ilkka Ollakka <ileoo at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8c2137907018ca0ae441a1d0e12b736cc3542d2d
---

 share/http/js/functions.js |   88 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 81 insertions(+), 7 deletions(-)

diff --git a/share/http/js/functions.js b/share/http/js/functions.js
index f259542..9ecce15 100644
--- a/share/http/js/functions.js
+++ b/share/http/js/functions.js
@@ -279,6 +279,14 @@ function clear_children( elt )
         while( elt.hasChildNodes() )
             elt.removeChild( elt.firstChild );
 }
+function playlist_populated()
+{
+    if( document.getElementById( 'playtree' ) != null && document.getElementById( 'playtree' ).childElementCount > 0 )
+    {
+        return true;
+    }
+    return false;
+}
 
 /**********************************************************************
  * Interface actions
@@ -332,22 +340,22 @@ function pl_previous()
 function pl_delete( id )
 {
     loadXMLDoc( 'requests/status.xml?command=pl_delete&id='+id, parse_status );
-    setTimeout( 'update_playlist()', 1000 );
+    setTimeout( 'update_playlist(true)', 1000 );
 }
 function pl_empty()
 {
     loadXMLDoc( 'requests/status.xml?command=pl_empty', parse_status );
-    setTimeout( 'update_playlist()', 1000 );
+    setTimeout( 'update_playlist(true)', 1000 );
 }
 function pl_sort( sort, order )
 {
     loadXMLDoc( 'requests/status.xml?command=pl_sort&id='+order+'&val='+sort, parse_status );
-    setTimeout( 'update_playlist()', 1000 );
+    setTimeout( 'update_playlist(true)', 1000 );
 }
 function pl_shuffle()
 {
     loadXMLDoc( 'requests/status.xml?command=pl_random', parse_status );
-    setTimeout( 'update_playlist()', 1000 );
+    setTimeout( 'update_playlist(true)', 1000 );
 }
 function pl_loop()
 {
@@ -395,9 +403,16 @@ function update_status()
         loadXMLDoc( 'requests/status.xml', parse_status );
     }
 }
-function update_playlist()
+function update_playlist(force_refresh)
 {
-    loadXMLDoc( 'requests/playlist.xml', parse_playlist );
+    if( force_refresh || !playlist_populated() )
+    {
+        loadXMLDoc( 'requests/playlist.xml', parse_playlist );
+    }
+    else
+    {
+        loadXMLDoc( 'requests/status.xml', update_playlist_view );
+    }
 }
 
 /**********************************************************************
@@ -598,7 +613,7 @@ function parse_playlist()
                         var nowplaying = document.getElementById( 'nowplaying' );
                         clear_children( nowplaying );
                         nowplaying.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
-                        pl.appendChild( document.createTextNode( '* '));
+                        pl.appendChild( document.createTextNode( '' ));
                         pl_cur_id = elt.getAttribute( 'id' );
                     }
                     pl.setAttribute( 'title', elt.getAttribute( 'uri' ));
@@ -704,6 +719,65 @@ function parse_browse_dir( )
     }
 }
 
+/* updates playlist to display active entry */
+function update_playlist_view ()
+{
+    if( req.readyState == 4 ) {
+        if( req.status == 200 ) {
+            var status = req.responseXML.documentElement;
+            var title = status.getElementsByTagName( 'title' );
+            if( title.length > 0 ) {
+                title = title[0].firstChild.data;
+
+                //update now-playing..
+                var nowplaying = document.getElementById( 'nowplaying' );
+                clear_children( nowplaying );
+                nowplaying.appendChild( document.createTextNode( title ) );
+
+                //update playlist..
+                var playtree = document.getElementById( 'playtree' );
+                if( playtree.hasChildNodes() )
+                {
+                    var root = playtree.firstChild;  //root div
+                    if( root.hasChildNodes() )
+                    {
+                        for( var i = 0; i < root.childNodes.length - 1; i++ )
+                        {
+                            if ( root.childNodes[i].className == "pl_node" && root.childNodes[i].hasChildNodes() )
+                            {
+                                var node = root.childNodes[i];  //pl_node
+                                if( node.className == "pl_node" && node.hasChildNodes() )
+                                {
+                                    for( var j = 0; j < node.childNodes.length - 1; j++ )
+                                    {
+                                        if( node.childNodes[j].className == "pl_leaf" )
+                                        {
+                                            var leaf = node.childNodes[j];  //pl_leaf
+                                            var pl_title = leaf.textContent.substring( 0, leaf.textContent.length - leaf.text.length )
+                                            //if( leaf.style.fontWeight == "bold" && pl_title.substring(0, 2) == "* " )  //handle leaf currently identified as playing..
+                                            //{
+                                            //    pl_title = pl_title.substring(2);
+                                            //}
+                                            if( pl_title == title )
+                                            {
+                                                leaf.style.fontWeight = "bold";
+                                            }
+                                            else
+                                            {
+                                                leaf.style.fontWeight = "";
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
 /**********************************************************************
  * Input dialog functions
  *********************************************************************/



More information about the vlc-commits mailing list