Domanda

I need to use on_stop event in Kivy but it seems not to be working . please see below code

Any Advice : I am using kivy 1.8

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.core.audio import SoundLoader


class MyApp(App):
    def build(self):
        sound = SoundLoader.load("some_sound.ogg")
        sound.on_stop = sound.play
        sound.play()



        return Widget()

if __name__ in ('__android__', '__main__'):
    MyApp().run()

I even tried using state to run the sound in loop however its very weird that even when the song is stopped it still prints its state as play . Can someone advice what is wrong in this ?

Below Code:

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.core.audio import SoundLoader
from kivy.clock import Clock


class MyApp(App):
    def build(self):
        self.sound = SoundLoader.load("playScreen.wav")
        self.sound.on_stop = self.update
        self.sound.play()

        Clock.schedule_interval(self.update, 1.0/1)
        return Widget()

    def update(self,dt):
        print "state is ",self.sound.state
        if self.sound.state == 'stop':
            self.sound.play()

if __name__ in ('__android__', '__main__'):
    MyApp().run()
È stato utile?

Soluzione

This is a bug in audio_gstplayer.py - when EOS is reached, the GstPlayer is stopped, but the Sound.state is not updated, nor is the on_stop event fired.

If you just want the sound to continually loop, however, you can set the loop property.

sound = SoundLoader.load('some_sound.ogg')
sound.loop = True
sound.play()

EDIT: Submitted pull request https://github.com/kivy/kivy/pull/2131

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top