Reputation: 51
I am trying to play sounds through kivy, but have been unable to make it work. On releasing the button, the method appears to run successfully (i.e. the print statement runs, the app doesn't crash and no error message appears), but no sound is played. Having looked at the kivy data logger, the warning in the title is displayed.
from kivy.app import App
from kivy.core.audio import SoundLoader
from kivy.uix.boxlayout import BoxLayout
class Play(BoxLayout):
sound_done = SoundLoader.load('beep-01a.wav')
sound_finishing = SoundLoader.load('beep-07.wav')
def play_sound_1(self):
self.sound_finishing.play()
print ("sound 1")
def play_sound_2(self):
self.sound_done.play()
print ("sound 2")
class Sound(App):
def build(self):
p=Play()
#p.start()
return p
if __name__ == "__main__":
Sound().run()
<BoxLayout>
Button:
text: "sound 1"
on_release:
root.play_sound_1()
Button:
text: "sound 2"
on_release:
root.play_sound_2()
[INFO ] [Logger ] Record log in C:\Users\User\.kivy\logs\kivy_19-
07-15_9.txt
[INFO ] [Kivy ] v1.11.0
[INFO ] [Kivy ] Installed at "C:\ProgramData\Anaconda3\lib\site-
packages\kivy\__init__.py"
[INFO ] [Python ] v3.7.1 (default, Dec 10 2018, 22:54:23) [MSC
v.1915 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at
"C:\ProgramData\Anaconda3\python.exe"
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil,
img_gif (img_ffpyplayer ignored)
[INFO ] [Audio ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
[WARNING] Deprecated property "<AliasProperty name=filename>" of object "
<kivy.core.audio.audio_sdl2.SoundSDL2 object at 0x0000028632B1CAD8>" was
accessed, it will be removed in a future version
[WARNING] [AudioSDL2 ] Unable to load beep-01a.wav: b'Mix_LoadWAV_RW
with NULL src'
[WARNING] [AudioSDL2 ] Unable to load beep-07.wav: b'Mix_LoadWAV_RW with
NULL src'
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.5.13467 Compatibility Profile
Context 21.19.414.1792'>
[INFO ] [GL ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO ] [GL ] OpenGL renderer <b'AMD Radeon R7 Graphics'>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <b'4.50'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not
docked
[INFO ] [Text ] Provider: sdl2
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
sound 2
sound 2
sound 1
sound 1
[INFO ] [WindowSDL ] exiting mainloop and closing.
[INFO ] [Base ] Leaving application in progress...
Process finished with exit code 0
I have tried using the wav, mp3 and ogg sound file types, but none have worked. I have been stuck on this for quite a while, so any help would be hugely appreciated! Thanks
Upvotes: 1
Views: 1227
Reputation: 1
add mp3 to buildozer.spec source.include_exts = py,png,jpg,kv,atlas,mp3
Upvotes: 0
Reputation: 3
Perhaps the path you gave to the audio file is incorrect. You just provided the name of the file.
I, too, had this error and landed here... realized the message:
b'Mix_LoadWAV_RW with NULL src'
might be saying the path to the wav was null on loading the wav - maybe file not found.
I fixed this error by correcting the relative path to the wav file in my app structure.
For example, if file.wav is at /app/data/file.wav, and the main application is at /app/main.py, the path provided to SoundLoader.load() should be 'data/file.wav'.
It will likely be more portable if you add a solution using os.path.join(abs,rel)
Cheers.
Upvotes: 0