实际上我正在尝试kivy音频,它在linux上运行良好但是当我制作它的apk并在android中测试然后应用程序崩溃。这是代码和日志。
代码: -
import glob
import os
from kivy.app import App
from kivy.uix.relativelayout import RelativeLayout
from kivy.lang import Builder
from kivy.core.audio import SoundLoader
Builder.load_string('''
<hey>:
RelativeLayout:
Button:
id:change
text:"hi"
on_press:root.yeah()
''')
class hey(RelativeLayout):
def yeah(self):
#k = glob.glob("/root/.")
k=glob.glob('/sdcard/shivam.mp3')
print(k)
self.ids.change.text="%s"%k
self.song=SoundLoader.load('/sdcard/shivam.mp3')
return self.song.play()
class hello(App):
def build(self):
return hey()
hello().run()
日志: -
10-01 16:36:00.038 23853 24004 I python : [WARNING] [Config ] Older configuration version detected (0 instead of 19)
10-01 16:36:00.038 23853 24004 I python : [WARNING] [Config ] Upgrading configuration in progress.
10-01 16:36:00.045 23853 24004 I python : [INFO ] [Logger ] Record log in /data/user/0/org.kivy.example.audio/files/app/.kivy/logs/kivy_17-10-01_0.txt
10-01 16:36:00.045 23853 24004 I python : [INFO ] [Kivy ] v1.10.0
10-01 16:36:00.045 23853 24004 I python : [INFO ] [Python ] v2.7.2 (default, Aug 7 2017, 20:14:35)
10-01 16:36:00.045 23853 24004 I python : [GCC 4.8]
10-01 16:36:00.076 23853 24004 I python : [INFO ] [Factory ] 194 symbols loaded
10-01 16:36:00.607 23853 24004 I python : [INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
10-01 16:36:00.643 23853 24004 I python : [INFO ] [Audio ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
10-01 16:36:00.731 23853 24004 I python : [INFO ] [OSC ] using <thread> for socket
10-01 16:36:00.735 23853 24004 I python : [INFO ] [Window ] Provider: sdl2
10-01 16:36:00.769 23853 24004 I python : [INFO ] [GL ] Using the "OpenGL ES 2" graphics system
10-01 16:36:00.770 23853 24004 I python : [INFO ] [GL ] Backend used <gl>
10-01 16:36:00.770 23853 24004 I python : [INFO ] [GL ] OpenGL version <OpenGL ES 3.2 V@145.0 (GIT@I3d52eaf367)>
10-01 16:36:00.772 23853 24004 I python : [INFO ] [GL ] OpenGL vendor <Qualcomm>
10-01 16:36:00.772 23853 24004 I python : [INFO ] [GL ] OpenGL renderer <Adreno (TM) 506>
10-01 16:36:00.773 23853 24004 I python : [INFO ] [GL ] OpenGL parsed version: 3, 2
10-01 16:36:00.774 23853 24004 I python : [INFO ] [GL ] Texture max size <16384>
10-01 16:36:00.783 23853 24004 I python : [INFO ] [GL ] Texture max units <16>
10-01 16:36:00.869 23853 24004 I python : [INFO ] [Window ] auto add sdl2 input provider
10-01 16:36:00.874 23853 24004 I python : [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
10-01 16:36:00.894 23853 24004 I python : [INFO ] [Text ] Provider: sdl2
10-01 16:36:01.395 23853 24004 I python : [WARNING] [Base ] Unknown <android> provider
10-01 16:36:01.396 23853 24004 I python : [INFO ] [Base ] Start application main loop
10-01 16:36:01.402 23853 24004 I python : [INFO ] [GL ] NPOT texture support is available
10-01 16:36:01.406 23853 24004 I python : [ERROR ] [Base ] Failed to import "android" module. Could not remove android presplash.
10-01 16:36:04.487 23853 24004 I python : ['/sdcard/shivam.mp3']
10-01 16:36:04.537 23853 24004 I python : [WARNING] [Audio ] Unable to find a loader for </sdcard/shivam.mp3>
10-01 16:36:04.538 23853 24004 I python : [INFO ] [Base ] Leaving application in progress...
10-01 16:36:04.538 23853 24004 I python : Traceback (most recent call last):
10-01 16:36:04.539 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/app/main.py", line 34, in <module>
10-01 16:36:04.541 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/app.py", line 828, in run
10-01 16:36:04.542 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/base.py", line 504, in runTouchApp
10-01 16:36:04.543 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/core/window/window_sdl2.py", line 663, in mainloop
10-01 16:36:04.544 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/core/window/window_sdl2.py", line 405, in _mainloop
10-01 16:36:04.545 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/base.py", line 342, in idle
10-01 16:36:04.546 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/base.py", line 327, in dispatch_input
10-01 16:36:04.546 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/base.py", line 233, in post_dispatch_input
10-01 16:36:04.548 23853 24004 I python : File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:8191)
10-01 16:36:04.549 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/core/window/__init__.py", line 1188, in on_motion
10-01 16:36:04.549 23853 24004 I python : File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:8191)
10-01 16:36:04.550 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/core/window/__init__.py", line 1204, in on_touch_down
10-01 16:36:04.551 23853 24004 I python : File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:8191)
10-01 16:36:04.551 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/uix/relativelayout.py", line 288, in on_touch_down
10-01 16:36:04.552 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/uix/widget.py", line 457, in on_touch_down
10-01 16:36:04.552 23853 24004 I python : File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:8191)
10-01 16:36:04.553 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/uix/relativelayout.py", line 288, in on_touch_down
10-01 16:36:04.553 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/uix/widget.py", line 457, in on_touch_down
10-01 16:36:04.554 23853 24004 I python : File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:8191)
10-01 16:36:04.554 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/uix/behaviors/button.py", line 151, in on_touch_down
10-01 16:36:04.555 23853 24004 I python : File "kivy/_event.pyx", line 714, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:8146)
10-01 16:36:04.555 23853 24004 I python : File "kivy/_event.pyx", line 1225, in kivy._event.EventObservers.dispatch (kivy/_event.c:14035)
10-01 16:36:04.555 23853 24004 I python : File "kivy/_event.pyx", line 1109, in kivy._event.EventObservers._dispatch (kivy/_event.c:12816)
10-01 16:36:04.556 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/platform/build/dists/audio/private/lib/python2.7/site-packages/kivy/lang/builder.py", line 64, in custom_callback
10-01 16:36:04.556 23853 24004 I python : File "<string>", line 7, in <module>
10-01 16:36:04.557 23853 24004 I python : File "/root/plyer/examples/audio/.buildozer/android/app/main.py", line 25, in yeah
10-01 16:36:04.557 23853 24004 I python : AttributeError: 'NoneType' object has no attribute 'play'
10-01 16:36:04.600 23853 24004 I python : Python for android ended.
如何删除此错误?我认为这里Soundloader
没有加载mp3
文件。之前有人通过kivy试过Android的音频和视频吗?需要帮助
答案 0 :(得分:0)
在 buildozer.spec 文件的要求中添加 ffpyplayer。同样在代码的开头添加行 os.environ["KIVY_AUDIO"] = "ffpyplayer"
它对我有用。