android / camera-samples

Multiple samples showing the best practices in camera APIs on Android.
Apache License 2.0
4.95k stars 2.32k forks source link

How to use camerax 1.3.0-alpha04 to open two cameras #564

Open lodgkk opened 9 months ago

lodgkk commented 9 months ago

How to use camerax 1.3.0-alpha04 to open two cameras

kailianc commented 9 months ago

Do you want to open front + rear cameras at the same time? https://developer.android.com/reference/androidx/camera/lifecycle/ProcessCameraProvider#getAvailableConcurrentCameraInfos%28%29

Before that, you need to check this flag to see if device is supporting this feature: https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_CAMERA_CONCURRENT

lodgkk commented 9 months ago

I get an error Concurrent camera is not supported on the device , but I can open two cameras at the same time when using camera1. How can I solve this?

lodgkk commented 9 months ago

Do you want to open front + rear cameras at the same time? https://developer.android.com/reference/androidx/camera/lifecycle/ProcessCameraProvider#getAvailableConcurrentCameraInfos%28%29

Before that, you need to check this flag to see if device is supporting this feature: https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_CAMERA_CONCURRENT

I get an error Concurrent camera is not supported on the device , but I can open two cameras at the same time when using camera1. How can I solve this?

kailianc commented 9 months ago

Are you opening the front and rear cameras? It's possible that some OEMs don't advertise this feature but you are still be able to try, but the stability is not guaranteed. From framework's perspective, we treat this flag as the source of truth.

lodgkk commented 9 months ago

Are you opening the front and rear cameras? It's possible that some OEMs don't advertise this feature but you are still be able to try, but the stability is not guaranteed. From framework's perspective, we treat this flag as the source of truth.

My project is an access control project. When using camera1, it is possible to simultaneously turn on the rgb camera and infrared camera. When using camerax, I have tried turning on the rgb camera and infrared camera separately, and both worked without issue.

kailianc commented 9 months ago

CameraX Concurrent camera API only refers to opening front + rear camera on the device at the same time. Opening rgb camera and infrared camera is different. If you want to open front + rear camera, you could use concurrent camera API.

iamwilliamli commented 9 months ago

@kailianc Is it possible to turn on two rear camera for video recording at same time?