问题
I've got a problem where Kivy uses sdl2 on android, and works fine, but on linux it uses ffpyplayer, which doesn't.
So I'd like to get Kivy to use sdl2 on linux too, however sdl2 doesn't seem to work at all on linux.
$ KIVY_AUDIO=sdl2 python min_audio_example.py
[INFO ] [Audio ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
[CRITICAL] [AudioSDL2 ] Unable to open mixer: b'No such audio device'
Here's a minimal example with demonstrates the problem.
#!/usr/bin/env python
# works with:
# export KIVY_AUDIO=ffpyplayer
# fails with:
# export KIVY_AUDIO=sdl2
from kivy.app import App
from kivy.core.audio import SoundLoader
def playsound(dummy):
sound = SoundLoader.load("440Hz_44100Hz_16bit_05sec.ogg")
if sound:
print("Sound found at %s" % sound.source)
print("Sound is %.3f seconds" % sound.length)
print("sound state", sound.state)
sound.play()
print("sound state", sound.state)
import time
time.sleep(5)
class TestApp(App):
playsound(None)
if __name__ == '__main__':
TestApp().run()
I think it might be something to do with how the kivy wheel is built, so I tried
pip uninstall kivy
pip install -U --no-binary=:all: kivy
At that point, kivy doesn't seem to see sdl2 at all!
$ KIVY_AUDIO=sdl2 python min_audio_example.py
[INFO ] [Audio ] Providers: (audio_ffpyplayer, audio_pygame ignored)
[WARNING] [Audio ] Unable to find a loader for </home/john/data/sight-sing/sightsinger/440Hz1secfadeinandout.ogg>
It's now listing audio_ffpyplayer, and audio_pygame as providers, and not using either because of the environment variable. (The pygame provider also seems broken, but ffpyplayer still works)
Can anyone help?
回答1:
It is the kivy wheel build, and my attempted fix was nearly right.
The problem is that if kivy is built with a missing dependency, it will build without support for things, but not complain.
So, on debian, install kivy's dependencies:
(https://kivy.org/doc/stable/installation/installation-linux-venvs.html#installation-in-venv)
sudo apt-get install python-pip build-essential git python python-dev ffmpeg libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev zlib1g-dev
then:
pip uninstall kivy
then install without using the broken pre-built wheel
pip install --no-binary kivy kivy
来源:https://stackoverflow.com/questions/60096291/how-can-i-get-kivy-to-use-sdl2-on-linux