[gnome-music] fix song change when a song reaches its end



commit e5a8e506524a4bea6fbca68d0cf89034cc0b9e94
Author: Guillaume Quintard <guillaume quintard gmail com>
Date:   Wed Apr 24 10:18:49 2013 +0200

    fix song change when a song reaches its end

 src/player.js  |   14 ++++++++------
 src/widgets.js |   44 ++++++++++++++++++++++----------------------
 2 files changed, 30 insertions(+), 28 deletions(-)
---
diff --git a/src/player.js b/src/player.js
index 42abd61..7ee2a88 100644
--- a/src/player.js
+++ b/src/player.js
@@ -89,9 +89,12 @@ const Player = new Lang.Class({
         Gst.init(null, 0);
         this.player = Gst.ElementFactory.make("playbin", "player");
         this.player.connect("about-to-finish", Lang.bind(this,
-            function() {
-               this.playNext();
-                return true;
+               function() {
+                       if (!this.playlist || !this.currentTrack || 
!this.playlist.iter_next(this.currentTrack))
+                               this.currentTrack=null; 
+                       else
+                               this.load( this.playlist.get_value( this.currentTrack, this.playlist_field));
+                       return true;
             }));
         this.bus = this.player.get_bus();
         this.bus.add_signal_watch()
@@ -111,7 +114,7 @@ const Player = new Lang.Class({
     load: function(media) {
         var pixbuf;
 
-        this.emit("song-changed", this.currentTrack);
+        this.emit("playlist-item-changed", this.playlist, this.currentTrack);
 
         this._setDuration(media.get_duration());
         this.song_total_time_lbl.set_label(this.seconds_to_string (media.get_duration()));
@@ -153,6 +156,7 @@ const Player = new Lang.Class({
             this.stop();
         }
         this.load( this.playlist.get_value( this.currentTrack, this.playlist_field));
+
         this.player.set_state(Gst.State.PLAYING);
         this.timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, Lang.bind(this, 
this._updatePositionCallback));
     },
@@ -176,7 +180,6 @@ const Player = new Lang.Class({
                this.currentTrack=null; 
                return;
        }
-        this.emit("playlist-item-changed", this.playlist, this.currentTrack);
        this.stop();
        this.play();
     },
@@ -186,7 +189,6 @@ const Player = new Lang.Class({
                this.stop();
                this.currentTrack=null; 
                return;}
-        this.emit("playlist-item-changed", this.playlist, this.currentTrack);
        this.stop();
        this.play();
     },
diff --git a/src/widgets.js b/src/widgets.js
index 62a76da..434133f 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -136,6 +136,7 @@ const AlbumWidget = new Lang.Class({
        let cachedPlaylist = this.player.runningPlaylist("Album", album);
        if (cachedPlaylist){
                this.model = cachedPlaylist;
+               this.updateModel(cachedPlaylist, this.player.currentTrack);
        } else {
                this.model = Gtk.ListStore.new([
                                GObject.TYPE_STRING, /*title*/
@@ -146,7 +147,6 @@ const AlbumWidget = new Lang.Class({
                                GObject.TYPE_OBJECT, /*song object*/
                                GObject.TYPE_BOOLEAN
                                ]);
-               this.iterToClean = null;
                var tracks = [];
                grilo.getAlbumSongs(item.get_id(), Lang.bind(this, function (source, prefs, track) {
                        if (track != null) {
@@ -176,29 +176,29 @@ const AlbumWidget = new Lang.Class({
         this.ui.get_object("released_label_info").set_text(item.get_creation_date().get_year().toString());
 
         this.player.connect('playlist-item-changed', Lang.bind(this,
-            function(player, playlist, iter) {
-               //this is not our playlist, disregard the signal
-               if (playlist != this.model){
-                       print ("Album and"+type + "  "+this.album + " and "+id);
-                       return true;}
-               if (this.iterToClean){
-                       let item = this.model.get_value(this.iterToClean, 5);
-                       this.model.set_value(this.iterToClean, 0, item.get_title());
-                       // Hide now playing icon
-                       this.model.set_value(this.iterToClean, 3, false);
-               }
-               this.iterToClean = iter.copy(); 
+            function(player, playlist, iter) { this.updateModel(playlist, iter);}
+        ));
+    },
+    updateModel: function(playlist, iter){
+           //this is not our playlist, return
+           if (playlist != this.model){
+                   return true;}
+           if (this.iterToClean){
+                   let item = this.model.get_value(this.iterToClean, 5);
+                   this.model.set_value(this.iterToClean, 0, item.get_title());
+                   // Hide now playing icon
+                   this.model.set_value(this.iterToClean, 3, false);
+           }
+           this.iterToClean = iter.copy();     
 
-               // Highlight currently played song as bold
-               let item = this.model.get_value(iter, 5);
-               this.model.set_value(iter, 0, "<b>" + item.get_title() + "</b>");
-               // Display now playing icon
-               this.model.set_value(iter, 3, true);
+           // Highlight currently played song as bold
+           let item = this.model.get_value(iter, 5);
+           this.model.set_value(iter, 0, "<b>" + item.get_title() + "</b>");
+           // Display now playing icon
+           this.model.set_value(iter, 3, true);
 
-               // reset the previous item, if it exists
-               return true;
-           }
-        ));
+           // reset the previous item, if it exists
+           return true;
     },
 });
 


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