mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Set state after action to avoid coroutine going out of scope
This commit is contained in:
parent
d79aabab50
commit
df78952cfb
@ -32,6 +32,9 @@ abstract class RecorderService : LifecycleService() {
|
||||
var state = RecorderState.IDLE
|
||||
private set
|
||||
|
||||
protected var _newState = RecorderState.IDLE
|
||||
private set
|
||||
|
||||
var onStateChange: ((RecorderState) -> Unit)? = null
|
||||
var onError: () -> Unit = {}
|
||||
|
||||
@ -168,8 +171,9 @@ abstract class RecorderService : LifecycleService() {
|
||||
}
|
||||
|
||||
suspend fun stopRecording() {
|
||||
changeState(RecorderState.IDLE)
|
||||
_newState = RecorderState.IDLE
|
||||
stop()
|
||||
changeState(RecorderState.IDLE)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -105,11 +105,11 @@ class VideoRecorderService :
|
||||
super.startNewCycle()
|
||||
|
||||
fun action() {
|
||||
activeRecording?.stop()
|
||||
stopActiveRecording()
|
||||
val newRecording = prepareVideoRecording()
|
||||
|
||||
activeRecording = newRecording.start(ContextCompat.getMainExecutor(this)) { event ->
|
||||
if (event is VideoRecordEvent.Finalize && this@VideoRecorderService.state == RecorderState.IDLE) {
|
||||
if (event is VideoRecordEvent.Finalize && this@VideoRecorderService._newState == RecorderState.IDLE) {
|
||||
_videoFinalizerListener.complete(Unit)
|
||||
}
|
||||
}
|
||||
@ -197,7 +197,9 @@ class VideoRecorderService :
|
||||
// `resume` override not needed as `startNewCycle` is called by `IntervalRecorderService`
|
||||
|
||||
private fun stopActiveRecording() {
|
||||
activeRecording?.stop()
|
||||
runCatching {
|
||||
activeRecording?.stop()
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
|
@ -136,7 +136,7 @@ abstract class BaseRecorderModel<S : IntervalRecorderService.Settings, I, T : In
|
||||
|
||||
val intent = Intent(context, intentClass)
|
||||
|
||||
context.unbindService(connection)
|
||||
unbindFromService(context)
|
||||
context.stopService(intent)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user