From 8c163104d116bbd479a5cf14d83c1c439479dd9a Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 9 Mar 2011 21:37:47 +0100 Subject: [PATCH] Reimplement sending of started/stopped_playing events from the backend to interested frontends --- mopidy/backends/base/playback.py | 22 ++++++++++++++-------- mopidy/frontends/lastfm.py | 8 ++++++++ mopidy/frontends/mpd/__init__.py | 3 +++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/mopidy/backends/base/playback.py b/mopidy/backends/base/playback.py index e4ffa075..80133c33 100644 --- a/mopidy/backends/base/playback.py +++ b/mopidy/backends/base/playback.py @@ -2,6 +2,10 @@ import logging import random import time +from pykka.registry import ActorRegistry + +from mopidy.frontends.base import BaseFrontend + logger = logging.getLogger('mopidy.backends.base') class PlaybackController(object): @@ -463,10 +467,11 @@ class PlaybackController(object): For internal use only. Should be called by the backend directly after a track has started playing. """ - return # TODO-PYKKA Send started_playing event to interested parties - if self.current_track is not None: - self.backend.core_queue.put({ - 'to': 'frontend', + if self.current_track is None: + return + frontend_refs = ActorRegistry.get_by_class(BaseFrontend) + for frontend_ref in frontend_refs: + frontend_ref.send_one_way({ 'command': 'started_playing', 'track': self.current_track, }) @@ -479,10 +484,11 @@ class PlaybackController(object): is stopped playing, e.g. at the next, previous, and stop actions and at end-of-track. """ - return # TODO-PYKKA Send stopped_playing event to interested parties - if self.current_track is not None: - self.backend.core_queue.put({ - 'to': 'frontend', + if self.current_track is None: + return + frontend_refs = ActorRegistry.get_by_class(BaseFrontend) + for frontend_ref in frontend_refs: + frontend_ref.send_one_way({ 'command': 'stopped_playing', 'track': self.current_track, 'stop_position': self.time_position, diff --git a/mopidy/frontends/lastfm.py b/mopidy/frontends/lastfm.py index 4a703c22..d723052e 100644 --- a/mopidy/frontends/lastfm.py +++ b/mopidy/frontends/lastfm.py @@ -58,6 +58,14 @@ class LastfmFrontend(ThreadingActor, BaseFrontend): logger.error(u'Error during Last.fm setup: %s', e) self.stop() + def react(self, message): + if message.get('command') == 'started_playing': + self.started_playing(message['track']) + elif message.get('command') == 'stopped_playing': + self.stopped_playing(message['track'], message['stop_position']) + else: + pass # Ignore any other messages + def started_playing(self, track): artists = ', '.join([a.name for a in track.artists]) duration = track.length and track.length // 1000 or 0 diff --git a/mopidy/frontends/mpd/__init__.py b/mopidy/frontends/mpd/__init__.py index 96500d9b..c7f469dd 100644 --- a/mopidy/frontends/mpd/__init__.py +++ b/mopidy/frontends/mpd/__init__.py @@ -27,6 +27,9 @@ class MpdFrontend(ThreadingActor, BaseFrontend): self._thread = MpdThread() self._thread.start() + def react(self, message): + pass # Ignore any messages + class MpdThread(BaseThread): def __init__(self):