[gnome-music/wip/jfelder/smoothscale-player: 1/5] 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: 1/5] player: Define duration GObject property
- Date: Wed, 17 Oct 2018 21:31:42 +0000 (UTC)
commit 450cbbbe2d787aab0fe13000276d8356f5a7ddcf
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 -1 to be able to define the
property as an int.
This property will be used by SmoothScale.
gnomemusic/gstplayer.py | 14 +++++++-------
gnomemusic/player.py | 15 ++++++++-------
gnomemusic/widgets/smoothscale.py | 4 ++--
3 files changed, 17 insertions(+), 16 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index 3bcce4a8..6f76d509 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 = -1.
self._missing_plugin_messages = []
self._settings = Gio.Settings.new('org.gnome.Music')
@@ -132,7 +132,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 == -1.:
self._on_duration_changed(None, None)
@log
@@ -162,7 +162,7 @@ class GstPlayer(GObject.GObject):
if success:
self.duration = duration / Gst.SECOND
else:
- self.duration = None
+ self.duration = -1.
@log
def _on_bus_element(self, bus, message):
@@ -264,16 +264,16 @@ class GstPlayer(GObject.GObject):
return position
- @GObject.Property
+ @GObject.Property(type=float)
def duration(self):
"""Total duration of current media
- Total duration in seconds or None if not available
+ Total duration in seconds or -1. if not available
:return: duration
- :rtype: float or None
+ :rtype: float
"""
if self.state == Playback.STOPPED:
- return None
+ return -1.
return self._duration
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index c9fa7c73..1557e700 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=float, default=-1.)
def __repr__(self):
return '<Player>'
@@ -531,6 +532,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(
+ 'duration', self, 'duration', GObject.BindingFlags.SYNC_CREATE)
self._player.bind_property(
'state', self, 'state', GObject.BindingFlags.SYNC_CREATE)
@@ -737,15 +740,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 == -1.:
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)
@@ -819,11 +821,10 @@ class Player(GObject.GObject):
else:
return
- duration = self._player.duration
- if duration is None:
+ if self.props.duration == -1.:
return
- if duration >= offset * 1000:
+ if self.props.duration >= offset * 1000:
self._player.seek(offset * 1000)
self.emit('seeked', offset)
elif next_on_overflow:
diff --git a/gnomemusic/widgets/smoothscale.py b/gnomemusic/widgets/smoothscale.py
index 878947f0..733a3d30 100644
--- a/gnomemusic/widgets/smoothscale.py
+++ b/gnomemusic/widgets/smoothscale.py
@@ -112,7 +112,7 @@ class SmoothScale(Gtk.Scale):
def _on_duration_changed(self, klass, arguments):
duration = self._player.duration
- if duration is not None:
+ if duration != -1.:
self.set_range(0.0, duration * 60)
self.set_increments(300, 600)
@@ -176,7 +176,7 @@ class SmoothScale(Gtk.Scale):
# provides a duration.
duration = self._player.duration
if (self.get_realized() is False
- or duration is None):
+ or duration == -1.):
return
# Update self._timeout.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]