Trigger playing/stopped events at play, prev, next, stop, eot.
This commit is contained in:
parent
1ed711fb85
commit
a8f035e879
@ -312,16 +312,9 @@ class BasePlaybackController(object):
|
|||||||
|
|
||||||
original_cp_track = self.current_cp_track
|
original_cp_track = self.current_cp_track
|
||||||
|
|
||||||
# Notify frontends of the end_of_track event
|
|
||||||
self.backend.core_queue.put({
|
|
||||||
'to': 'frontend',
|
|
||||||
'command': 'end_of_track',
|
|
||||||
'track': original_cp_track[1],
|
|
||||||
})
|
|
||||||
|
|
||||||
if self.cp_track_at_eot:
|
if self.cp_track_at_eot:
|
||||||
|
self._trigger_stopped_playing_event()
|
||||||
self.play(self.cp_track_at_eot)
|
self.play(self.cp_track_at_eot)
|
||||||
|
|
||||||
if self.random and self.current_cp_track in self._shuffled:
|
if self.random and self.current_cp_track in self._shuffled:
|
||||||
self._shuffled.remove(self.current_cp_track)
|
self._shuffled.remove(self.current_cp_track)
|
||||||
else:
|
else:
|
||||||
@ -354,6 +347,7 @@ class BasePlaybackController(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.cp_track_at_next:
|
if self.cp_track_at_next:
|
||||||
|
self._trigger_stopped_playing_event()
|
||||||
self.play(self.cp_track_at_next)
|
self.play(self.cp_track_at_next)
|
||||||
else:
|
else:
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -408,12 +402,7 @@ class BasePlaybackController(object):
|
|||||||
if self.random and self.current_cp_track in self._shuffled:
|
if self.random and self.current_cp_track in self._shuffled:
|
||||||
self._shuffled.remove(self.current_cp_track)
|
self._shuffled.remove(self.current_cp_track)
|
||||||
|
|
||||||
# Notify frontends of the now_playing event
|
self._trigger_started_playing_event()
|
||||||
self.backend.core_queue.put({
|
|
||||||
'to': 'frontend',
|
|
||||||
'command': 'now_playing',
|
|
||||||
'track': cp_track[1],
|
|
||||||
})
|
|
||||||
|
|
||||||
def _play(self, track):
|
def _play(self, track):
|
||||||
"""
|
"""
|
||||||
@ -433,6 +422,7 @@ class BasePlaybackController(object):
|
|||||||
return
|
return
|
||||||
if self.state == self.STOPPED:
|
if self.state == self.STOPPED:
|
||||||
return
|
return
|
||||||
|
self._trigger_stopped_playing_event()
|
||||||
self.play(self.cp_track_at_previous, on_error_step=-1)
|
self.play(self.cp_track_at_previous, on_error_step=-1)
|
||||||
|
|
||||||
def resume(self):
|
def resume(self):
|
||||||
@ -489,7 +479,10 @@ class BasePlaybackController(object):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stop playing."""
|
"""Stop playing."""
|
||||||
if self.state != self.STOPPED and self._stop():
|
if self.state == self.STOPPED:
|
||||||
|
return
|
||||||
|
self._trigger_stopped_playing_event()
|
||||||
|
if self._stop():
|
||||||
self.state = self.STOPPED
|
self.state = self.STOPPED
|
||||||
|
|
||||||
def _stop(self):
|
def _stop(self):
|
||||||
@ -500,3 +493,31 @@ class BasePlaybackController(object):
|
|||||||
:rtype: :class:`True` if successful, else :class:`False`
|
:rtype: :class:`True` if successful, else :class:`False`
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def _trigger_started_playing_event(self):
|
||||||
|
"""
|
||||||
|
Notifies frontends that a track has started playing.
|
||||||
|
|
||||||
|
For internal use only. Should be called by the backend directly after a
|
||||||
|
track has started playing.
|
||||||
|
"""
|
||||||
|
self.backend.core_queue.put({
|
||||||
|
'to': 'frontend',
|
||||||
|
'command': 'started_playing',
|
||||||
|
'track': self.current_track,
|
||||||
|
})
|
||||||
|
|
||||||
|
def _trigger_stopped_playing_event(self):
|
||||||
|
"""
|
||||||
|
Notifies frontends that a track has stopped playing.
|
||||||
|
|
||||||
|
For internal use only. Should be called by the backend before a track
|
||||||
|
is stopped playing, e.g. at the next, previous, and stop actions and at
|
||||||
|
end-of-track.
|
||||||
|
"""
|
||||||
|
self.backend.core_queue.put({
|
||||||
|
'to': 'frontend',
|
||||||
|
'command': 'stopped_playing',
|
||||||
|
'track': self.current_track,
|
||||||
|
'stop_position': self.time_position,
|
||||||
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user