[gnome-music/wip/jfelder/mpris-fix-playlist-changes: 2/2] mpris: Correctly listen to player model changes



commit 540297b110b5445ed53d0f4919e09a911319ec70
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Nov 20 20:38:08 2019 +0100

    mpris: Correctly listen to player model changes
    
    This is a follow up and fix of commit
    a65f4439e007a9e0202565afb13ce7ae3447f495.
    
    The MPRIS tracklist (and some other properties) need to be updated in
    two cases:
    - the current song changes
    - the player playlist changes (some songs are added or removed)
    
    Commit a65f4439e007a9e0202565afb13ce7ae3447f495 added the possibility
    to handle the latter case.
    
    However, when a new player playlist is loaded (the user clicks on an
    other album or artist for example), the player playlist is completely
    refreshed. In that corner case, the MPRIS tracklist cannot be updated
    because the player position has not been updated yet. The MPRIS
    tracklist (and the other properties) will be correctly updated once a
    new song is playing (by the _on_current_song_changed method).

 gnomemusic/mpris.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index edfb310f..dc9822a4 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -521,9 +521,14 @@ class MPRIS(DBusInterface):
             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)
+        self._on_player_model_changed(self._player_model, 0, 0, 0)
 
     def _on_player_model_changed(self, model, pos, removed, added):
+        # Do no update the properties if the model has completely changed.
+        # These changes will be applied once a new song starts playing.
+        if added == model.get_n_items():
+            return
+
         self._update_tracklist()
 
         properties = {}


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