[gnome-music/wip/jfelder/mpris-fix-playlist-changes: 1/2] mpris: Listen to the player model changes once a song is playing



commit a79deab13c97cb9df57309eca9c6f8df9b864905
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Nov 20 23:23:50 2019 +0100

    mpris: Listen to the player model changes once a song is playing
    
    If the "items-changed" signal from the player model is connected
    before the model is populated, the MPRIS tracklist will be populated
    with a list of empty track the first time it is filled. Indeed, the
    current song property from the player has not been set yet.
    
    Fix the issue by connecting this signal once the first song starts
    playing.

 gnomemusic/mpris.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 9792e1ea..edfb310f 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -293,8 +293,7 @@ class MPRIS(DBusInterface):
 
         self._coremodel = app.props.coremodel
         self._player_model = self._coremodel.props.playlist_sort
-        self._player_model.connect(
-            "items-changed", self._on_player_model_changed)
+        self._player_model_changed_id = None
 
         self._coremodel.connect(
             "playlist-loaded", self._on_player_playlist_changed)
@@ -518,6 +517,10 @@ class MPRIS(DBusInterface):
             if self._previous_can_play is True:
                 return
 
+        if self._player_model_changed_id is None:
+            self._player_model_changed_id = self._player_model.connect_after(
+                "items-changed", self._on_player_model_changed)
+
         self._on_player_model_changed(None, 0, 0, 0)
 
     def _on_player_model_changed(self, model, pos, removed, added):


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