SDL2 audio provider is not working in some Linux distributions.
See original GitHub issueVersions
- Python: 3.7
- Kivy: 1.11.1
- Kivy installation method: pip
- OS: reported by users in Ubuntu 18.04, Xubuntu 19.04, Debian.
Description
I’ve seen some issue reports (for example, https://github.com/kivy/kivy/issues/6536 and https://github.com/kivy/kivy/issues/6512) that cannot reproduce audio using SDL2. It was also reported with ffpyplayer, but seems to be patched in the latest release (see https://github.com/matham/ffpyplayer/issues/71#issuecomment-554074454).
I’ve been trying different things to make it work, and finally I realised that the problem is the way the wheel is built in pip. If you try to install with pip install https://github.com/kivy/kivy/archive/stable.zip
(or with the dev branch) and sdl2 installed, it works because pip builds a fresh wheel. It is not really neccesary to download and compile sdl2 from the web, it is enough to install the sdl2 package from distro repositories.
Code and Logs
Example:
import os
os.environ["KIVY_AUDIO"] = "sdl2"
from kivy.core.audio import SoundLoader
sound = SoundLoader.load('mytest.wav')
if sound:
print("Sound found at %s" % sound.source)
print("Sound is %.3f seconds" % sound.length)
sound.play()
where mytest.wav
is any audio file supported by SDL2.
Please, make sure that you see something like:
[INFO ] [Audio ] Providers: audio_sdl2
in your log, to ensure that audio_sdl2 is installed and being used.
If you try and have the same issue I’m reporting, you should see something like this:
[CRITICAL] [AudioSDL2 ] Unable to open mixer: b'No such audio device'
[WARNING] Deprecated property "<AliasProperty name=filename>" of object "<kivy.core.audio.audio_sdl2.SoundSDL2>" was accessed, it will be removed in a future version
[WARNING] [AudioSDL2 ] Unable to load (...): b"Audio device hasn't been opened"
If you need help with testing or something, just tell me.
Greetings.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Was getting the same error on Ubuntu 18.04. Reinstalled kivy using your suggested way:
pip install https://github.com/kivy/kivy/archive/stable.zip
And the problem is gone. Thank your @Franccisco.
I’m having the same issue and this did not fix my problem, I’m still getting the same output. I’m in Ubuntu 18.04.
Following @johnlawrenceaspden instructions the audio works but just for a fraction of a second, the output seems fine: