Add next_track and previous_track to BasePlaybackController API. Pass track object to internal _next() and _previous() methods.

This commit is contained in:
Stein Magnus Jodal 2010-02-10 12:14:45 +01:00
parent 52aface886
commit 32afe4c103

View File

@ -249,6 +249,15 @@ class BasePlaybackController(object):
self._state = self.STOPPED self._state = self.STOPPED
self.state = self.STOPPED self.state = self.STOPPED
@property
def next_track(self):
"""The next track in the playlist."""
try:
return self.backend.current_playlist.playlist.tracks[
self.playlist_position + 1]
except IndexError:
return None
@property @property
def playlist_position(self): def playlist_position(self):
"""The position in the current playlist.""" """The position in the current playlist."""
@ -260,6 +269,15 @@ class BasePlaybackController(object):
except ValueError: except ValueError:
return None return None
@property
def previous_track(self):
"""The previous track in the playlist."""
try:
return self.backend.current_playlist.playlist.tracks[
self.playlist_position - 1]
except IndexError:
return None
@property @property
def state(self): def state(self):
""" """
@ -314,10 +332,11 @@ class BasePlaybackController(object):
def next(self): def next(self):
"""Play the next track.""" """Play the next track."""
self.stop() self.stop()
if self._next(): if self.next_track is not None and self._next(self.next_track):
self.current_track = self.next_track
self.state = self.PLAYING self.state = self.PLAYING
def _next(self): def _next(self, track):
raise NotImplementedError raise NotImplementedError
def pause(self): def pause(self):
@ -337,10 +356,9 @@ class BasePlaybackController(object):
""" """
if self.state == self.PAUSED and track is None: if self.state == self.PAUSED and track is None:
return self.resume() return self.resume()
if track is not None:
self.current_track = track
self.stop() self.stop()
if self._play(track): if track is not None and self._play(track):
self.current_track = track
self.state = self.PLAYING self.state = self.PLAYING
def _play(self, track): def _play(self, track):
@ -349,10 +367,12 @@ class BasePlaybackController(object):
def previous(self): def previous(self):
"""Play the previous track.""" """Play the previous track."""
self.stop() self.stop()
if self._previous(): if (self.previous_track is not None
and self._previous(self.previous_track)):
self.current_track = self.previous_track
self.state = self.PLAYING self.state = self.PLAYING
def _previous(self): def _previous(self, track):
raise NotImplementedError raise NotImplementedError
def resume(self): def resume(self):