audio: Give the BassPlayer a play_percent property

For calculating what percentage of a song has been played, which is used
to determine if a track can be marked as played or not

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-09-06 08:47:24 -04:00
parent 51e8bc295d
commit e467b784e4
2 changed files with 8 additions and 7 deletions

View File

@ -41,6 +41,13 @@ class BassPlayer(GObject.GObject):
state = Gst.State.PLAYING if playing else Gst.State.PAUSED
self.playbin.set_state(state)
@GObject.Property
def play_percent(self):
if self.playbin.clock == None or self.duration == 0:
return 0
runtime = self.playbin.clock.get_time() - self.playbin.base_time
return runtime / self.duration
@GObject.Property
def position(self):
(res, pos) = self.playbin.query_position(Gst.Format.TIME)

View File

@ -46,8 +46,7 @@ class Player(bass.BassPlayer):
self.playbin.set_state(state)
def next(self, *args):
duration = self.duration
if duration > 0 and (self.runtime() / duration) > (2 / 3):
if self.play_percent > (2 / 3):
self.track.played()
(track, cont) = tagdb.Stack.next()
@ -75,11 +74,6 @@ class Player(bass.BassPlayer):
def previous(self, *args):
self.play_track(tagdb.Stack.previous())
def runtime(self):
if self.playbin.clock == None:
return 0
return self.playbin.clock.get_time() - self.playbin.base_time
@GObject.Signal(arg_types=(tagdb.track.Track, tagdb.track.Track))
def track_changed(self, prev, new):
pass