Android Question mp.load problem

Tomas Petrus

Active Member
Licensed User
Updating old Android App to new versions and got a problem with mediaplayer

this is updated code supposed to play sound if the file exist
B4X:
Sub PlaySound(Zvuk As String, Opakovani As Boolean)
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then Return

    Dim cesta As String = rp.GetSafeDirDefaultExternal("shared")
       
    If File.Exists(cesta,Zvuk) = False Then
        LogColor("neeexistuje",Colors.Magenta)
    Else
        LogColor("Existuje",Colors.Magenta)
        mp.Load(cesta, Zvuk)
        mp.Looping = Opakovani
        mp.Play
    End If
End Sub
check for exists pass and then it crash on mp.load

B4X:
Error occurred on line: 2516 (Main)
java.io.IOException: Prepare failed.: status=0x1
    at android.media.MediaPlayer._prepare(Native Method)
    at android.media.MediaPlayer.prepare(MediaPlayer.java:1310)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.loadAfterReset(MediaPlayerWrapper.java:101)
    at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:66)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
any ideas ?
 

Erel

Administrator
Staff member
Licensed User
You don't need to request any permission here. Watch the runtime permissions video tutorial.

The problem is somewhere else.
 

Tomas Petrus

Active Member
Licensed User
I thought so, but tried already all other ideas ...so..

any leads where the problem could be ? the file is added with file manager, exists check is ok and then on load it crashes..
 

Tomas Petrus

Active Member
Licensed User
Yep the old version were downloading the files from somewhere but after update it stoped working so I tried to include sound files directly to the app. and yes those sound files are in Files folder now
 
Top