Properly get track position before change events
In particular, this allows to send the right information when: 1. the track finishes and switches to the next one in the list; 2. user presses next / previous The cases of EOS and stop event were already handled properly. Note: we only have GStreamer's `about-to-finish` event to deal with the end of a track, which usually happens a few seconds before the end of the track. We set the position to the length of the track, which is not overridden unless the user generates a relevant callback.
This commit is contained in:
parent
068800c699
commit
d1449bcb6f
@ -251,6 +251,10 @@ class PlaybackController(object):
|
|||||||
if self._state == PlaybackState.STOPPED:
|
if self._state == PlaybackState.STOPPED:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Unless overridden by other calls (e.g. next / previous / stop) this
|
||||||
|
# will be the last position recorded until the track gets reassigned.
|
||||||
|
self._last_position = self._current_tl_track.track.length
|
||||||
|
|
||||||
pending = self.core.tracklist.eot_track(self._current_tl_track)
|
pending = self.core.tracklist.eot_track(self._current_tl_track)
|
||||||
# avoid endless loop if 'repeat' is 'true' and no track is playable
|
# avoid endless loop if 'repeat' is 'true' and no track is playable
|
||||||
# * 2 -> second run to get all playable track in a shuffled playlist
|
# * 2 -> second run to get all playable track in a shuffled playlist
|
||||||
@ -394,6 +398,10 @@ class PlaybackController(object):
|
|||||||
if not backend:
|
if not backend:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# This must happen before prepare_change gets called, otherwise the
|
||||||
|
# backend flushes the information of the track.
|
||||||
|
self._last_position = self.get_time_position()
|
||||||
|
|
||||||
# TODO: Wrap backend call in error handling.
|
# TODO: Wrap backend call in error handling.
|
||||||
backend.playback.prepare_change()
|
backend.playback.prepare_change()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user