Initializing both cameras produces java error

EJLib

Member
Licensed User
Longtime User
I am having trouble opening 2 hardware cameras at the same time. I have tried both the CameraEx and Camera libraries. It seems that initializing the second camera breaks the initialization of the first camera. It produces a "java.lang.RunTimeException: Method called after release()" error. Each camera works fine if I comment out the other initialization.

Is there a work around so I can preview both cameras at the same time?

Thanks,
EJ



Code:
Sub Globals
   Dim Panel1 As Panel
   Dim Panel2 As Panel
   Dim frontCam As Camera
   Dim backCam As Camera
End Sub
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("lg")
   Dim numberOfCameras As Int = r.RunStaticMethod("android.hardware.Camera", "getNumberOfCameras", Null, Null)
   ToastMessageShow("# of cameras" & numberOfCameras,True)
End Sub
Private Sub InitializeCameras
   frontCam.Initialize2(Panel1,"frontCamera",1)'' the first camera initialized produces an error when starting its preview
   backCam.Initialize2(Panel2,"backCamera",0) '' the second camera initialized runs fine.
End Sub
Sub backCamera_Ready (Success As Boolean)
   If Success Then
      backCam.StartPreview
   Else
      Msgbox("cannot open back camera","")
   End If
End Sub
Sub frontCamera_Ready (Success As Boolean)
   If Success Then
      frontCam.StartPreview'' This raises an error "java.lang.RunTimeException: Method called after release()"
   Else
      Msgbox("cannot open front camera","")
   End If
End Sub

Sub Activity_Resume
   InitializeCameras
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   frontCam.StopPreview
   backCam.StopPreview
   frontCam.Release
   backCam.Release
End Sub
 
The camera app of the htc one m8 open front and rear cameras at the same time. I used this code and gave me the same error. Apparently that's an mystery manufacturers don't want us to know. o_O
 
Upvote 0
Back
Top