mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +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() {
|
override fun start() {
|
||||||
|
super.start()
|
||||||
batchesFolder.initFolders()
|
batchesFolder.initFolders()
|
||||||
if (!batchesFolder.checkIfFolderIsAccessible()) {
|
if (!batchesFolder.checkIfFolderIsAccessible()) {
|
||||||
onCustomOutputFolderNotAccessible()
|
onCustomOutputFolderNotAccessible()
|
||||||
@ -48,10 +49,12 @@ abstract class IntervalRecorderService<S : IntervalRecorderService.Settings, I>
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun pause() {
|
override fun pause() {
|
||||||
|
super.pause()
|
||||||
cycleTimer.shutdown()
|
cycleTimer.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resume() {
|
override fun resume() {
|
||||||
|
super.resume()
|
||||||
createTimer()
|
createTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,21 +39,27 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
var recordingTime = 0L
|
var recordingTime = 0L
|
||||||
private set
|
private set
|
||||||
|
|
||||||
protected abstract fun start()
|
protected open fun start() {
|
||||||
|
createRecordingTimeTimer()
|
||||||
protected abstract fun pause()
|
|
||||||
|
|
||||||
// TODO: Move pause / recording here
|
|
||||||
protected abstract fun resume()
|
|
||||||
protected open suspend fun stop() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
NotificationManagerCompat.from(this)
|
||||||
.cancel(NotificationHelper.RECORDER_CHANNEL_NOTIFICATION_ID)
|
.cancel(NotificationHelper.RECORDER_CHANNEL_NOTIFICATION_ID)
|
||||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
super.onDestroy()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun startForegroundService()
|
protected abstract fun startForegroundService()
|
||||||
@ -141,20 +147,9 @@ abstract class RecorderService : LifecycleService() {
|
|||||||
isPaused = false
|
isPaused = false
|
||||||
}
|
}
|
||||||
// `start` is handled by `startRecording`
|
// `start` is handled by `startRecording`
|
||||||
|
|
||||||
createRecordingTimeTimer()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RecorderState.PAUSED -> {
|
RecorderState.PAUSED -> pause()
|
||||||
isPaused = true
|
|
||||||
|
|
||||||
recordingTimeTimer.shutdown()
|
|
||||||
pause()
|
|
||||||
}
|
|
||||||
|
|
||||||
RecorderState.STOPPED -> {
|
|
||||||
recordingTimeTimer.shutdown()
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,6 @@ import kotlinx.coroutines.withContext
|
|||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
const val CAMERA_CLOSE_TIMEOUT = 20000L
|
|
||||||
|
|
||||||
class VideoRecorderService :
|
class VideoRecorderService :
|
||||||
IntervalRecorderService<VideoRecorderService.Settings, RecordingInformation>() {
|
IntervalRecorderService<VideoRecorderService.Settings, RecordingInformation>() {
|
||||||
override var batchesFolder: BatchesFolder = VideoBatchesFolder.viaInternalFolder(this)
|
override var batchesFolder: BatchesFolder = VideoBatchesFolder.viaInternalFolder(this)
|
||||||
@ -238,7 +236,10 @@ class VideoRecorderService :
|
|||||||
type = RecordingInformation.Type.VIDEO,
|
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(
|
data class Settings(
|
||||||
override val maxDuration: Long,
|
override val maxDuration: Long,
|
||||||
override val intervalDuration: Long,
|
override val intervalDuration: Long,
|
||||||
|
@ -77,6 +77,7 @@ fun VideoRecordingStatus(
|
|||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier.padding(bottom = 32.dp),
|
modifier = Modifier.padding(bottom = 32.dp),
|
||||||
) {
|
) {
|
||||||
|
if (!videoRecorder.isStartingRecording) {
|
||||||
val cameraControl = videoRecorder.recorderService!!.cameraControl!!
|
val cameraControl = videoRecorder.recorderService!!.cameraControl!!
|
||||||
if (cameraControl.hasTorchAvailable()) {
|
if (cameraControl.hasTorchAvailable()) {
|
||||||
val isTorchEnabled = cameraControl.isTorchEnabled()
|
val isTorchEnabled = cameraControl.isTorchEnabled()
|
||||||
@ -92,6 +93,7 @@ fun VideoRecordingStatus(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
|
@ -77,6 +77,8 @@ abstract class BaseRecorderModel<S : IntervalRecorderService.Settings, I, T : In
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceDisconnected(arg0: ComponentName) {
|
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()
|
reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,9 +137,14 @@ abstract class BaseRecorderModel<S : IntervalRecorderService.Settings, I, T : In
|
|||||||
recorderService!!.stopRecording()
|
recorderService!!.stopRecording()
|
||||||
|
|
||||||
val intent = Intent(context, intentClass)
|
val intent = Intent(context, intentClass)
|
||||||
|
runCatching {
|
||||||
context.unbindService(connection)
|
context.unbindService(connection)
|
||||||
|
}
|
||||||
|
runCatching {
|
||||||
context.stopService(intent)
|
context.stopService(intent)
|
||||||
}
|
}
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
fun pauseRecording() {
|
fun pauseRecording() {
|
||||||
recorderService!!.pauseRecording()
|
recorderService!!.pauseRecording()
|
||||||
|
@ -25,7 +25,10 @@ class VideoRecorderModel :
|
|||||||
var cameraID by mutableIntStateOf(CameraInfo.Lens.BACK.androidValue)
|
var cameraID by mutableIntStateOf(CameraInfo.Lens.BACK.androidValue)
|
||||||
|
|
||||||
override val isInRecording: Boolean
|
override val isInRecording: Boolean
|
||||||
get() = super.isInRecording && recorderService!!.cameraControl != null
|
get() = super.isInRecording
|
||||||
|
|
||||||
|
val isStartingRecording: Boolean
|
||||||
|
get() = recorderService?.cameraControl == null
|
||||||
|
|
||||||
val cameraSelector: CameraSelector
|
val cameraSelector: CameraSelector
|
||||||
get() = CameraSelector.Builder().requireLensFacing(cameraID).build()
|
get() = CameraSelector.Builder().requireLensFacing(cameraID).build()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user