audio: Watch for EOS messages from the gstreamer bus
Mark the track as played if it has run for more than 2/3 of the running time. Also check the "continue" field when choosing the next song from the stack. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
171e8a1829
commit
5633d50024
|
@ -14,6 +14,7 @@ class Player:
|
|||
|
||||
self.bus = self.playbin.get_bus()
|
||||
self.bus.add_signal_watch()
|
||||
self.bus.connect("message::eos", self.next)
|
||||
self.bus.connect("message::state-changed", self.on_state_changed)
|
||||
self.bus.connect("message::tag", self.on_tag)
|
||||
|
||||
|
@ -61,6 +62,10 @@ class Player:
|
|||
self.playbin.set_state(state)
|
||||
|
||||
def next(self, *args):
|
||||
duration = self.duration()
|
||||
if duration > 0 and (self.runtime() / duration) > (2 / 3):
|
||||
self.track.played()
|
||||
|
||||
(track, cont) = trackdb.Stack.next()
|
||||
state = Gst.State.PLAYING if cont else Gst.State.PAUSED
|
||||
self.load_set_state(track, state)
|
||||
|
@ -97,6 +102,11 @@ class Player:
|
|||
def previous(self, *args):
|
||||
self.play_track(trackdb.Stack.previous())
|
||||
|
||||
def runtime(self):
|
||||
if self.playbin.clock == None:
|
||||
return 0
|
||||
return self.playbin.clock.get_time() - self.playbin.base_time
|
||||
|
||||
def seeked(self, scale, scroll, value):
|
||||
self.playbin.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH,
|
||||
value * Gst.SECOND)
|
||||
|
|
Loading…
Reference in New Issue