Merge pull request #208 from jodal/feature/give-backends-an-audio-proxy
Explictly give backends an audio proxy
This commit is contained in:
commit
941d97dd82
@ -51,8 +51,8 @@ def main():
|
||||
setup_logging(options.verbosity_level, options.save_debug_log)
|
||||
check_old_folders()
|
||||
setup_settings(options.interactive)
|
||||
setup_audio()
|
||||
setup_backend()
|
||||
audio = setup_audio()
|
||||
setup_backend(audio)
|
||||
setup_frontends()
|
||||
loop.run()
|
||||
except SettingsError as e:
|
||||
@ -118,14 +118,15 @@ def setup_settings(interactive):
|
||||
|
||||
|
||||
def setup_audio():
|
||||
Audio.start()
|
||||
return Audio.start().proxy()
|
||||
|
||||
|
||||
def stop_audio():
|
||||
stop_actors_by_class(Audio)
|
||||
|
||||
def setup_backend():
|
||||
get_class(settings.BACKENDS[0]).start()
|
||||
|
||||
def setup_backend(audio):
|
||||
get_class(settings.BACKENDS[0]).start(audio=audio)
|
||||
|
||||
|
||||
def stop_backend():
|
||||
|
||||
@ -4,6 +4,12 @@ from .stored_playlists import BaseStoredPlaylistsProvider
|
||||
|
||||
|
||||
class Backend(object):
|
||||
#: Actor proxy to an instance of :class:`mopidy.audio.Audio`.
|
||||
#:
|
||||
#: Should be passed to the backend constructor as the kwarg ``audio``,
|
||||
#: which will then set this field.
|
||||
audio = None
|
||||
|
||||
#: The current playlist controller. An instance of
|
||||
#: :class:`mopidy.backends.base.CurrentPlaylistController`.
|
||||
current_playlist = None
|
||||
@ -22,3 +28,6 @@ class Backend(object):
|
||||
|
||||
#: List of URI schemes this backend can handle.
|
||||
uri_schemes = []
|
||||
|
||||
def __init__(self, audio=None):
|
||||
self.audio = audio
|
||||
|
||||
@ -32,7 +32,7 @@ class LocalBackend(ThreadingActor, base.Backend):
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LocalBackend, self).__init__(*args, **kwargs)
|
||||
base.Backend.__init__(self, *args, **kwargs)
|
||||
|
||||
self.current_playlist = core.CurrentPlaylistController(backend=self)
|
||||
|
||||
@ -50,14 +50,6 @@ class LocalBackend(ThreadingActor, base.Backend):
|
||||
|
||||
self.uri_schemes = [u'file']
|
||||
|
||||
self.audio = None
|
||||
|
||||
def on_start(self):
|
||||
audio_refs = ActorRegistry.get_by_class(audio.Audio)
|
||||
assert len(audio_refs) == 1, \
|
||||
'Expected exactly one running Audio instance.'
|
||||
self.audio = audio_refs[0].proxy()
|
||||
|
||||
|
||||
class LocalStoredPlaylistsProvider(base.BaseStoredPlaylistsProvider):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
@ -47,7 +47,7 @@ class SpotifyBackend(ThreadingActor, base.Backend):
|
||||
from .playback import SpotifyPlaybackProvider
|
||||
from .stored_playlists import SpotifyStoredPlaylistsProvider
|
||||
|
||||
super(SpotifyBackend, self).__init__(*args, **kwargs)
|
||||
base.Backend.__init__(self, *args, **kwargs)
|
||||
|
||||
self.current_playlist = core.CurrentPlaylistController(backend=self)
|
||||
|
||||
@ -66,7 +66,6 @@ class SpotifyBackend(ThreadingActor, base.Backend):
|
||||
|
||||
self.uri_schemes = [u'spotify']
|
||||
|
||||
self.audio = None
|
||||
self.spotify = None
|
||||
|
||||
# Fail early if settings are not present
|
||||
@ -74,11 +73,6 @@ class SpotifyBackend(ThreadingActor, base.Backend):
|
||||
self.password = settings.SPOTIFY_PASSWORD
|
||||
|
||||
def on_start(self):
|
||||
audio_refs = ActorRegistry.get_by_class(audio.Audio)
|
||||
assert len(audio_refs) == 1, \
|
||||
'Expected exactly one running Audio instance.'
|
||||
self.audio = audio_refs[0].proxy()
|
||||
|
||||
logger.info(u'Mopidy uses SPOTIFY(R) CORE')
|
||||
self.spotify = self._connect()
|
||||
|
||||
@ -89,6 +83,7 @@ class SpotifyBackend(ThreadingActor, base.Backend):
|
||||
from .session_manager import SpotifySessionManager
|
||||
|
||||
logger.debug(u'Connecting to Spotify')
|
||||
spotify = SpotifySessionManager(self.username, self.password)
|
||||
spotify = SpotifySessionManager(self.username, self.password,
|
||||
audio=self.audio, backend=self.actor_ref.proxy())
|
||||
spotify.start()
|
||||
return spotify
|
||||
|
||||
@ -27,13 +27,13 @@ class SpotifySessionManager(BaseThread, PyspotifySessionManager):
|
||||
appkey_file = os.path.join(os.path.dirname(__file__), 'spotify_appkey.key')
|
||||
user_agent = 'Mopidy %s' % get_version()
|
||||
|
||||
def __init__(self, username, password):
|
||||
def __init__(self, username, password, audio, backend):
|
||||
PyspotifySessionManager.__init__(self, username, password)
|
||||
BaseThread.__init__(self)
|
||||
self.name = 'SpotifyThread'
|
||||
|
||||
self.audio = None
|
||||
self.backend = None
|
||||
self.audio = audio
|
||||
self.backend = backend
|
||||
|
||||
self.connected = threading.Event()
|
||||
self.session = None
|
||||
@ -44,19 +44,8 @@ class SpotifySessionManager(BaseThread, PyspotifySessionManager):
|
||||
self._initial_data_receive_completed = False
|
||||
|
||||
def run_inside_try(self):
|
||||
self.setup()
|
||||
self.connect()
|
||||
|
||||
def setup(self):
|
||||
audio_refs = ActorRegistry.get_by_class(audio.Audio)
|
||||
assert len(audio_refs) == 1, \
|
||||
'Expected exactly one running Audio instance.'
|
||||
self.audio = audio_refs[0].proxy()
|
||||
|
||||
backend_refs = ActorRegistry.get_by_class(Backend)
|
||||
assert len(backend_refs) == 1, 'Expected exactly one running backend.'
|
||||
self.backend = backend_refs[0].proxy()
|
||||
|
||||
def logged_in(self, session, error):
|
||||
"""Callback used by pyspotify"""
|
||||
if error:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user