如何聆听cameraX镜头的朝向变化 [英] How to listen to the cameraX lens facing changes

查看:144
本文介绍了如何聆听cameraX镜头的朝向变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

camerax是否提供api来面对镜头变化回调?切换面向镜头的相机后,我想在完成更换并准备使用相机时得到通知.

Does camerax provide api for lens facing changes callback? After switching the lens facing camera I want to be notified when it has finished changing and the camera is ready to use.

当前,我正在使用camerax的这种依赖关系

Currently I'm using this dependencies of camerax

implementation "androidx.camera:camera-lifecycle:1.0.0-beta01"
implementation "androidx.camera:camera-view:1.0.0-alpha08"
implementation "androidx.camera:camera-extensions:1.0.0-alpha08"

推荐答案

像这样的声音在相机开始发射帧时需要一个信号.例如,您可以使用 Camera2Interop 并在预览用例上设置 CaptureCallback .在使用 CameraSelector 绑定所需的镜头用预览用例后,您可以在调用 onCaptureCompleted()时侦听,这应该会向您发出一个信号,表明相机已经开始.

Sounds like you need a signal for when the camera starts emitting frames. You can use Camera2Interop and set a CaptureCallback on the preview use case for example. After binding the preview use case using a CameraSelector for the lens facing you want, you can listen for when onCaptureCompleted() is invoked, this should give you a signal that the camera has started.

val builder = Preview.Builder()
Camera2Interop.Extender(builder).setSessionCaptureCallback(object: CameraCaptureSession.CaptureCallback() {
   override fun onCaptureCompleted(session: CameraCaptureSession, request: CaptureRequest, result: TotalCaptureResult) {
      // Camera will start emitting frames
   }
})
val preview = builder.build()

这篇关于如何聆听cameraX镜头的朝向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆