Created
May 23, 2020 10:48
-
-
Save ananthrajsingh/022cc56639cab1f4712077feb727b4ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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