From 19fc129722fa0f77b1b8195fa6d49d33bfc5fec0 Mon Sep 17 00:00:00 2001 From: Qua-non Date: Fri, 14 Sep 2012 04:39:21 +0530 Subject: [PATCH] Core Audio: add get_pos method --- kivy/core/audio/__init__.py | 8 ++++++++ kivy/core/audio/audio_gstreamer.py | 14 ++++++++++++-- kivy/core/audio/audio_pygame.py | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/kivy/core/audio/__init__.py b/kivy/core/audio/__init__.py index ec55a31dd..869975e9a 100644 --- a/kivy/core/audio/__init__.py +++ b/kivy/core/audio/__init__.py @@ -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 diff --git a/kivy/core/audio/audio_gstreamer.py b/kivy/core/audio/audio_gstreamer.py index 3d3c92847..a1fee4582 100644 --- a/kivy/core/audio/audio_gstreamer.py +++ b/kivy/core/audio/audio_gstreamer.py @@ -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) \ No newline at end of file diff --git a/kivy/core/audio/audio_pygame.py b/kivy/core/audio/audio_pygame.py index 7d064ad6d..07d326d4a 100644 --- a/kivy/core/audio/audio_pygame.py +++ b/kivy/core/audio/audio_pygame.py @@ -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()