CameraX Multiple Back Cameras

人走茶凉 提交于 2021-02-11 12:38:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!