Hi All, I am experimenting with the Camera and Camera2 libraries for a project here at work, i am currently experimenting with the Camera2 library, for still pictures everything works as expected, but when I switch from still mode to video mode i get the following error:
The example written by Erel crashes at the following line
the whole function where that above line resides is below:
Any ideas as to why this is, I have also tried this example on my Samsung Galaxy S9+ running Android 9.0 and I still see the same issue, on my Galaxy i don't see an error but instead i only see a white Panel with the Camera button on it.
Any help will be very much appreciated guys.
Walter
Error occurred on line: 123 (CamEx2)
java.io.IOException: prepare failed.
at android.media.MediaRecorder._prepare(Native Method)
at android.media.MediaRecorder.prepare(MediaRecorder.java:981)
at anywheresoftware.b4a.objects.Camera2.StartSession(Camera2.java:273)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:780)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:363)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1736)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
The example written by Erel crashes at the following line
B4X:
Camera.StartSession(tv, PreviewSize, CaptureSize, 0, 0, True)
the whole function where that above line resides is below:
B4X:
Public Sub PrepareSurfaceForVideo (MyTaskIndex As Int, Dir As String, FileName As String) As ResumableSub
If MyTaskIndex <> TaskIndex Then Return False
CloseSession
Wait For (CreateSurface) Complete (Result As Boolean)
If MyTaskIndex <> TaskIndex Then Return False
File.Delete(Dir, FileName)
MediaRecorder = Camera.CreateMediaRecorder(PreviewSize, Dir, FileName)
Dim rotation As Int = jcamera.GetField("lastKnownOrientation")
Dim SensorOrientation As Int = GetFromCameraCharacteristic("SENSOR_ORIENTATION")
Dim orientations As List
If SensorOrientation = 90 Then
orientations = Array(90, 0, 270, 180)
Else
orientations = Array(270, 180, 90, 0)
End If
MediaRecorder.RunMethod("setOrientationHint", Array(orientations.Get(Floor(rotation / 90))))
LogColor("previewsize: " & PreviewSize.Width & " -- " & PreviewSize.Height & " " & "capturesize: " & CaptureSize.Width & " -- " & CaptureSize.Height, Colors.Blue)
Log("tv initialized: " & tv.IsInitialized)
Camera.StartSession(tv, PreviewSize, CaptureSize, 0, 0, True)
Wait For Camera_SessionConfigured (Success As Boolean)
If MyTaskIndex <> TaskIndex Then Return False
Return Success
End Sub
Any ideas as to why this is, I have also tried this example on my Samsung Galaxy S9+ running Android 9.0 and I still see the same issue, on my Galaxy i don't see an error but instead i only see a white Panel with the Camera button on it.
Any help will be very much appreciated guys.
Walter