Created
July 31, 2022 20:14
-
-
Save mayowa-egbewunmi/6103f7e3816c34811a586107cf95106b 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
class VideoCaptureManager private constructor(private val builder: Builder) : | |
LifecycleEventObserver { | |
... | |
@SuppressLint("MissingPermission") | |
fun startRecording(filePath: String) { | |
val outputOptions = FileOutputOptions.Builder(File(filePath)).build() | |
activeRecording = videoCapture.output | |
.prepareRecording(getContext(), outputOptions) | |
.apply { withAudioEnabled() } | |
.start(ContextCompat.getMainExecutor(getContext()), videoRecordingListener) | |
} | |
fun pauseRecording() { | |
activeRecording.pause() | |
listener?.recordingPaused() | |
} | |
fun resumeRecording() { | |
activeRecording.resume() | |
} | |
fun stopRecording() { | |
activeRecording.stop() | |
} | |
private val videoRecordingListener = Consumer<VideoRecordEvent> { event -> | |
when (event) { | |
is VideoRecordEvent.Finalize -> if (event.hasError()) { | |
listener?.onError(event.cause) | |
} else { | |
listener?.recordingCompleted(event.outputResults.outputUri) | |
} | |
is VideoRecordEvent.Pause -> listener?.recordingPaused() | |
is VideoRecordEvent.Status -> { | |
listener?.onProgress(event.recordingStats.recordedDurationNanos) | |
} | |
} | |
} | |
interface Listener { | |
fun onInitialised(cameraLensInfo: HashMap<Int, CameraInfo>) | |
fun onProgress(progress: Int) | |
fun recordingPaused() | |
fun recordingCompleted(outputUri: Uri) | |
fun onError(throwable: Throwable?) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment