Move next and prevous methods to base backend

This commit is contained in:
Thomas Adamcik 2010-02-14 16:09:41 +01:00
parent f9312b372f
commit cdbeaa845b
2 changed files with 21 additions and 27 deletions

View File

@ -112,10 +112,29 @@ class BasePlaybackController(object):
raise NotImplementedError
def next(self):
raise NotImplementedError
playlist = self.backend.current_playlist.playlist
if not self.current_track:
self.play()
elif self.playlist_position + 1 >= len(playlist.tracks):
self.stop()
else:
next_track = playlist.tracks[self.playlist_position+1]
self.play(next_track)
def previous(self):
raise NotImplementedError
playlist = self.backend.current_playlist.playlist
if not self.current_track:
self.play()
elif not playlist.tracks:
self.stop()
elif self.playlist_position - 1 > 0:
first_track = playlist.tracks[0]
self.play(first_track)
else:
previous_track = playlist.tracks[self.playlist_position-1]
self.play(previous_track)
def pause(self):
raise NotImplementedError

View File

@ -85,31 +85,6 @@ class GStreamerPlaybackController(BasePlaybackController):
if self.state != self.PLAYING:
self.bin.set_state(gst.STATE_PLAYING)
def next(self):
playlist = self.backend.current_playlist.playlist
if not self.current_track:
self.play()
elif self.playlist_position + 1 >= len(playlist.tracks):
self.stop()
else:
next_track = playlist.tracks[self.playlist_position+1]
self.play(next_track)
def previous(self):
playlist = self.backend.current_playlist.playlist
if not self.current_track:
self.play()
elif not playlist.tracks:
self.stop()
elif self.playlist_position - 1 > 0:
first_track = playlist.tracks[0]
self.play(first_track)
else:
previous_track = playlist.tracks[self.playlist_position-1]
self.play(previous_track)
@property
def volume(self):
return int(self.bin.get_property('volume') * 100)