Android Question Camera2 App crash on video with front camera

Alexander Stolte

Expert
Licensed User
Longtime User
Hello,

i use this example, because there is the error too.
If you swtich to video mode and then to the front camera, then record a video and stop the video. The Error is on line 134 in the "CamEx2" class.

The following error message:

B4X:
Logger connected to:  samsung SM-G935F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Start success: true
(Rect)(0, 0, 2608, 1960)
Error occurred on line: 134 (CamEx2)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at b4a.example3.camex2._stopvideorecording(camex2.java:437)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
    at b4a.example3.main$ResumableSub_CaptureVideo.resume(main.java:1073)
    at b4a.example3.main._capturevideo(main.java:1061)
    at b4a.example3.main._btnrecord_click(main.java:1049)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:6213)
    at android.widget.TextView.performClick(TextView.java:11074)
    at android.view.View$PerformClick.run(View.java:23645)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6692)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.RuntimeException: stop failed.
    at android.media.MediaRecorder._stop(Native Method)
    at android.media.MediaRecorder.stop(MediaRecorder.java:1205)
    ... 33 more
Error: (Exception) java.lang.Exception:  java.lang.reflect.InvocationTargetException
Start success: true
(Rect)(0, 0, 2608, 1960)

My Phone: Samsung S7 Edge with Android 7 (7.0)
CamEx2 Version: 1.20
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works properly here, tested on Android 5X.

See the answer here: https://stackoverflow.com/a/16222037/971547

I guess that it failed to record anything so it raised an error.

You can change the code to:
B4X:
Public Sub StopVideoRecording (MyTaskIndex As Int)
   CloseSession
   Try
       MediaRecorder.RunMethod("stop", Null)
   Catch
       Log(LastException)
   End Try
   RecordingVideo = False
End Sub
 
Upvote 0
Top