[gnome-music/wip/mschraal/player-factor-out-gstreamer: 43/56] gstplayer: Don't request duration all the time



commit 87ee2d16a02580cc696ad56c044a08ad7aa8fa06
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Feb 9 16:34:27 2018 +0100

    gstplayer: Don't request duration all the time

 gnomemusic/gstplayer.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index 92aaf30..21491b7 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -74,6 +74,8 @@ class GstPlayer(GObject.GObject):
         self._bus.connect('message::error', self._on_bus_error)
         self._bus.connect('message::element', self._on_bus_element)
         self._bus.connect('message::eos', self._on_bus_eos)
+        self._bus.connect(
+            'message::duration-changed', self._on_duration_changed)
 
     @log
     def _setup_replaygain(self):
@@ -135,6 +137,11 @@ class GstPlayer(GObject.GObject):
         # Gst.State.PAUSED are.
         self.state = self.state
 
+    @log
+    def _on_duration_changed(self, bus, message):
+        self._duration = self._player.query_duration(
+            Gst.Format.TIME)[1] / 10**9
+
     @log
     def _on_bus_element(self, bus, message):
         if GstPbutils.is_missing_plugin_message(message):
@@ -240,9 +247,8 @@ class GstPlayer(GObject.GObject):
     @log
     def duration(self):
         """Total duration in seconds (float)"""
-        duration = self._player.query_duration(Gst.Format.TIME)[1] / 10**9
-        print("duration ", duration)
-        return duration
+        print("duration ", self._duration)
+        return self._duration
 
     @GObject.Property
     @log


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