SoundLoader.load crashes in Kivy kv
08:57 10 Dec 2025

Kivy SoundLoader.load() crashes (block) if I use KV for UI building, but works fine, when I do widgets in the code. What's the cause? And ho to solve it?

The code, reduced to the load method which blocks everything. I removed the play part for simplicity to show the problem here.

This doesn't work:

my.kv:

#:kivy 1.0.9

MyButton:
    text: "MyButton"

my.py

from kivy.uix.button import Button
from kivy.core.audio import SoundLoader


class MyButton(Button): pass


class MyApp(App):
    sound = None

    def build(self):
        self.sound = SoundLoader.load('music.mp3')
        return super().build()


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

But this works:

my.py:

from kivy.uix.button import Button
from kivy.core.audio import SoundLoader


class MyApp(App):
    sound = None

    def build(self):
        self.sound = SoundLoader.load('music.mp3')
        button = Button(text='Play Audio')
        return button


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

I also traced back where the SoundLoader.load() stops. Soundloader.load() iterates Soundloader._classes as classobj (here: SoundAvplayer) and calls the respective extensions() method to get a list of allowed file extensions. And exactly here inside SoundAvPlayer.extensions() stops the program. Although it only has to return a simple list (or tuple) of strings.

Any idea?

python audio kivy