how can i change the camera lens orientation in camera x?

Initialize a variable in the beginning:

private var lensFacing = CameraSelector.LENS_FACING_BACK

Change your camera toggle method to this:

private fun toggleFrontBackCamera() {
    lensFacing = if (CameraSelector.LENS_FACING_FRONT == lensFacing)
        CameraSelector.LENS_FACING_BACK
    else 
        CameraSelector.LENS_FACING_FRONT
    startCamera()
}

And finally create an instance of CameraSelector in your startCamera() and use this in cameraProvider.bindToLifecycle():

val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top