问题
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