[gnome-music/wip/jfelder/player-seeked-finished-signal: 2/2] player: Fix signal emission after a seek operation



commit 2fa4b6314523282e791310688a930242aa48122d
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Jun 6 18:38:41 2019 +0200

    player: Fix signal emission after a seek operation
    
    As the seek_simple operation is asynchronous, the seek-finished signal
    cannot directly be emitted by the Player.
    
    Fix the issue by listening to the reset-time message in
    GstPlayer. This message is sent once the seek_simple operation is
    finished. The seek-finished signal is then transmitted to the Player.

 gnomemusic/gstplayer.py | 9 +++++++--
 gnomemusic/player.py    | 7 ++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index 5949253e..2265ae7a 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -51,7 +51,8 @@ class GstPlayer(GObject.GObject):
     """
     __gsignals__ = {
         'eos': (GObject.SignalFlags.RUN_FIRST, None, ()),
-        'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int, ))
+        'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int, )),
+        'seek-finished': (GObject.SignalFlags.RUN_FIRST, None, ())
     }
 
     def __repr__(self):
@@ -86,6 +87,7 @@ class GstPlayer(GObject.GObject):
         self._bus.connect('message::async-done', self._on_async_done)
         self._bus.connect('message::error', self._on_bus_error)
         self._bus.connect('message::element', self._on_bus_element)
+        self._bus.connect('message::reset-time', self._on_reset_time)
         self._bus.connect('message::eos', self._on_bus_eos)
         self._bus.connect('message::new-clock', self._on_new_clock)
 
@@ -135,6 +137,10 @@ class GstPlayer(GObject.GObject):
 
         self.notify('state')
 
+    @log
+    def _on_reset_time(self, bus, message):
+        self.emit("seek-finished")
+
     @log
     def _on_new_clock(self, bus, message):
         clock = message.parse_new_clock()
@@ -275,7 +281,6 @@ class GstPlayer(GObject.GObject):
 
         :param float seconds: Position in seconds to seek
         """
-        # FIXME: seek should be signalled to MPRIS
         self._player.seek_simple(
             Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
             seconds * Gst.SECOND)
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index f23ed5e1..3e42d2aa 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -579,6 +579,7 @@ class Player(GObject.GObject):
         self._gst_player = GstPlayer(application)
         self._gst_player.connect('clock-tick', self._on_clock_tick)
         self._gst_player.connect('eos', self._on_eos)
+        self._gst_player.connect('seek-finished', self._on_seek_finished)
         self._gst_player.bind_property(
             'duration', self, 'duration', GObject.BindingFlags.SYNC_CREATE)
         self._gst_player.bind_property(
@@ -878,7 +879,6 @@ class Player(GObject.GObject):
         duration_second = self._gst_player.props.duration
         if position_second <= duration_second:
             self._gst_player.seek(position_second)
-            self.emit('seek-finished')
 
     @log
     def get_mpris_playlist(self):
@@ -892,3 +892,8 @@ class Player(GObject.GObject):
         :rtype: list of index and Grl.Media
         """
         return self._playlist.get_mpris_playlist()
+
+    @log
+    def _on_seek_finished(self, klass):
+        # FIXME: Just a proxy
+        self.emit('seek-finished')


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