[gnome-music/wip/jfelder/mpris-fix-seek: 1/3] player: Fix seek signal emission



commit ba249f04ac733f2e29a652a6cb2a8ad569389814
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Oct 18 12:07:32 2018 +0200

    player: Fix seek signal emission
    
    Seek operations synchronization between SmoothScale and MPRIS has
    never worked reliably.
    
    With the previous changes, it is now possible to correctly emit a
    seek-finished signal once a seek operation has been requested by
    SmoothScale. MPRIS listens to this signal to emit its own seeked
    signal.
    
    Force SmoothScale position update after a seek operation by directly
    calling update_position_callback. This prevents any delay when the
    seek operation has been performed by an MPRIS client.

 gnomemusic/mpris.py               | 4 ++--
 gnomemusic/player.py              | 5 +++--
 gnomemusic/widgets/smoothscale.py | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index e34dac23..2e8fa183 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -228,7 +228,7 @@ class MediaPlayer2Service(Server):
         self.player.connect('notify::repeat-mode', self._on_repeat_mode_changed)
         self.player.connect('volume-changed', self._on_volume_changed)
         self.player.connect('prev-next-invalidated', self._on_prev_next_invalidated)
-        self.player.connect('seeked', self._on_seeked)
+        self.player.connect('seek-finished', self._on_seek_finished)
         self.player.connect('playlist-changed', self._on_playlist_changed)
         self.player_toolbar = app.get_active_window()._player_toolbar
         self.player_toolbar.connect(
@@ -471,7 +471,7 @@ class MediaPlayer2Service(Server):
         self.player.play()
 
     @log
-    def _on_seeked(self, player, position_second):
+    def _on_seek_finished(self, player, position_second):
         self.Seeked(int(position_second * 1e6))
 
     @log
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index cf56283e..d790018a 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -499,7 +499,7 @@ class Player(GObject.GObject):
         'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int,)),
         'playlist-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
         'prev-next-invalidated': (GObject.SignalFlags.RUN_FIRST, None, ()),
-        'seeked': (GObject.SignalFlags.RUN_FIRST, None, (int,)),
+        'seek-finished': (GObject.SignalFlags.RUN_FIRST, None, (float,)),
         'song-changed': (GObject.SignalFlags.RUN_FIRST, None, (int,)),
         'song-validated': (GObject.SignalFlags.RUN_FIRST, None, (int, int)),
         'volume-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
@@ -636,7 +636,7 @@ class Player(GObject.GObject):
         """
         position = self._player.position
         if position >= 5:
-            self._player.seek(0)
+            self.set_position(0.0)
             return
 
         if self._playlist.previous():
@@ -826,6 +826,7 @@ class Player(GObject.GObject):
         duration_second = self._player.props.duration
         if position_second <= duration_second:
             self._player.seek(position_second)
+            self.emit('seek-finished', position_second)
 
     @log
     def get_volume(self):
diff --git a/gnomemusic/widgets/smoothscale.py b/gnomemusic/widgets/smoothscale.py
index aa607525..701a82be 100644
--- a/gnomemusic/widgets/smoothscale.py
+++ b/gnomemusic/widgets/smoothscale.py
@@ -101,7 +101,7 @@ class SmoothScale(Gtk.Scale):
             self.props.sensitive = True
 
         if state == Playback.PLAYING:
-            self._update_timeout()
+            self._update_position_callback()
         else:
             self._remove_timeout()
 


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