[gnome-music/wip/jfelder/mpris-seek: 7/7] mpris: Limit Seeked signal emissions



commit c192323deb73801ed4a52ccc86e2e196fb2e0cfb
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Apr 16 16:15:53 2019 +0200

    mpris: Limit Seeked signal emissions
    
    According to MPRIS specifications, the Seeked signal should only be
    sent when the position has changed in a way that is inconsistant with
    the current playing state (for example, when the song position has
    been changed by SmoothScale).
    
    This issue is fixed by storing the song position every time a request
    is made and emit a Seeked signal if the difference between the new and
    the previous position is greater than 2 seconds (It seems like a good
    default value).
    
    Related: #43

 gnomemusic/mpris.py | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 60c58989..8c77101c 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -240,6 +240,7 @@ class MediaPlayer2Service(Server):
         self._path_list = []
         self._metadata_list = []
         self._previous_playback_status = "Stopped"
+        self._song_position = 0
 
     @log
     def _get_playback_status(self):
@@ -610,6 +611,13 @@ class MediaPlayer2Service(Server):
 
         :param int position_msecond: new position in microseconds.
         """
+        # Only send the signal when the position has changed in a way
+        # that is inconsistant with the current playing state
+        if abs(position_msecond - self._song_position) < 2e6:
+            self._song_position = position_msecond
+            return
+
+        self._song_position = position_msecond
         variant = GLib.Variant.new_tuple(GLib.Variant('x', position_msecond))
         self.con.emit_signal(
             None, '/org/mpris/MediaPlayer2',


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