Skip to content

Instantly share code, notes, and snippets.

@itome
Created October 24, 2018 17:41
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 itome/f4ec07e924be2b038b4f300acffa1022 to your computer and use it in GitHub Desktop.
Save itome/f4ec07e924be2b038b4f300acffa1022 to your computer and use it in GitHub Desktop.
private var captureSession: CameraCaptureSession? = null
private fun createCameraPreviewSession() {
if (cameraDevice == null) {
return
}
val texture = textureView.surfaceTexture
texture.setDefaultBufferSize(640, 480)
val surface = Surface(texture)
val previewRequestBuilder = cameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
previewRequestBuilder.addTarget(surface)
cameraDevice?.createCaptureSession(listOf(surface), object : CameraCaptureSession.StateCallback() {
override fun onConfigured(session: CameraCaptureSession) {
captureSession = session
captureSession?.setRepeatingRequest(previewRequestBuilder.build(), null, null)
}
override fun onConfigureFailed(session: CameraCaptureSession) {}
}, null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment