mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Fix recorder states
This commit is contained in:
parent
3d355df522
commit
4be2fc52e2
@ -38,6 +38,7 @@ abstract class IntervalRecorderService<S : IntervalRecorderService.Settings, I>
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
super.start()
|
||||
batchesFolder.initFolders()
|
||||
if (!batchesFolder.checkIfFolderIsAccessible()) {
|
||||
onCustomOutputFolderNotAccessible()
|
||||
@ -48,10 +49,12 @@ abstract class IntervalRecorderService<S : IntervalRecorderService.Settings, I>
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
super.pause()
|
||||
cycleTimer.shutdown()
|
||||
}
|
||||
|
||||
override fun resume() {
|
||||
super.resume()
|
||||
createTimer()
|
||||
}
|
||||
|
||||
|
@ -39,21 +39,27 @@ abstract class RecorderService : LifecycleService() {
|
||||
var recordingTime = 0L
|
||||
private set
|
||||
|
||||
protected abstract fun start()
|
||||
|
||||
protected abstract fun pause()
|
||||
|
||||
// TODO: Move pause / recording here
|
||||
protected abstract fun resume()
|
||||
protected open suspend fun stop() {
|
||||
protected open fun start() {
|
||||
createRecordingTimeTimer()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
protected open fun pause() {
|
||||
isPaused = true
|
||||
|
||||
recordingTimeTimer.shutdown()
|
||||
}
|
||||
|
||||
protected open fun resume() {
|
||||
createRecordingTimeTimer()
|
||||
}
|
||||
|
||||
protected open suspend fun stop() {
|
||||
recordingTimeTimer.shutdown()
|
||||
|
||||
NotificationManagerCompat.from(this)
|
||||
.cancel(NotificationHelper.RECORDER_CHANNEL_NOTIFICATION_ID)
|
||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||
stopSelf()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
protected abstract fun startForegroundService()
|
||||
@ -141,20 +147,9 @@ abstract class RecorderService : LifecycleService() {
|
||||
isPaused = false
|
||||
}
|
||||
// `start` is handled by `startRecording`
|
||||
|
||||
createRecordingTimeTimer()
|
||||
}
|
||||
|
||||
RecorderState.PAUSED -> {
|
||||
isPaused = true
|
||||
|
||||
recordingTimeTimer.shutdown()
|
||||
pause()
|
||||
}
|
||||
|
||||
RecorderState.STOPPED -> {
|
||||
recordingTimeTimer.shutdown()
|
||||
}
|
||||
RecorderState.PAUSED -> pause()
|
||||
|
||||
else -> {}
|
||||
}
|
||||
|
@ -33,8 +33,6 @@ import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
const val CAMERA_CLOSE_TIMEOUT = 20000L
|
||||
|
||||
class VideoRecorderService :
|
||||
IntervalRecorderService<VideoRecorderService.Settings, RecordingInformation>() {
|
||||
override var batchesFolder: BatchesFolder = VideoBatchesFolder.viaInternalFolder(this)
|
||||
@ -238,7 +236,10 @@ class VideoRecorderService :
|
||||
type = RecordingInformation.Type.VIDEO,
|
||||
)
|
||||
|
||||
// TODO: Save camera selector as it doesn't make sense to change the camera midway
|
||||
companion object {
|
||||
const val CAMERA_CLOSE_TIMEOUT = 20000L
|
||||
}
|
||||
|
||||
data class Settings(
|
||||
override val maxDuration: Long,
|
||||
override val intervalDuration: Long,
|
||||
|
@ -77,20 +77,22 @@ fun VideoRecordingStatus(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.padding(bottom = 32.dp),
|
||||
) {
|
||||
val cameraControl = videoRecorder.recorderService!!.cameraControl!!
|
||||
if (cameraControl.hasTorchAvailable()) {
|
||||
val isTorchEnabled = cameraControl.isTorchEnabled()
|
||||
if (!videoRecorder.isStartingRecording) {
|
||||
val cameraControl = videoRecorder.recorderService!!.cameraControl!!
|
||||
if (cameraControl.hasTorchAvailable()) {
|
||||
val isTorchEnabled = cameraControl.isTorchEnabled()
|
||||
|
||||
TorchStatus(
|
||||
enabled = isTorchEnabled,
|
||||
onChange = {
|
||||
if (isTorchEnabled) {
|
||||
cameraControl.disableTorch()
|
||||
} else {
|
||||
cameraControl.enableTorch()
|
||||
}
|
||||
},
|
||||
)
|
||||
TorchStatus(
|
||||
enabled = isTorchEnabled,
|
||||
onChange = {
|
||||
if (isTorchEnabled) {
|
||||
cameraControl.disableTorch()
|
||||
} else {
|
||||
cameraControl.enableTorch()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
@ -77,6 +77,8 @@ abstract class BaseRecorderModel<S : IntervalRecorderService.Settings, I, T : In
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
||||
// `onServiceDisconnected` is called when the connection is unexpectedly lost,
|
||||
// so we need to make sure to manually call `reset` to clean up in other places
|
||||
reset()
|
||||
}
|
||||
}
|
||||
@ -135,8 +137,13 @@ abstract class BaseRecorderModel<S : IntervalRecorderService.Settings, I, T : In
|
||||
recorderService!!.stopRecording()
|
||||
|
||||
val intent = Intent(context, intentClass)
|
||||
context.unbindService(connection)
|
||||
context.stopService(intent)
|
||||
runCatching {
|
||||
context.unbindService(connection)
|
||||
}
|
||||
runCatching {
|
||||
context.stopService(intent)
|
||||
}
|
||||
reset()
|
||||
}
|
||||
|
||||
fun pauseRecording() {
|
||||
|
@ -25,7 +25,10 @@ class VideoRecorderModel :
|
||||
var cameraID by mutableIntStateOf(CameraInfo.Lens.BACK.androidValue)
|
||||
|
||||
override val isInRecording: Boolean
|
||||
get() = super.isInRecording && recorderService!!.cameraControl != null
|
||||
get() = super.isInRecording
|
||||
|
||||
val isStartingRecording: Boolean
|
||||
get() = recorderService?.cameraControl == null
|
||||
|
||||
val cameraSelector: CameraSelector
|
||||
get() = CameraSelector.Builder().requireLensFacing(cameraID).build()
|
||||
|
Loading…
x
Reference in New Issue
Block a user