2

I tried to take a video with CameraX. For that I have read the SO posts here and here . But when I copy paste the code and adjust it a little bit, there is an unresolved reference with the setLensFacing() method:

videoCapture = VideoCaptureConfig.Builder().apply {
                setTargetRotation(binding.viewFinder.display.rotation)
                setLensFacing(lensFacing)
            }.build()

I adjust the code little bit since you do not need to pass a config object to a VideoCapture anymore. You can build it directly. At this point, Android Studio is telling me that setLensFacing(lensFacing) is unresolved. I am a little bit confused because on this page , there is a nice documentation and VideoCaptureConfig.Builder() contains setLensFacing()

I hope someone can help.

ebeninki
  • 909
  • 1
  • 12
  • 34

2 Answers2

1

Camera selection is no longer done through the use cases. The code you wrote was possible until -I think- version 1.0.0-alpha08.

The way to select the lens now is by using a CameraSelector when binding a use case (or multiple use cases) to a lifecycle. That way all the use cases use the same lensFacing.

So you can write:

val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()
// Or alternatively if you want a specific lens, like the back facing lens
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA

val videoCapture = VideoCaptureConfig.Builder().build()
processCameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, videoCapture)

Note that currently, the VideoCapture use case is hidden in the camerax API, and is still in an early state of development.

Husayn Hakeem
  • 4,184
  • 1
  • 16
  • 31
-1

In CameraX 1.0.0-beta11, the video capture configuration has moved from VideoCaptureConfig to VideoCapture and the lens is set in the CameraSelector Builder:

val videoCapture = VideoCapture.Builder().apply {
            setVideoFrameRate(30)
            setAudioBitRate(128999)
            setTargetRotation(viewFinder.display.rotation)
            setTargetAspectRatio(AspectRatio.RATIO_16_9)
        }.build()

val cameraSelector = CameraSelector.Builder()
                    .requireLensFacing(CameraSelector.LENS_FACING_BACK)
                    .build()
Oscar Salguero
  • 10,275
  • 5
  • 49
  • 48