I have a Android camera2 API preview running ok in Kotlin using suspendCoroutine for all the surface setup and callbacks. But when I try to take a picture 5 seconds after the app starts (TEMPLATE_STILL_CAPTURE, YUV_420_888, smallest res) for some reason it all goes completely black for a moment (even in the preview window) and I get a YUV image full of 0-lum pixels.
private suspend fun captureStill(): Image = suspendCoroutine { cont ->
val captureRequestStill = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE)
captureRequestStill.addTarget(imageReaderYUV.surface)
imageReaderYUV.setOnImageAvailableListener({ cont.resume(imageReaderYUV.acquireLatestImage()) }, backgroundHandler)
cameraCaptureSession.capture(captureRequestStill.build(), null, backgroundHandler)
}
Am I missing something? Did I mangle some aspect of the setup earlier? Is setOnImageAvailableListener not ok for capturing a YUV image?
See the full setup dance in one suspend-enabled function