mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +02:00
feat: Add timeout to camera closing
This commit is contained in:
parent
569794d437
commit
c38be920ec
@ -24,7 +24,10 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlinx.coroutines.withTimeout
|
||||||
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
|
|
||||||
|
const val CAMERA_CLOSE_TIMEOUT = 20000L
|
||||||
|
|
||||||
class VideoRecorderService :
|
class VideoRecorderService :
|
||||||
IntervalRecorderService<VideoRecorderService.Settings, RecordingInformation>() {
|
IntervalRecorderService<VideoRecorderService.Settings, RecordingInformation>() {
|
||||||
@ -117,8 +120,12 @@ class VideoRecorderService :
|
|||||||
super.stop()
|
super.stop()
|
||||||
|
|
||||||
stopActiveRecording()
|
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()
|
closeCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +148,6 @@ class VideoRecorderService :
|
|||||||
val newRecording = prepareVideoRecording()
|
val newRecording = prepareVideoRecording()
|
||||||
|
|
||||||
activeRecording = newRecording.start(ContextCompat.getMainExecutor(this)) { event ->
|
activeRecording = newRecording.start(ContextCompat.getMainExecutor(this)) { event ->
|
||||||
// TODO: Add timeout to completer
|
|
||||||
if (event is VideoRecordEvent.Finalize) {
|
if (event is VideoRecordEvent.Finalize) {
|
||||||
_cameraClosedListener.complete(Unit)
|
_cameraClosedListener.complete(Unit)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user