Skip to content

Instantly share code, notes, and snippets.

@ananthrajsingh
Created May 23, 2020 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ananthrajsingh/022cc56639cab1f4712077feb727b4ee to your computer and use it in GitHub Desktop.
Save ananthrajsingh/022cc56639cab1f4712077feb727b4ee to your computer and use it in GitHub Desktop.
private fun createCameraPreviewSessionFront() {
try {
val texture = textureViewFront.surfaceTexture
texture.setDefaultBufferSize(previewSizeFront.width, previewSizeFront.height)
val surface = Surface(texture)
previewRequestBuilderFront = cameraDeviceFront!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
previewRequestBuilderFront.addTarget(surface)
// Here, we create a CameraCaptureSession for camera preview.
cameraDeviceFront?.createCaptureSession(Arrays.asList(surface, imageReaderFront?.surface), object : CameraCaptureSession.StateCallback() {
override fun onConfigured(cameraCaptureSession: CameraCaptureSession) {
// The camera is already closed
if (cameraDeviceFront == null) return
// When the session is ready, we start displaying the preview.
captureSessionFront = cameraCaptureSession
try {
// Auto focus should be continuous for camera preview.
previewRequestBuilderFront.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
// Finally, we start displaying the camera preview.
previewRequestFront = previewRequestBuilderFront.build()
captureSessionFront?.setRepeatingRequest(previewRequestFront, captureCallback, backgroundHandler)
} catch (e: CameraAccessException) {
Log.e(TAG, e.toString())
}
}
override fun onConfigureFailed(session: CameraCaptureSession) {
}
}, null)
} catch (e: CameraAccessException) {
Log.e(TAG, e.toString())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment