[gnome-music/wip/jfelder/smoothscale-player: 1/6] player: Define state GObject property
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/smoothscale-player: 1/6] player: Define state GObject property
- Date: Tue, 16 Oct 2018 17:06:29 +0000 (UTC)
commit a2cc4e2987d45fb9a4acc8a802b3dfb9c7ff53be
Author: Jean Felder <jfelder src gnome org>
Date: Tue Oct 2 14:56:24 2018 +0200
player: Define state GObject property
After a seek operation, state change state needs to be manually
triggered to notify a change the change.
This property will also be used by SmoothScale in addition to mpris
and PlayerToolbar.
gnomemusic/gstplayer.py | 2 +-
gnomemusic/inhibitsuspend.py | 15 +++++++--------
gnomemusic/mpris.py | 6 +++---
gnomemusic/player.py | 21 ++++++++-------------
gnomemusic/widgets/playertoolbar.py | 6 +++---
5 files changed, 22 insertions(+), 28 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index 6c39f777..b8772bbc 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -214,7 +214,7 @@ class GstPlayer(GObject.GObject):
return Playback.STOPPED
- @GObject.Property
+ @GObject.Property(type=int)
def state(self):
"""Current state of the player
diff --git a/gnomemusic/inhibitsuspend.py b/gnomemusic/inhibitsuspend.py
index b6fc9d03..e6ea5f6a 100644
--- a/gnomemusic/inhibitsuspend.py
+++ b/gnomemusic/inhibitsuspend.py
@@ -51,8 +51,7 @@ class InhibitSuspend(GObject.GObject):
self._player = player
self._inhibit_cookie = 0
- self._player.connect(
- 'playback-status-changed', self._on_playback_status_changed)
+ self._player.connect('notify::state', self._on_player_state_changed)
self._settings = Gio.Settings.new('org.gnome.Music')
self._should_inhibit = self._settings.get_boolean('inhibit-suspend')
@@ -79,14 +78,14 @@ class InhibitSuspend(GObject.GObject):
@log
def _on_inhibit_suspend_changed(self, settings, value):
self._should_inhibit = value
- self._on_playback_status_changed(None)
+ self._on_player_state_changed(None, None)
@log
- def _on_playback_status_changed(self, arguments):
- if (self._player.get_playback_status() == Playback.PLAYING
- or self._player.get_playback_status() == Playback.LOADING):
+ def _on_player_state_changed(self, klass, arguments):
+ if (self._player.props.state == Playback.PLAYING
+ or self._player.props.state == Playback.LOADING):
self._inhibit_suspend()
- if (self._player.get_playback_status() == Playback.PAUSED
- or self._player.get_playback_status() == Playback.STOPPED):
+ if (self._player.props.state == Playback.PAUSED
+ or self._player.props.state == Playback.STOPPED):
self._uninhibit_suspend()
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 078e2324..d488d8c7 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -224,7 +224,7 @@ class MediaPlayer2Service(Server):
self.player = app.get_active_window()._player
self.player.connect(
'song-changed', self._on_current_song_changed)
- self.player.connect('playback-status-changed', self._on_playback_status_changed)
+ self.player.connect('notify::state', self._on_player_state_changed)
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)
@@ -242,7 +242,7 @@ class MediaPlayer2Service(Server):
@log
def _get_playback_status(self):
- state = self.player.get_playback_status()
+ state = self.player.props.state
if state == Playback.PLAYING:
return 'Playing'
elif state == Playback.PAUSED:
@@ -429,7 +429,7 @@ class MediaPlayer2Service(Server):
[])
@log
- def _on_playback_status_changed(self, data=None):
+ def _on_player_state_changed(self, klass, args):
self.PropertiesChanged(MediaPlayer2Service.MEDIA_PLAYER2_PLAYER_IFACE,
{
'PlaybackStatus': GLib.Variant('s', self._get_playback_status()),
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 79cfd4ac..c9fa7c73 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -497,7 +497,6 @@ class Player(GObject.GObject):
__gsignals__ = {
'clock-tick': (GObject.SignalFlags.RUN_FIRST, None, (int,)),
- '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,)),
@@ -506,6 +505,8 @@ class Player(GObject.GObject):
'volume-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
}
+ state = GObject.Property(type=int, default=Playback.STOPPED)
+
def __repr__(self):
return '<Player>'
@@ -530,6 +531,8 @@ 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.bind_property(
+ 'state', self, 'state', GObject.BindingFlags.SYNC_CREATE)
root_window = parent_window.get_toplevel()
self._inhibit_suspend = InhibitSuspend(root_window, self)
@@ -564,7 +567,7 @@ class Player(GObject.GObject):
:returns: True if a song is currently played.
:rtype: bool
"""
- return self._player.state == Playback.PLAYING
+ return self.props.state == Playback.PLAYING
@log
def _load(self, song):
@@ -598,23 +601,20 @@ class Player(GObject.GObject):
and not self._playlist.set_song(song_index)):
return False
- if self._player.state != Playback.PAUSED:
+ if self.props.state != Playback.PAUSED:
self._load(self._playlist.props.current_song)
self._player.state = Playback.PLAYING
- self.emit('playback-status-changed')
@log
def pause(self):
"""Pause"""
self._player.state = Playback.PAUSED
- self.emit('playback-status-changed')
@log
def stop(self):
"""Stop"""
self._player.state = Playback.STOPPED
- self.emit('playback-status-changed')
@log
def next(self):
@@ -643,7 +643,7 @@ class Player(GObject.GObject):
@log
def play_pause(self):
"""Toggle play/pause state"""
- if self._player.state == Playback.PLAYING:
+ if self.props.state == Playback.PLAYING:
self.pause()
else:
self.play()
@@ -660,7 +660,7 @@ class Player(GObject.GObject):
playlist_changed = self._playlist.set_playlist(
playlist_type, playlist_id, model, iter_)
- if self._player.state == Playback.PLAYING:
+ if self.props.state == Playback.PLAYING:
self.emit('prev-next-invalidated')
if playlist_changed:
@@ -806,11 +806,6 @@ class Player(GObject.GObject):
"""GstPlayer getter"""
return self._player
- @log
- def get_playback_status(self):
- # FIXME: Just a proxy right now.
- return self._player.state
-
@log
def get_position(self):
return self._player.position
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index ac893d2d..1cbb89d2 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -84,7 +84,7 @@ class PlayerToolbar(Gtk.ActionBar):
self._player.connect('song-changed', self._update_view)
self._player.connect('prev-next-invalidated', self._sync_prev_next)
self._player.connect('notify::repeat-mode', self._sync_repeat_image)
- self._player.connect('playback-status-changed', self._sync_playing)
+ self._player.connect('notify::state', self._sync_playing)
@Gtk.Template.Callback()
@log
@@ -127,11 +127,11 @@ class PlayerToolbar(Gtk.ActionBar):
self._repeat_image.set_from_icon_name(icon, Gtk.IconSize.MENU)
@log
- def _sync_playing(self, player):
+ def _sync_playing(self, klass, args):
if not self._main_window.props.selection_mode:
self.show()
- if self._player.get_playback_status() == Playback.PLAYING:
+ if self._player.props.state == Playback.PLAYING:
image = self._pause_image
tooltip = _("Pause")
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]