SoundSDL2 freezes when loading audio
Software Versions
- Python: 3.13.2
- OS:Linux 6.12.17-amd64
- Kivy: 2.3.1
- Kivy installation method: apt
Describe the bug
kivy.core.audio.audio_sdl2.SoundSDL2 freezes when trying to load '.oga' audio after UI is shown
Expected behavior Either of the following:
- the sound is loaded
- an exception is thrown
- a warning is logged and None is returned
To Reproduce
Code and Logs and screenshots
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.core.audio import SoundLoader
class PongApp(App):
def build(self):
Clock.schedule_interval(self.update, 1)
return Widget()
def update(self, dt):
self.sound = SoundLoader.load('/usr/share/sounds/freedesktop/stereo/service-login.oga')
exit()
if __name__ == '__main__':
PongApp().run()
Additional context
At the same time the following code logs a warning and sets sound to None.
from kivy.core.audio import SoundLoader
sound = SoundLoader.load('/usr/share/sounds/freedesktop/stereo/service-login.oga')
[INFO ] [Audio ] Providers: audio_gstplayer, audio_sdl2 (audio_ffpyplayer ignored)
[WARNING] [Audio ] Unable to find a loader for </usr/share/sounds/freedesktop/stereo/service-login.oga>
Sidenote: Using SoundGstplayer in both cases load the audio correctly.
from kivy.core.audio.audio_gstplayer import SoundGstplayer
sound = SoundGstplayer(source='/usr/share/sounds/freedesktop/stereo/service-login.oga')
I've run into this as well, but wasn't able to narrow it down this far. Thanks @pe7ro !
All I knew was that my kivy app (game) was freezing completely at some point, if I used a python variant of 3.13 (3.10, 3.11, 3.12 are fine).
It's definitely something with SoundLoader. Commenting out its usage, 3.13 no longer freezes.
I figured I'd chime in to specify it's definitely not an issue with versions of python prior to 3.13.
I can confirm that the code above freezes when run. (Note: I added from kivy.clock import Clock to the imports)
Python: 3.12.3 OS: Ubuntu 24.04 (kernel 6.8.8) Kivy: 2.3.1
The code works correctly (exits normally) with Kivy 2.3.0. (pip install kivy==2.3.0)
Original application context: https://github.com/sanderland/katrain/issues/773
It (SoundLoader.load) freezes on Windows with Kivy 2.3.0
Python: 3.12.2
OS: Windows 11
Kivy: 2.3.0
Workaround:
if platform.system() == 'Windows':
from kivy.core.audio.audio_sdl2 import MusicSDL2
else:
from kivy.core.audio import SoundLoader
#...
def play():
if platform.system() == 'Windows':
sound = MusicSDL2(source=path)
else:
sound = SoundLoader.load(path)
Clock.schedule_once(lambda dt: sound.play(), 0)