Skip to content

seek, get_pos and get_length support for mediaplayer #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2013
Merged

Conversation

akshayaurora
Copy link
Member

Testing with the following code and android_mediaplayer_seek_length branch of kivy for the changes that were needed to audio_pygame. Currently wrong pos(off by a few secs) is displayed with vorbis files (known issue with Android MediaPlayer).

from kivy.app import App
from kivy.core.audio import SoundLoader
from kivy.clock import Clock
from kivy.logger import Logger
from kivy.lang import Builder

root = Builder.load_string('''
BoxLayout:
    audio_pos: 0
    orientation: 'vertical'
    Label:
        text: str(slider.value)
    Slider:
        id: slider
        min: 0.0
        value: root.audio_pos
    BoxLayout
        Button:
            text: "play"
            on_press:
                root.sound.play()
                root.upd_pos()
        Button:
            text: 'stop'
            on_release:
                root.sound.stop()
                slider.value = 0.0
                root.upd_pos(stop=True)
        Button:
            text: 'seek to 20.0'
            on_release: root.sound.seek(20.0)
''')

class TestApp(App):
    def build(self):
        root.sound = SoundLoader.load('audio02.ogg')
        root.upd_pos = self.upd_pos
        return root

    def upd_pos(self, stop=False):
        if stop:
            Clock.unschedule(self.get_pos)
        else:
            Clock.unschedule(self.get_pos)
            Clock.schedule_interval(self.get_pos, 1./9.)

    def get_pos(self, dt):
        root.ids.slider.max = root.sound._get_length()
        root.audio_pos = root.sound.get_pos()

if __name__ == '__main__':
    TestApp().run()

@tito
Copy link
Member

tito commented Apr 11, 2013

Dude, perfect PR. Really. !

tito added a commit that referenced this pull request Apr 11, 2013
seek, get_pos  and get_length support for mediaplayer
@tito tito merged commit 1ce9ae9 into master Apr 11, 2013
@tito tito deleted the seek_support branch April 11, 2013 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants