[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: Tue, 16 Oct 2018 17:06:34 +0000 (UTC)
commit 01d4cfea44bd220e024ac40b4b7b20c25acb7bef
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 | 15 ++++++++-------
gnomemusic/widgets/smoothscale.py | 4 ++--
3 files changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/gnomemusic/gstplayer.py b/gnomemusic/gstplayer.py
index b8772bbc..b60464b6 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
@@ -165,7 +165,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):
@@ -267,7 +267,7 @@ class GstPlayer(GObject.GObject):
return position
- @GObject.Property
+ @GObject.Property(type=int)
def duration(self):
"""Total duration of current media
@@ -276,7 +276,7 @@ class GstPlayer(GObject.GObject):
:rtype: float or None
"""
if self.state == Playback.STOPPED:
- return None
+ return -1
return self._duration
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index c9fa7c73..d78c9bcb 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,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..426c01e8 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]