How to listen to the cameraX lens facing changes

孤街浪徒 提交于 2020-12-12 13:23:40

问题


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.

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"

回答1:


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()


来源:https://stackoverflow.com/questions/61561964/how-to-listen-to-the-camerax-lens-facing-changes

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