I have a textureView initialized by:
@SuppressLint("MissingPermission")
fun open_camera() {
cameraManager.openCamera(camIdWithFlash, object: CameraDevice.StateCallback() {
override fun onOpened(camera: CameraDevice) {
cameraDevice = camera
capReq = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
var surface = Surface(textureView.surfaceTexture)
capReq.addTarget(surface)
// captureRequest = capReq.build()
cameraDevice.createCaptureSession(listOf(surface), object:
CameraCaptureSession.StateCallback() {
override fun onConfigured(session: CameraCaptureSession) {
cameraCaptureSession = session
// Setting up capture request modifications
// capReq.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.FLASH_MODE_OFF)
cameraCaptureSession.setRepeatingRequest(capReq.build(), null, null)
}
override fun onConfigureFailed(session: CameraCaptureSession) {
TODO("Not yet implemented")
}
}, handler)
}
override fun onDisconnected(camera: CameraDevice) {
}
override fun onError(camera: CameraDevice, error: Int) {
}
}, handler)
}
However I am really lost in how to create a mediaRecorder to take video and connect it with the texture view. I've tried watching tutorials but they are often really old and do not work. Any help would be appreciated. Thank you!
Declare specific variables in
activityandfragment.Initialize
MediaRecorder.Use a similar guide to record video and connect to
TextureViewusingCamera2 Kotlin ApiCameraManagerandTextureView.CameraManagerand setTextureView.MediaRecorderand init parameters usinginitMediaRecorder.SurfaceforMediaRecorderand add it as target forCaptureRequest.startRecordingandstopRecordingfunctions.The function has to set up
MediaRecorder.getRotationCompensationis ahelper function, and you should define it like this:Create Recording function that has to start the
MediaRecorderand should begin recording.Create Stop Recording function that has to stop the
MediaRecorderand reset the recording.Create
open_camerafun to includeMediaRecorderCallback.Create a function to get file path:
Call
startRecording funand callstopRecording fun: