我有代码:
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()
在这段代码中,我使用了magic.mp3,并且我希望能够在.apk
文件中使用它,但是没有这个功能。我想我应该在buildozer.spec
中添加.mp3
文件
# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,mp3
我还补充道:
# (list) List of inclusions using pattern matching
source.include_patterns = assets/*,magic/*.mp3
但是我不能播放这个文件,我得到了错误:
'NoneType' object has no attribute 'source'
如何修复它?我希望你能帮我
发布于 2020-07-09 15:07:53
这是一个迟来的答案,FWIW。我认为你的问题不是你的mp3找不到,而是你的文件在mp3中。python-for-android中的SDL2库目前不支持mp3 (参见https://github.com/kivy/kivy/issues/5412 )。
你应该能够通过将你的mp3文件转换成wav或ogg来解决这个问题。
https://stackoverflow.com/questions/60023813
复制相似问题