From c38be920ec8b565870cbbcac1ee7a6cbd85dcda3 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Fri, 1 Dec 2023 00:13:51 +0100 Subject: [PATCH] feat: Add timeout to camera closing --- .../myzel394/alibi/services/VideoRecorderService.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/myzel394/alibi/services/VideoRecorderService.kt b/app/src/main/java/app/myzel394/alibi/services/VideoRecorderService.kt index 2bed4c8..11cc34d 100644 --- a/app/src/main/java/app/myzel394/alibi/services/VideoRecorderService.kt +++ b/app/src/main/java/app/myzel394/alibi/services/VideoRecorderService.kt @@ -24,7 +24,10 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.coroutines.withTimeout +import kotlinx.coroutines.withTimeoutOrNull +const val CAMERA_CLOSE_TIMEOUT = 20000L class VideoRecorderService : IntervalRecorderService() { @@ -117,8 +120,12 @@ class VideoRecorderService : super.stop() stopActiveRecording() - _cameraClosedListener.await() - // Camera can only be closed after the recording has been finalized + + withTimeoutOrNull(CAMERA_CLOSE_TIMEOUT) { + // Camera can only be closed after the recording has been finalized + _cameraClosedListener.await() + } + closeCamera() } @@ -141,7 +148,6 @@ class VideoRecorderService : val newRecording = prepareVideoRecording() activeRecording = newRecording.start(ContextCompat.getMainExecutor(this)) { event -> - // TODO: Add timeout to completer if (event is VideoRecordEvent.Finalize) { _cameraClosedListener.complete(Unit) }