Refactor common sanity checks for seek into base class and expect _seek from subclasses

This commit is contained in:
Thomas Adamcik 2010-04-06 21:40:29 +02:00
parent e77bfef196
commit acbb2bd7bf
2 changed files with 13 additions and 11 deletions

View File

@ -507,6 +507,18 @@ class BasePlaybackController(object):
:param time_position: time position in milliseconds
:type time_position: int
"""
if self.state == self.STOPPED:
self.play()
if time_position < 0:
time_position = 0
elif self.current_track and time_position > self.current_track.length:
self.next()
return
self._seek(time_position)
def _seek(self, time_position):
raise NotImplementedError
def stop(self):

View File

@ -71,17 +71,7 @@ class GStreamerPlaybackController(BasePlaybackController):
def _resume(self):
return self._set_state(gst.STATE_PLAYING)
# FIXME refactor to _seek ?
def seek(self, time_position):
if self.state == self.STOPPED:
self.play()
if time_position < 0:
time_position = 0
elif self.current_track and time_position > self.current_track.length:
self.next()
return
def _seek(self, time_position):
self._bin.seek_simple(gst.Format(gst.FORMAT_TIME),
gst.SEEK_FLAG_FLUSH, time_position * gst.MSECOND)
self._set_state(gst.STATE_PLAYING)