[gnome-music/wip/jfelder/mpris-fix-seek: 2/2] player: Synchronize smoothscale and mpris seek
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-fix-seek: 2/2] player: Synchronize smoothscale and mpris seek
- Date: Tue, 25 Sep 2018 21:31:25 +0000 (UTC)
commit f3171136be99a9f68fa5e76895a6b0504feb10fd
Author: Jean Felder <jfelder src gnome org>
Date: Tue Sep 25 23:09:42 2018 +0200
player: Synchronize smoothscale and mpris seek
SmoothScale directly interacts with GstPlayer while mpris server
relies on Player for seek operations.
Move seeked signal emission to GstPlayer. Player listens this signal
to restart the player and emit its own seeked signal.
Mpris server listens the seeked signal from Player to update its
position.
When a Seek operation is performed from a mpris client, Smoothscale
position is updated when GstPlayer state changes back to PLAYING.
data/ui/PlayerToolbar.ui | 1 -
gnomemusic/gstplayer.py | 4 +++-
gnomemusic/mpris.py | 3 ++-
gnomemusic/player.py | 8 +++++++-
gnomemusic/widgets/playertoolbar.py | 5 -----
gnomemusic/widgets/smoothscale.py | 8 +-------
6 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/data/ui/PlayerToolbar.ui b/data/ui/PlayerToolbar.ui
index 58bff15b..aac22d98 100644
--- a/data/ui/PlayerToolbar.ui
+++ b/data/ui/PlayerToolbar.ui
@@ -201,7 +201,6 @@
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="draw_value">False</property>
- <signal name = "seek-finished" handler="_on_seek_finished" swapped="no"/>
<signal name = "value-changed" handler="_on_progress_value_changed" swapped="no"/>
</object>
</child>
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index 13dcb920..983f9ab1 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -54,7 +54,8 @@ class GstPlayer(GObject.GObject):
"""
__gsignals__ = {
'eos': (GObject.SignalFlags.RUN_FIRST, None, ()),
- 'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int, ))
+ 'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int, )),
+ 'seeked': (GObject.SignalFlags.RUN_FIRST, None, ())
}
def __repr__(self):
@@ -310,6 +311,7 @@ class GstPlayer(GObject.GObject):
self._player.seek_simple(
Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT,
seconds * Gst.SECOND)
+ self.emit('seeked')
@log
def _start_plugin_installation(
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 2e22a03a..5644e327 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -471,7 +471,8 @@ class MediaPlayer2Service(Server):
self.player.play()
@log
- def _on_seeked(self, player, position_second):
+ def _on_seeked(self, player):
+ position_second = self.player.get_position()
self.Seeked(position_second * 1e6)
@log
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index f985f9cf..2ff60943 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -500,7 +500,7 @@ class Player(GObject.GObject):
'playback-status-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
'playlist-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
'prev-next-invalidated': (GObject.SignalFlags.RUN_FIRST, None, ()),
- 'seeked': (GObject.SignalFlags.RUN_FIRST, None, (int,)),
+ 'seeked': (GObject.SignalFlags.RUN_FIRST, None, ()),
'song-changed': (GObject.SignalFlags.RUN_FIRST, None, (int,)),
'song-validated': (GObject.SignalFlags.RUN_FIRST, None, (int, int)),
'volume-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
@@ -530,6 +530,7 @@ class Player(GObject.GObject):
self._player = GstPlayer()
self._player.connect('clock-tick', self._on_clock_tick)
self._player.connect('eos', self._on_eos)
+ self._player.connect('seeked', self._on_seeked)
root_window = parent_window.get_toplevel()
self._inhibit_suspend = InhibitSuspend(root_window, self)
@@ -588,6 +589,11 @@ class Player(GObject.GObject):
else:
self.stop()
+ @log
+ def _on_seeked(self, klass):
+ self.play()
+ self.emit('seeked')
+
@log
def play(self, song_index=None):
"""Play"""
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 5091dd13..ac893d2d 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -86,11 +86,6 @@ class PlayerToolbar(Gtk.ActionBar):
self._player.connect('notify::repeat-mode', self._sync_repeat_image)
self._player.connect('playback-status-changed', self._sync_playing)
- @Gtk.Template.Callback()
- @log
- def _on_seek_finished(self, klass, time):
- self._player.play()
-
@Gtk.Template.Callback()
@log
def _on_progress_value_changed(self, progress_scale):
diff --git a/gnomemusic/widgets/smoothscale.py b/gnomemusic/widgets/smoothscale.py
index b9d6cb30..310c1440 100644
--- a/gnomemusic/widgets/smoothscale.py
+++ b/gnomemusic/widgets/smoothscale.py
@@ -41,12 +41,6 @@ class SmoothScale(Gtk.Scale):
"""
__gtype_name__ = 'SmoothScale'
- __gsignals__ = {
- 'seek-finished': (
- GObject.SignalFlags.RUN_FIRST, None, (float,)
- ),
- }
-
def __repr__(self):
return '<SmoothScale>'
@@ -107,6 +101,7 @@ class SmoothScale(Gtk.Scale):
self.set_sensitive(True)
if state == Playback.PLAYING:
+ self._update_position_callback()
self._update_timeout()
else:
self._remove_timeout()
@@ -130,7 +125,6 @@ class SmoothScale(Gtk.Scale):
self._on_smooth_scale_change_value(self)
self._old_smooth_scale_value = round(value, round_digits)
- self.emit('seek-finished', value)
return False
@log
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]