Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. val isAvailable = textureView?.isAvailable ?: false
  2. if (cameraDevice == null || !isAvailable) return@launch
  3.  
  4. try {
  5. closePreviewSession()
  6. setUpMediaRecorder()
  7. val texture = textureView?.surfaceTexture.apply {
  8. this!!.setDefaultBufferSize(previewSize.width,
  9. previewSize.height)
  10. }
  11.  
  12. // Set up Surface for camera preview and MediaRecorder
  13. val previewSurface = Surface(texture)
  14. val recorderSurface = mediaRecorder!!.surface
  15. val surfaces = ArrayList<Surface>().apply {
  16. add(previewSurface)
  17. add(recorderSurface)
  18. }
  19. previewRequestBuilder =
  20. cameraDevice!!.createCaptureRequest(TEMPLATE_RECORD).apply {
  21. addTarget(previewSurface)
  22. addTarget(recorderSurface)
  23. }
  24.  
  25. // Start a capture session
  26. // Once the session starts, we can update the UI and start recording
  27. cameraDevice?.createCaptureSession(
  28. surfaces,
  29. object : CameraCaptureSession.StateCallback() {
  30. override fun onConfigured(cameraCaptureSession:
  31. CameraCaptureSession) {
  32. captureSession = cameraCaptureSession
  33. updatePreview()
  34. isRecordingVideo = true
  35. mediaRecorder?.start()
  36.  
  37. }
  38.  
  39. override fun
  40. onConfigureFailed(cameraCaptureSession: CameraCaptureSession) {
  41. if (activity != null) showToast("Failed")
  42. }
  43. }, backgroundHandler
  44. )
  45. } catch (e: CameraAccessException) {
  46. Log.e(TAG, e.toString())
  47. } catch (e: IOException) {
  48. Log.e(TAG, e.toString())
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement