Reputation: 43
Why can't I load sounds with Kivy, when I'm following the instructions on the Kivy website precisely? Any help is greatly appreciated!
The following example is from https://kivy.org/docs/api-kivy.core.audio.html:
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()
I've copied and pasted this example into a blank Python file, and ran the code. I've made sure to use a valid wav file for 'mytest.wav', and have placed the wav file in the same directory as the Python file.
I get the following error message:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/MyUsername/PycharmProjects/MyProject/sound_test.py
[INFO ] [Logger ] Record log in /Users/MyUsername/.kivy/logs/kivy_17-10-24_4.txt
[INFO ] [Kivy ] v1.10.1.dev0, git-Unknown, 20170911
[INFO ] [Python ] v3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
[INFO ] [AudioGstplayer] Using Gstreamer 1.12.2.0
[INFO ] [Audio ] Providers: audio_gstplayer, audio_sdl2 (audio_ffpyplayer, audio_avplayer ignored)
Traceback (most recent call last):
File "/Users/MyUsername/PycharmProjects/MyProject/sound_test.py", line 3, in <module>
sound = SoundLoader.load("mytest.wav")
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/kivy/core/audio/__init__.py", line 86, in load
return classobj(source=filename)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/kivy/core/audio/audio_gstplayer.py", line 45, in __init__
super(SoundGstplayer, self).__init__(**kwargs)
File "kivy/_event.pyx", line 262, in kivy._event.EventDispatcher.__init__
File "kivy/properties.pyx", line 478, in kivy.properties.Property.__set__
File "kivy/properties.pyx", line 516, in kivy.properties.Property.set
File "kivy/properties.pyx", line 571, in kivy.properties.Property.dispatch
File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/kivy/core/audio/__init__.py", line 174, in on_source
self.load()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/kivy/core/audio/audio_gstplayer.py", line 62, in load
self.player.load()
File "kivy/lib/gstplayer/_gstplayer.pyx", line 233, in kivy.lib.gstplayer._gstplayer.GstPlayer.load
kivy.lib.gstplayer._gstplayer.GstPlayerException: Unable to create a playbin
Process finished with exit code 1
I've also tried getting rid of the code below line 3, but that doesn't affect the error message.
Upvotes: 1
Views: 2233
Reputation: 335
For anyone else who comes across this issue on OS X. The problem for me was the kivy.lib.gstreamer directory. After I removed this directory SoundLoader worked fine.
Go to terminal and navigate to where Kivy is installed. On my machine it was in usr/local/lib/python3.7/site-packages/kivy/lib
Once you are in /lib type:
rm -R gstreamer
Upvotes: 1
Reputation: 2645
On windows every extensions of music files work since kivy came with GStreamer that handle all the formats but On some other platform only the .ogg works, convert your file to the ogg format then retry.
If it does not work, I think there is a problem with your kivy installation please try to re-install kivy following those steps:
1.Install the requirements using homebrew:
$ brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer
2.Install cython 0.23 and kivy using pip:
$ pip install -I Cython==0.23
$ USE_OSX_FRAMEWORKS=0 pip install kivy
I really hope this works since I don't have mac os to test it
Upvotes: 0