[gnome-music/wip/jfelder/mpris-seek: 5/7] mpris: Listen to gst state changes to update song position
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-seek: 5/7] mpris: Listen to gst state changes to update song position
- Date: Tue, 23 Apr 2019 16:20:49 +0000 (UTC)
commit c2cab2d95f3f7898231577ef4a1088bc195abb70
Author: Jean Felder <jfelder src gnome org>
Date: Tue Apr 16 14:48:01 2019 +0200
mpris: Listen to gst state changes to update song position
Adopt the same logic than the one used by SmoothScale to get the song
position and update it.
Also, do not emit a Seeked signal at the beginning of a song (to
respect MPRIS specifications). A threshold value of 0.01 seems to be a
good compromise as the position query is never exactly equal to 0 at
startup.
gnomemusic/gstplayer.py | 1 -
gnomemusic/mpris.py | 13 ++++++++-----
2 files changed, 8 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..60c58989 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,14 @@ 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()
+ # Do not emit a Seeked signal at the beginning of a song.
+ # 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 +514,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]