Android Question Camera2 CameraEX class Error when switching to Video

walterf25

Expert
Licensed User
Longtime User
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
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
 

walterf25

Expert
Licensed User
Longtime User
Does it help if you add a call to Sleep(300) after the previous session ends and before the new one opens?
No it does not.

Walter
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…