[gnome-music/wip/mschraal/gapless-v3: 18/18] fix duration



commit 1a14fa7e1ef32ac27cc4302fd31b4a0a01588a20
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Oct 17 15:38:05 2018 +0200

    fix duration
    
    sometimes a 0 duration is sent

 gnomemusic/widgets/playertoolbar.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 3bafbf23..4f131e64 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -83,6 +83,7 @@ class PlayerToolbar(Gtk.ActionBar):
         self._player.connect('clock-tick', self._on_clock_tick)
         self._player.connect('song-changed', self._update_view)
         self._player.connect('prev-next-invalidated', self._sync_prev_next)
+        self._player.connect('notify::duration', self._on_duration_changed)
         self._player.connect('notify::repeat-mode', self._sync_repeat_image)
         self._player.connect('notify::state', self._sync_playing)
 
@@ -148,6 +149,14 @@ class PlayerToolbar(Gtk.ActionBar):
         self._next_button.props.sensitive = self._player.props.has_next
         self._prev_button.props.sensitive = self._player.props.has_previous
 
+    @log
+    def _on_duration_changed(self, klass, data=None):
+        duration = klass.props.duration
+
+        if duration != -1:
+            self._duration_label.set_label(
+                utils.seconds_to_string(int(duration)))
+
     @log
     def _update_view(self, player, position):
         """Updates model when the song changes
@@ -156,10 +165,6 @@ class PlayerToolbar(Gtk.ActionBar):
         :param int position: current song position
         """
         current_song = player.props.current_song
-        duration = player.props.duration
-        if duration != -1:
-            self._duration_label.set_label(
-                utils.seconds_to_string(int(duration)))
 
         self._play_button.set_sensitive(True)
         self._sync_prev_next()


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