[gnome-music/wip/jfelder/smoothscale-player: 2/6] player: Define duration GObject property
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/smoothscale-player: 2/6] player: Define duration GObject property
- Date: Thu, 11 Oct 2018 06:35:55 +0000 (UTC)
commit 7460727ea07fb37e7105a246d88433b375270bc1
Author: Jean Felder <jfelder src gnome org>
Date: Thu Oct 4 08:10:45 2018 +0200
player: Define duration GObject property
Change default duration value to zero to be able to define the
property as an int.
This property will be used by SmoothScale.
gnomemusic/gstplayer.py | 10 +++++-----
gnomemusic/player.py | 16 +++++++++-------
2 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index e3c7e028..af7ed175 100644
--- a/gnomemusic/gstplayer.py
+++ b/gnomemusic/gstplayer.py
@@ -66,7 +66,7 @@ class GstPlayer(GObject.GObject):
Gst.init(None)
- self._duration = None
+ self._duration = 0
self._missing_plugin_messages = []
self._settings = Gio.Settings.new('org.gnome.Music')
@@ -131,7 +131,7 @@ class GstPlayer(GObject.GObject):
# TODO: Workaround the first duration change not being emitted
# and hence smoothscale not being initialized properly.
- if self.duration is None:
+ if self.duration == 0:
self._on_duration_changed(None, None)
@log
@@ -159,7 +159,7 @@ class GstPlayer(GObject.GObject):
if success:
self.duration = duration / Gst.SECOND
else:
- self.duration = None
+ self.duration = 0
@log
def _on_bus_element(self, bus, message):
@@ -259,7 +259,7 @@ class GstPlayer(GObject.GObject):
return position
- @GObject.Property
+ @GObject.Property(type=int)
def duration(self):
"""Total duration of current media
@@ -268,7 +268,7 @@ class GstPlayer(GObject.GObject):
:rtype: float or None
"""
if self.state == Playback.STOPPED:
- return None
+ return 0
return self._duration
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 9b09830b..a3c1d44d 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -506,6 +506,7 @@ class Player(GObject.GObject):
}
state = GObject.Property(type=int, default=Playback.STOPPED)
+ duration = GObject.Property(type=int, default=0)
def __repr__(self):
return '<Player>'
@@ -531,6 +532,9 @@ 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(
+ 'duration', self, 'duration',
+ GObject.BindingFlags.SYNC_CREATE)
self._player.bind_property(
'state', self, 'state',
GObject.BindingFlags.SYNC_CREATE |
@@ -739,15 +743,14 @@ class Player(GObject.GObject):
self._new_clock = True
self._lastfm.now_playing(current_song)
- duration = self._player.duration
- if duration is None:
+ if self.props.duration == 0:
return
position = self._player.position
if position > 0:
- percentage = tick / duration
+ percentage = tick / self.props.duration
if (not self._lastfm.scrobbled
- and duration > 30
+ and self.props.duration > 30
and (percentage > 0.5 or tick > 4 * 60)):
self._lastfm.scrobble(current_song, self._time_stamp)
@@ -821,11 +824,10 @@ class Player(GObject.GObject):
else:
return
- duration = self._player.duration
- if duration is None:
+ if self.props.duration == 0:
return
- if duration >= offset * 1000:
+ if self.props.duration >= offset * 1000:
self._player.seek(offset * 1000)
self.emit('seeked', offset)
elif next_on_overflow:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]