Merge pull request #679 from kivy/audio_pos

Core Audio: add get_pos() method
This commit is contained in:
Mathieu Virbel 2012-09-13 16:18:54 -07:00
commit c691474b49
3 changed files with 25 additions and 2 deletions

View File

@ -129,6 +129,14 @@ class Sound(EventDispatcher):
return
self.load()
def get_pos(self):
'''
get the current position of the audio file. returns 0 if not playing
.. versionadded:: 1.4.1
'''
return 0
def _get_length(self):
return 0

View File

@ -1,4 +1,4 @@
'''
'''
AudioGstreamer: implementation of Sound with GStreamer
'''
@ -94,6 +94,16 @@ class SoundGstreamer(Sound):
self._data.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_SKIP,
position / 1000000000.)
def get_pos(self):
if self._data is not None:
if self._data.get_state()[1] == gst.STATE_PLAYING:
try:
return self._data.query_position(gst.Format
(gst.FORMAT_TIME))[0] / 1000000000.
except:
pass
return 0
def _get_volume(self):
if self._data is not None:
self._volume = self._data.get_property('volume')
@ -122,4 +132,4 @@ class SoundGstreamer(Sound):
(gst.FORMAT_TIME))[0] / 1000000000.
return super(SoundGstreamer, self)._get_length()
SoundLoader.register(SoundGstreamer)
SoundLoader.register(SoundGstreamer)

View File

@ -78,6 +78,11 @@ class SoundPygame(Sound):
# Unable to seek in pygame...
pass
def get_pos(self):
if self._data is not None:
return mixer.music.get_pos()
return 0
def _get_volume(self):
if self._data is not None:
self._volume = self._data.get_volume()