问题
I'm trying to implement a custom camera app using CameraX. Seeing as a lot of new devices have multiple back cameras now, I also want to include that. So basically, the user can select which camera to use. I've tried the following using the addCameraFilter option:
val cameraSelector = CameraSelector.Builder()
.requireLensFacing(when (camera.cameraSettings?.lensFacing?.let {
LensFacing.valueOf(it)
}) {
LensFacing.Back -> CameraSelector.LENS_FACING_BACK
else -> CameraSelector.LENS_FACING_FRONT
})
.addCameraFilter { cameraList ->
val cameraChosen = camera.cameraSettings?.camera
cameraChosen?.let {
if (cameraChosen < cameraList.size) {
val setCamera = cameraList[cameraChosen]
cameraList.clear()
cameraList.add(setCamera)
}
}
cameraList
}
.build()
In debug mode, however, cameraList is always equal to 1. Even on devices with multiple back cameras. Does this mean that CameraX automatically chose the "right" camera? How can I manually choose another one (f.ex. some phones have a wide lens camera)?
Thanks!
来源:https://stackoverflow.com/questions/65993527/camerax-multiple-back-cameras