Give the backends an audio proxy on construction
This commit is contained in:
parent
66f476e85a
commit
f88b7115d9
@ -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()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user