core,playbin: Generate basic meta-data on external URI change
authorJens Georg <mail@jensge.org>
Thu, 14 Jun 2012 08:58:59 +0000 (10:58 +0200)
committerJens Georg <mail@jensge.org>
Tue, 3 Jul 2012 07:53:48 +0000 (09:53 +0200)
src/plugins/playbin/rygel-playbin-player.vala
src/rygel/rygel-av-transport.vala

index a8f1f32..3ee329b 100644 (file)
@@ -316,6 +316,7 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
                             // uri changed externally
                             this._uri = this.playbin.uri;
                             this.notify_property("uri");
+                            this.metadata = this.generate_basic_didl ();
                         }
                     }
                 }
@@ -382,4 +383,24 @@ public class Rygel.Playbin.Player : GLib.Object, Rygel.MediaPlayer {
     private void on_uri_notify (ParamSpec pspec) {
         this.uri_update_hint = true;
     }
+
+    /**
+     * Generate basic DIDLLite information.
+     *
+     * This is used when the URI gets changed externally. DLNA requires that a
+     * minimum DIDLLite is always present if the URI is not empty.
+     */
+    private string generate_basic_didl () {
+        var writer = new DIDLLiteWriter (null);
+        var item = writer.add_item ();
+        item.id = "1";
+        item.parent_id = "-1";
+        item.upnp_class = "object.item";
+        var resource = item.add_resource ();
+        resource.uri = this._uri;
+        var file = File.new_for_uri (this.uri);
+        item.title = file.get_basename ();
+
+        return writer.get_string ();
+    }
 }
index 6d929e2..5f346fe 100644 (file)
@@ -76,7 +76,6 @@ internal class Rygel.AVTransport : Service {
         set {
             this._metadata = value;
             this.player.metadata = value;
-            this.changelog.log ("CurrentTrackMetadata", this.metadata);
         }
     }
 
@@ -162,6 +161,7 @@ internal class Rygel.AVTransport : Service {
         this.player.notify["playback-state"].connect (this.notify_state_cb);
         this.player.notify["duration"].connect (this.notify_duration_cb);
         this.player.notify["uri"].connect (this.notify_uri_cb);
+        this.player.notify["metadata"].connect (this.notify_meta_data_cb);
 
         this.session = new SessionAsync ();
     }
@@ -561,4 +561,9 @@ internal class Rygel.AVTransport : Service {
         this.changelog.log ("CurrentTrackURI", this.uri);
         this.changelog.log ("AVTransportURI", this.uri);
     }
+
+    private void notify_meta_data_cb (Object player, ParamSpec p) {
+        this._metadata = this.player.metadata;
+        this.changelog.log ("CurrentTrackMetadata", this.metadata);
+    }
 }