previewBack.setSurfaceProvider(viewBack.surfaceProvider)
previewFront.setSurfaceProvider(viewFront.surfaceProvider)
val cameraBack = cameraProvider.bindToLifecycle(this, cameraSelectorBack, previewBack)
val cameraFront = cameraProvider.bindToLifecycle(this, cameraSelectorFront, previewFront)
java.lang.IllegalArgumentException: Multiple LifecycleCameras with use cases are registered to the same LifecycleOwner.
at androidx.camera.lifecycle.LifecycleCameraRepository.bindToLifecycleCamera(LifecycleCameraRepository.java:269)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:423)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:274)
Hii guy’s use - cameraProvider.unbindAll() // Unbind use cases before rebinding,
btnSwitchCamera.setOnClickListener {
Hi lodgkk,
Version 1.3.0-alpha06 is the latest version supporting both front and back cameras simultaneously. https://developer.android.com/jetpack/androidx/releases/camera#1.3.0-alpha06
This is the javadoc for main api: https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-main/camera/camera-lifecycle/src/main/java/androidx/camera/lifecycle/ProcessCameraProvider.java#759
This is the sample app to show a front + back camera previews in Picture-in-Picutre layout or Side-by-Side layout: https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-main/camera/integration-tests/coretestapp/src/main/java/androidx/camera/integration/core/ConcurrentCameraActivity.java#239
Let us know if any other questions.