mirror of https://github.com/kivy/kivy.git
Merge pull request #679 from kivy/audio_pos
Core Audio: add get_pos() method
This commit is contained in:
commit
c691474b49
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue