[gnome-music/wip/jfelder/mpris-seek: 2/4] mpris: Listen to state changes to update song position



commit 957d9a4f532359cb1a63a53463795b42bd7d8901
Author: Jean Felder <jfelder src gnome org>
Date:   Tue Apr 16 14:48:01 2019 +0200

    mpris: Listen to state changes to update song position

 gnomemusic/gstplayer.py |  1 -
 gnomemusic/mpris.py     | 12 +++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index 346331e5..e13a13b3 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -296,7 +296,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/mpris.py b/gnomemusic/mpris.py
index e064258f..ccc7c89a 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -226,7 +226,6 @@ 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('seek-finished', self._on_seek_finished)
         self.player.connect(
             'playlist-changed', self._on_player_playlist_changed)
         self.player_toolbar = app.get_active_window()._player_toolbar
@@ -470,6 +469,13 @@ class MediaPlayer2Service(Server):
     @log
     def _on_player_state_changed(self, klass, args):
         playback_status = self._get_playback_status()
+
+        if playback_status == "Playing":
+            position_second = self.player.get_position()
+            # at startup, position is never exactly equal to 0
+            if position_second > 0.01:
+                self.Seeked(int(position_second * 1e6))
+
         if playback_status == self._previous_playback_status:
             return
 
@@ -507,10 +513,6 @@ class MediaPlayer2Service(Server):
                                },
                                [])
 
-    @log
-    def _on_seek_finished(self, player, position_second):
-        self.Seeked(int(position_second * 1e6))
-
     @log
     def _on_player_playlist_changed(self, klass):
         self._update_songs_list()


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