Add paused_playing and resumed_playing events
This commit is contained in:
parent
0e8fb5e7ac
commit
ad246706c6
@ -383,6 +383,7 @@ class PlaybackController(object):
|
|||||||
"""Pause playback."""
|
"""Pause playback."""
|
||||||
if self.provider.pause():
|
if self.provider.pause():
|
||||||
self.state = self.PAUSED
|
self.state = self.PAUSED
|
||||||
|
self._trigger_paused_playing_event()
|
||||||
|
|
||||||
def play(self, cp_track=None, on_error_step=1):
|
def play(self, cp_track=None, on_error_step=1):
|
||||||
"""
|
"""
|
||||||
@ -441,6 +442,7 @@ class PlaybackController(object):
|
|||||||
"""If paused, resume playing the current track."""
|
"""If paused, resume playing the current track."""
|
||||||
if self.state == self.PAUSED and self.provider.resume():
|
if self.state == self.PAUSED and self.provider.resume():
|
||||||
self.state = self.PLAYING
|
self.state = self.PLAYING
|
||||||
|
self._trigger_resumed_playing_event()
|
||||||
|
|
||||||
def seek(self, time_position):
|
def seek(self, time_position):
|
||||||
"""
|
"""
|
||||||
@ -484,6 +486,20 @@ class PlaybackController(object):
|
|||||||
if clear_current_track:
|
if clear_current_track:
|
||||||
self.current_cp_track = None
|
self.current_cp_track = None
|
||||||
|
|
||||||
|
def _trigger_paused_playing_event(self):
|
||||||
|
if self.current_track is None:
|
||||||
|
return
|
||||||
|
for listener_ref in ActorRegistry.get_by_class(BackendListener):
|
||||||
|
listener_ref.proxy().paused_playing(
|
||||||
|
track=self.current_track, time_position=self.time_position)
|
||||||
|
|
||||||
|
def _trigger_resumed_playing_event(self):
|
||||||
|
if self.current_track is None:
|
||||||
|
return
|
||||||
|
for listener_ref in ActorRegistry.get_by_class(BackendListener):
|
||||||
|
listener_ref.proxy().resumed_playing(
|
||||||
|
track=self.current_track, time_position=self.time_position)
|
||||||
|
|
||||||
def _trigger_started_playing_event(self):
|
def _trigger_started_playing_event(self):
|
||||||
if self.current_track is None:
|
if self.current_track is None:
|
||||||
return
|
return
|
||||||
|
|||||||
@ -9,6 +9,33 @@ class BackendListener(object):
|
|||||||
interested in all events.
|
interested in all events.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def paused_playing(self, track, time_position):
|
||||||
|
"""
|
||||||
|
Called whenever playback is paused.
|
||||||
|
|
||||||
|
*MAY* be implemented by actor.
|
||||||
|
|
||||||
|
:param track: the track that was playing when playback paused
|
||||||
|
:type track: :class:`mopidy.models.Track`
|
||||||
|
:param time_position: the time position in milliseconds
|
||||||
|
:type time_position: int
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def resumed_playing(self, track, time_position):
|
||||||
|
"""
|
||||||
|
Called whenever playback is resumed.
|
||||||
|
|
||||||
|
*MAY* be implemented by actor.
|
||||||
|
|
||||||
|
:param track: the track that was playing when playback resumed
|
||||||
|
:type track: :class:`mopidy.models.Track`
|
||||||
|
:param time_position: the time position in milliseconds
|
||||||
|
:type time_position: int
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def started_playing(self, track):
|
def started_playing(self, track):
|
||||||
"""
|
"""
|
||||||
Called whenever a new track starts playing.
|
Called whenever a new track starts playing.
|
||||||
|
|||||||
@ -11,6 +11,8 @@ from mopidy.models import Track
|
|||||||
class BackendEventsTest(unittest.TestCase):
|
class BackendEventsTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.events = {
|
self.events = {
|
||||||
|
'paused_playing': threading.Event(),
|
||||||
|
'resumed_playing': threading.Event(),
|
||||||
'started_playing': threading.Event(),
|
'started_playing': threading.Event(),
|
||||||
'stopped_playing': threading.Event(),
|
'stopped_playing': threading.Event(),
|
||||||
}
|
}
|
||||||
@ -20,6 +22,21 @@ class BackendEventsTest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
ActorRegistry.stop_all()
|
ActorRegistry.stop_all()
|
||||||
|
|
||||||
|
def test_pause_sends_paused_playing_event(self):
|
||||||
|
self.backend.current_playlist.add([Track(uri='a')])
|
||||||
|
self.backend.playback.play()
|
||||||
|
self.backend.playback.pause()
|
||||||
|
self.events['paused_playing'].wait(timeout=1)
|
||||||
|
self.assertTrue(self.events['paused_playing'].is_set())
|
||||||
|
|
||||||
|
def test_resume_sends_resumed_playing_event(self):
|
||||||
|
self.backend.current_playlist.add([Track(uri='a')])
|
||||||
|
self.backend.playback.play()
|
||||||
|
self.backend.playback.pause()
|
||||||
|
self.backend.playback.resume()
|
||||||
|
self.events['resumed_playing'].wait(timeout=1)
|
||||||
|
self.assertTrue(self.events['resumed_playing'].is_set())
|
||||||
|
|
||||||
def test_play_sends_started_playing_event(self):
|
def test_play_sends_started_playing_event(self):
|
||||||
self.backend.current_playlist.add([Track(uri='a')])
|
self.backend.current_playlist.add([Track(uri='a')])
|
||||||
self.backend.playback.play()
|
self.backend.playback.play()
|
||||||
@ -38,6 +55,12 @@ class DummyBackendListener(ThreadingActor, BackendListener):
|
|||||||
def __init__(self, events):
|
def __init__(self, events):
|
||||||
self.events = events
|
self.events = events
|
||||||
|
|
||||||
|
def paused_playing(self, track, time_position):
|
||||||
|
self.events['paused_playing'].set()
|
||||||
|
|
||||||
|
def resumed_playing(self, track, time_position):
|
||||||
|
self.events['resumed_playing'].set()
|
||||||
|
|
||||||
def started_playing(self, track):
|
def started_playing(self, track):
|
||||||
self.events['started_playing'].set()
|
self.events['started_playing'].set()
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,12 @@ class BackendListenerTest(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.listener = BackendListener()
|
self.listener = BackendListener()
|
||||||
|
|
||||||
|
def test_listener_has_default_impl_for_the_paused_playing_event(self):
|
||||||
|
self.listener.paused_playing(Track(), 0)
|
||||||
|
|
||||||
|
def test_listener_has_default_impl_for_the_resumed_playing_event(self):
|
||||||
|
self.listener.resumed_playing(Track(), 0)
|
||||||
|
|
||||||
def test_listener_has_default_impl_for_the_started_playing_event(self):
|
def test_listener_has_default_impl_for_the_started_playing_event(self):
|
||||||
self.listener.started_playing(Track())
|
self.listener.started_playing(Track())
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user