Add change track to playback providers.

This method is intended to make implementing EOT handling much more streamlined
by adding a way to easily just change the URI and any other state without
messing with gstreamer pipe states

Naming of this is a bit unfortunate as it is not the same as the
core.playback's concept of change_track. At least not yet
This commit is contained in:
Thomas Adamcik 2012-11-01 22:28:57 +01:00
parent e00b590ae9
commit 3a9ce05b7c
2 changed files with 23 additions and 16 deletions

View File

@ -88,8 +88,8 @@ class BaseLibraryProvider(object):
class BasePlaybackProvider(object):
"""
:param audio: the audio actor
:type audio: actor proxy to an instance of :class:`mopidy.audio.Audio`
:param audio: audio sub-system
:type audio: actor proxy to a :class:`mopidy.audio.Audio` actor.
:param backend: the backend
:type backend: :class:`mopidy.backends.base.Backend`
"""
@ -121,9 +121,24 @@ class BasePlaybackProvider(object):
:rtype: :class:`True` if successful, else :class:`False`
"""
self.audio.prepare_change()
self.audio.set_uri(track.uri).get()
self.change_track(track)
return self.audio.start_playback().get()
def change_track(self, track):
"""
Swith to provided track.
Used for handling of EOT and and in :meth:`play`.
*MAY be reimplemented by subclass.*
:param track: the track to play
:type track: :class:`mopidy.models.Track`
:rtype: :class:`True` if successful, else :class:`False`
"""
self.audio.set_uri(track.uri).get()
return True
def resume(self):
"""
Resume playback at the same time position playback was paused.

View File

@ -23,26 +23,18 @@ class SpotifyPlaybackProvider(base.BasePlaybackProvider):
return super(SpotifyPlaybackProvider, self).pause()
def play(self, track):
if track.uri is None:
return False
def change_track(self, track):
self.audio.set_uri('appsrc://').get()
self.audio.set_metadata(track).get()
try:
self.backend.spotify.session.load(
Link.from_string(track.uri).as_track())
self.backend.spotify.session.play(1)
self.audio.prepare_change()
self.audio.set_uri('appsrc://')
self.audio.start_playback()
self.audio.set_metadata(track)
self._timer.play()
return True
except SpotifyError as e:
logger.info('Playback of %s failed: %s', track.uri, e)
return False
self._timer.play()
return True
def resume(self):
time_position = self.get_time_position()