I am developing an app which is capturing device front camera and added auto focus on camera to get the selfie clearly but camerax api is not showing any rectangle where focus is being made. I am using below code to achieve auto-focus on camera:
activity?.let {
previewView.previewStreamState.observe(it) { value ->
if (value.equals(PreviewView.StreamState.STREAMING)) {
setUpCameraAutoFocus()
}
}
}
private fun setUpCameraAutoFocus() {
val autoFocusPoint = SurfaceOrientedMeteringPointFactory(1f, 1f)
.createPoint(.5f, .5f)
try {
val autoFocusAction = FocusMeteringAction.Builder(
autoFocusPoint,
FocusMeteringAction.FLAG_AF
).apply {
//start auto-focusing after 2 seconds
setAutoCancelDuration(2, TimeUnit.SECONDS)
}.build()
camera!!.cameraControl.startFocusAndMetering(autoFocusAction)
} catch (e: CameraInfoUnavailableException) {
Log.d("ERROR", "cannot access camera", e)
}
}
I haven't worked on camera api's mush so need some help. Anything else need to done to enable the auto-focus?