Add time position stuff to gstreamer output

This commit is contained in:
Thomas Adamcik 2010-08-14 17:52:12 +02:00
parent a094c66546
commit 3dc9240ea4
2 changed files with 24 additions and 2 deletions

View File

@ -60,11 +60,11 @@ class LocalPlaybackController(BasePlaybackController):
return self._set_state('PLAYING')
def _seek(self, time_position):
pass
self._send({'command': 'set_position', 'position': time_position})
@property
def time_position(self):
pass
return self._send_recv({'command': 'get_position'})
class LocalStoredPlaylistsController(BaseStoredPlaylistsController):

View File

@ -105,6 +105,12 @@ class GStreamerProcess(BaseProcess):
connection.send(volume)
elif message['command'] == 'set_volume':
self.set_volume(message['volume'])
elif message['command'] == 'set_position':
self.set_position(message['position'])
elif message['command'] == 'get_position':
response = self.get_position()
connection = unpickle_connection(message['reply_to'])
connection.send(response)
else:
logger.warning(u'Cannot handle message: %s', message)
@ -180,3 +186,19 @@ class GStreamerProcess(BaseProcess):
"""Set volume in range [0..100]"""
gst_volume = volume / 100.0
self.gst_volume.set_property('volume', gst_volume)
def set_position(self, position):
logger.info('Seeking to %s' % position)
self.gst_pipeline.seek_simple(gst.Format(gst.FORMAT_TIME),
gst.SEEK_FLAG_FLUSH, position * gst.MSECOND)
self.set_state('PLAYING')
def get_position(self):
try:
position = self.gst_pipeline.query_position(gst.FORMAT_TIME)[0]
return position // gst.MSECOND
except gst.QueryError, e:
logger.error('time_position failed: %s', e)
return 0