[rygel/wip/didl-s: 25/25] renderer: Fix end-of-list behavior



commit a45dc0bef3f367126881e25d44f45cb822a3b7a0
Author: Jens Georg <jensg openismus com>
Date:   Tue Nov 20 17:10:17 2012 +0100

    renderer: Fix end-of-list behavior

 src/librygel-renderer/rygel-av-transport.vala     |   17 ++++++++--
 src/librygel-renderer/rygel-playlist-handler.vala |   32 ++++++++++++++++----
 2 files changed, 38 insertions(+), 11 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-av-transport.vala b/src/librygel-renderer/rygel-av-transport.vala
index 83fc111..ce3b1f2 100644
--- a/src/librygel-renderer/rygel-av-transport.vala
+++ b/src/librygel-renderer/rygel-av-transport.vala
@@ -642,6 +642,8 @@ internal class Rygel.AVTransport : Service {
     }
 
     private void next_cb (Service service, ServiceAction action) {
+        // DLNA leaves us two options here, bail out with error 711 or just
+        // ignore it on EOL. We chose the latter.
         if (this.playlist_handler != null) {
             this.playlist_handler.next ();
             action.return ();
@@ -651,6 +653,8 @@ internal class Rygel.AVTransport : Service {
     }
 
     private void previous_cb (Service service, ServiceAction action) {
+        // DLNA leaves us two options here, bail out with error 711 or just
+        // ignore it on BOL. We chose the latter.
         if (this.playlist_handler != null) {
             this.playlist_handler.previous ();
             action.return ();
@@ -672,9 +676,12 @@ internal class Rygel.AVTransport : Service {
 
                 return;
             } else {
-                debug ("=> Setting next playlist item");
-                // Get next playlist item
-                this.playlist_handler.next ();
+                // Set next playlist item
+                if (!this.playlist_handler.next ()) {
+                    // We were at the end of the list; as per DLNA, move to
+                    // STOPPED and let current track be 1.
+                    this.playlist_handler.reset ();
+                }
             }
         } else {
             this.changelog.log ("TransportState", state);
@@ -727,7 +734,9 @@ internal class Rygel.AVTransport : Service {
             return;
         }
 
-        this.playlist_handler = new PlaylistHandler (collection, this);
+        this.playlist_handler = new PlaylistHandler (collection,
+                                                     this,
+                                                     this.player);
 
         action.return ();
     }
diff --git a/src/librygel-renderer/rygel-playlist-handler.vala b/src/librygel-renderer/rygel-playlist-handler.vala
index 274956e..23149ae 100644
--- a/src/librygel-renderer/rygel-playlist-handler.vala
+++ b/src/librygel-renderer/rygel-playlist-handler.vala
@@ -7,16 +7,22 @@ internal class Rygel.PlaylistHandler : GLib.Object {
 
     public MediaCollection collection { construct; private get; }
     public unowned AVTransport transport { construct; private get; }
+    public unowned MediaPlayer player { construct; private get; }
     public uint current_track { construct set; get; default = 1; }
 
+    public uint size { get { return items.length (); } }
+
     private List<DIDLLiteItem> items;
     private uint timeout_id;
     private uint default_image_timeout;
     private Configuration config;
 
     public PlaylistHandler (MediaCollection collection,
-                            AVTransport     transport) {
-        Object (collection : collection, transport : transport);
+                            AVTransport     transport,
+                            MediaPlayer     player) {
+        Object (collection : collection,
+                transport : transport,
+                player : player);
     }
 
     public override void constructed () {
@@ -30,28 +36,32 @@ internal class Rygel.PlaylistHandler : GLib.Object {
         this.set_track ();
     }
 
-    public void next () {
+    public bool next () {
         this.current_track++;
         if (this.current_track > this.items.length ()) {
             debug ("Ignoring next, end of list: %u", this.items.length ());
             this.current_track = this.items.length ();
 
-            return;
+            return false;
         }
 
         this.set_track ();
+
+        return true;
     }
 
-    public void previous () {
+    public bool previous () {
         this.current_track--;
         if (this.current_track < 1) {
             debug ("Ignoring previous, beginning of list.");
             this.current_track = 1;
 
-            return;
+            return false;
         }
 
         this.set_track ();
+
+        return true;
     }
 
     public void set_track () {
@@ -78,13 +88,21 @@ internal class Rygel.PlaylistHandler : GLib.Object {
 
             this.timeout_id = Timeout.add_seconds ((uint) timeout, () => {
                 this.timeout_id = 0;
-                this.next ();
+                if (!this.next ()) {
+                    this.reset ();
+                }
 
                 return false;
             });
         }
     }
 
+    public void reset () {
+        this.player.playback_state = "STOPPED";
+        this.current_track = 1;
+        this.set_track ();
+    }
+
     private void on_setting_changed (string section, string key) {
         if (section != CONFIG_SECTION && key != TIMEOUT_KEY) {
             return;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]