Search code examples
pythonandroidaudiokivybuildozer

Jnuis wont work after asking android for external storage permission. Why?


When i run my program with this code:

from jnius import autoclass
MediaPlayer = autoclass('android.media.MediaPlayer')
mPlayer = MediaPlayer()

from android.permissions import request_permissions, Permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

It works totally fine, well when i dont do any jnius after asking permission... I am trying to play sound btw, tried kivy audio but when it loaded the audio (.wav file) it just crashed...

And when i swap the to parts out like so:

from android.permissions import request_permissions, Permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

from jnius import autoclass
MediaPlayer = autoclass('android.media.MediaPlayer')
mPlayer = MediaPlayer()

It just crashes after a few seconds... How do i fix this? I just want to play sounds... (from external storage)

Thx in advance.

Edit: if i do this:

sound = SoundLoader.load('dir/air_spray2.wav')
if sound:
    sound.play()

It plays like a tenth of a second of the song and then it just crashes the app(reason why i cant use kivy soundloader)


Solution

  • I somehow found out myself, just delete it

    from android.permissions import request_permissions, Permission
    request_permissions([Permission.WRITE_EXTERNAL_STORAGE])
    

    =

    and add it to the manifest... not both, just in the manifest... android.permission =