Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val isAvailable = textureView?.isAvailable ?: false
- if (cameraDevice == null || !isAvailable) return@launch
- try {
- closePreviewSession()
- setUpMediaRecorder()
- val texture = textureView?.surfaceTexture.apply {
- this!!.setDefaultBufferSize(previewSize.width,
- previewSize.height)
- }
- // Set up Surface for camera preview and MediaRecorder
- val previewSurface = Surface(texture)
- val recorderSurface = mediaRecorder!!.surface
- val surfaces = ArrayList<Surface>().apply {
- add(previewSurface)
- add(recorderSurface)
- }
- previewRequestBuilder =
- cameraDevice!!.createCaptureRequest(TEMPLATE_RECORD).apply {
- addTarget(previewSurface)
- addTarget(recorderSurface)
- }
- // Start a capture session
- // Once the session starts, we can update the UI and start recording
- cameraDevice?.createCaptureSession(
- surfaces,
- object : CameraCaptureSession.StateCallback() {
- override fun onConfigured(cameraCaptureSession:
- CameraCaptureSession) {
- captureSession = cameraCaptureSession
- updatePreview()
- isRecordingVideo = true
- mediaRecorder?.start()
- }
- override fun
- onConfigureFailed(cameraCaptureSession: CameraCaptureSession) {
- if (activity != null) showToast("Failed")
- }
- }, backgroundHandler
- )
- } catch (e: CameraAccessException) {
- Log.e(TAG, e.toString())
- } catch (e: IOException) {
- Log.e(TAG, e.toString())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement