CameraX Back and front camera can't preview at same time ?
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)
It seems it's not supported. https://issuetracker.google.com/issues/151866349 I've even tried to use different LifecycleOwner for both previews but the only one camera is working, other one is black
I get it
Hii guy's use - cameraProvider.unbindAll() // Unbind use cases before rebinding,
btnSwitchCamera.setOnClickListener {
if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA && cameraProvider.hasCamera(
CameraSelector.DEFAULT_BACK_CAMERA)) {
cameraProvider.unbindAll() // Unbind use cases before rebinding
cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
val preview = Preview.Builder().build().also {
it.setSurfaceProvider(viewFinder.createSurfaceProvider())
}
cameraProvider.bindToLifecycle(this, cameraSelector, preview)
} else if (cameraSelector == CameraSelector.DEFAULT_BACK_CAMERA && cameraProvider.hasCamera(
CameraSelector.DEFAULT_FRONT_CAMERA)) {
cameraProvider.unbindAll() // Unbind use cases before rebinding
cameraSelector = CameraSelector.DEFAULT_FRONT_CAMERA
val preview = Preview.Builder().build().also {
it.setSurfaceProvider(viewFinder.createSurfaceProvider())
}
cameraProvider.bindToLifecycle(this, cameraSelector, preview)
}
}
@taiyabali There is no problem with switching back/front cameras. CameraX doesn't support both simultaneously. Like two previews on the screen.
@agent10 Do u have any solution cuz I have exactly same problem.
@letuss004 I do) I use pure Camera2 api
@agent10 haha i expected an camerax but camera2 fair enough. Did u share source in github? I really want to take a look
@agent10 what do you do with devices that are not supported by hardware both cameras? As far as I understand, not all devices support both camera same time
@agent10 what do you do with devices that are not supported by hardware both cameras? As far as I understand, not all devices support both camera in time As far as I understand, all devices support both camera same time use Camera1 api.
Hi, CameraX will support back and front camera operating at the same time in the next alpha release. Not only for preview but also for image capture and potentially other use cases as well. We will appreciate if you could try it and give feedback to us.
To check the device capability of concurrent cameras in Camera2, you can use FEATURE_CAMERA_CONCURRENT.
https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_CAMERA_CONCURRENT
Hi, CameraX will support back and front camera operating at the same time in the next alpha release. Not only for preview but also for image capture and potentially other use cases as well. We will appreciate if you could try it and give feedback to us.
Has the alpha version that supports using both front and back cameras simultaneously been released? What is the version number?
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.
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.
Concurrent camera is not supported on the device ,How can I solve this?
If it's not supported on this device, then OEM decides to not expose this feature (e.g. due to power consumption or other device capability reason), the behavior will not be guaranteed. You need to find a device with this capability.