I have code:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.core.audio import SoundLoader
from kivy.graphics.context_instructions import Color
class TestApp(App):
def build(self):
fl = FloatLayout()
try:
sound = SoundLoader.load('magic.mp3')
if sound:
print("Sound found at %s" % sound.source)
print("Sound is %.3f seconds" % sound.length)
fl.add_widget(Label(text=str("Sound found at %s" % sound.source), pos=(0, 0), font_size=(40)))
sound.play()
except Exception as error:
fl.add_widget(Label(text=str(error), pos=(0, 0), font_size=(40)))
return fl
if __name__ == "__main__":
TestApp().run()
I this code I use magic.mp3 and I want to be able to use it in .apk
file, but there isn't it. I thought I should add .mp3
files in buildozer.spec
:
# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,mp3
And I also added:
# (list) List of inclusions using pattern matching
source.include_patterns = assets/*,magic/*.mp3
But I cann't play this file, and I get the error:
'NoneType' object has no attribute 'source'
How to fix it? I hope you help me
Here's a belated answer, FWIW. I think your problem is not that your mp3 isn't found, but that your file is in mp3. The SDL2 library in python-for-android doesn't support mp3 at the moment (see https://github.com/kivy/kivy/issues/5412 ).
You should be able to work around this by converting your mp3 file to wav or ogg.