Search code examples
androidcameraandroid-camera2android-cameraxjitsi

Android : CameraX don't open after JitsiMeetView


I am using CameraX on my app and I am also using JistiMeetView. When I start the app, I can open the activity that contains CameraX and the camera can start. When I open the activity with JitsiMeetView, I correctly join the room, but when I exit the jitsi activity and go back to the camera activity, the camera cannot start. So i think jitsi is keeping the camera resources but I don't know how to shut down all the resources.

Here is the code when I destroy the jitsi activity:

@Override
protected void onDestroy() {
    jitsiMeetView.leave();
    jitsiMeetView.dispose();
    super.onDestroy();
}

The camera activity code to start the camera:

 private fun startCamera(lensFacing: Int) {

        val cameraProviderFuture = ProcessCameraProvider.getInstance(this)

        cameraProviderFuture.addListener(Runnable {
            // Used to bind the lifecycle of cameras to the lifecycle owner
            val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()

            preview = Preview.Builder().build()
                    .also {
                it.setSurfaceProvider(findViewById<PreviewView>(R.id.phototake_camera_view).surfaceProvider)
            }

            imageCapture = ImageCapture.Builder().setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
                    .build()

            imageAnalyzer = ImageAnalysis.Builder()
                    .build()

            // Select back camera
            val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()

            try {
                // Unbind use cases before rebinding
                cameraProvider.unbindAll()

                // Bind use cases to camera
                cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture, imageAnalyzer)

            } catch (exc: Exception) {
                Log.e(TAG, "Use case binding failed", exc)
            }

        }, ContextCompat.getMainExecutor(this))
    }

and also in the log i have this when i stop jitsi view and it's still there:

W/unknown:ReactNative: Attempt to set local data for view with unknown tag: 247
I/org.webrtc.Logging: CameraStatistics: Camera fps: 21.
D/NetworkManagementSocketTagger: tagSocket(71) with statsTag=0xffffffff, statsUid=-1
I/org.webrtc.Logging: CameraStatistics: Camera fps: 20.
I/org.webrtc.Logging: CameraStatistics: Camera fps: 20.
I/org.webrtc.Logging: CameraStatistics: Camera fps: 20.
D/NetworkManagementSocketTagger: tagSocket(81) with statsTag=0xffffffff, statsUid=-1
I/org.webrtc.Logging: CameraStatistics: Camera fps: 20.
I/org.webrtc.Logging: CameraStatistics: Camera fps: 20.
D/NetworkManagementSocketTagger: tagSocket(81) with statsTag=0xffffffff, statsUid=-1
I/org.webrtc.Logging: CameraStatistics: Camera fps: 21.

I'm using Kotlin just for CameraX activity


Solution

  • I found the solution.

    After following the official website : https://jitsi.github.io/handbook/docs/dev-guide/dev-guide-android-sdk

    I've forgot all JitsiMeetActivityDelegate.onHost...(this); on the Activity life cycle of Jisti Activity. I've just added them and it works fine now.