[gnome-music/wip/jfelder/gstplayer-fix-seek-finished] gstplayer: Correctly emit "seek-finished" signal



commit 962fe7bc139fb456cd20367b6af9cd28c9f74478
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Jun 19 12:26:26 2019 +0200

    gstplayer: Correctly emit "seek-finished" signal
    
    commit 2fa4b6314523282e791310688a930242aa48122d introduced a
    "seek-finished" signal by listening to the reset-time message. The
    problem with this approach lies in the fact that the seek operation is
    not finished. Thus, the position has not been updated yet and returns
    an undefined value.
    
    Fix the issue by moving the signal emission in "_on_async_done"
    method. Indeed, an async-done message is sent once the seek operation
    is finished. A flag is set when requesting a seek operation to avoid
    sending a "seek-finished" signal when an other async operation has
    been performed.

 gnomemusic/gstplayer.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index f53cc142..dc563dff 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -73,6 +73,7 @@ class GstPlayer(GObject.GObject):
 
         self._application = application
         self._duration = -1.
+        self._seek = False
         self._tick = 0
 
         self._missing_plugin_messages = []
@@ -91,7 +92,6 @@ 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)
         self._bus.connect("message::stream-start", self._on_bus_stream_start)
@@ -146,11 +146,11 @@ class GstPlayer(GObject.GObject):
         else:
             self.props.duration = duration
 
-        self.notify('state')
+        if self._seek is True:
+            self._seek = False
+            self.emit("seek-finished")
 
-    @log
-    def _on_reset_time(self, bus, message):
-        self.emit("seek-finished")
+        self.notify('state')
 
     @log
     def _on_new_clock(self, bus, message):
@@ -303,7 +303,7 @@ class GstPlayer(GObject.GObject):
 
         :param float seconds: Position in seconds to seek
         """
-        self._player.seek_simple(
+        self._seek = self._player.seek_simple(
             Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
             seconds * Gst.SECOND)
 


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