Android Question MediaPlayer - java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method)

MaaMoz

Member
Licensed User
Longtime User
Hello friendly b4a community

In my privatly used app I use in several Activities MediaPlayers which are declared in Process_Globals of the relevant Activity.
To increase the Play Speed, I use the following code.

B4X:
Private Sub setPlaySpeed
    Private jo As JavaObject
    jo = mpX
    jo = jo.GetField("mp") 'Get the native Mediaplayer object
   
    If fltPlaySpeed = -1 Then fltPlaySpeed = 1.0

    Dim PP As JavaObject = jo.RunMethod("getPlaybackParams", Null)
    PP.RunMethod("setSpeed", Array(fltPlaySpeed))
    jo.RunMethod("setPlaybackParams", Array(PP))
End Sub

' The MediaPlayers are declared in Process_Globals as: Private mpX As MediaPlayer
' fltPlaySpeed is declared in Process_Globals as: Private fltPlaySpeed As Float = -1

The above code works perfectly in 3 different Activities.

When I added the exactly same code to the Main Activity, the following error occurs.
What could be the cause?

java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
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:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at aamr.biread.mm.main._setplayspeed(main.java:14026)
at aamr.biread.mm.main._lblspeedup_click(main.java:14097)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:8047)
at android.widget.TextView.performClick(TextView.java:17792)
at android.view.View.performClickInternal(View.java:8024)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:31890)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8919)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Caused by: java.lang.IllegalArgumentException
at android.media.MediaPlayer.setPlaybackParams(Native Method)
... 34 more
 
Last edited:

MaaMoz

Member
Licensed User
Longtime User
(Switch to B4XPages and everything will be much simpler)

This is the relevant error message:
Caused by: java.lang.IllegalArgumentException
at android.media.MediaPlayer.setPlaybackParams(Native Method)

The call to setPlaybackParams fail. There is no other related information about the error.
I thank you very much for your kind and friendly reply. Enjoy your day.
 
Upvote 0
Top