mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Only start recording if recordingstate is idle
This commit is contained in:
parent
b1c77fe16a
commit
4f9f65d0b1
@ -29,7 +29,7 @@ abstract class RecorderService : LifecycleService() {
|
||||
private lateinit var recordingTimeTimer: ScheduledExecutorService
|
||||
private var notificationDetails: RecorderNotificationHelper.NotificationDetails? = null
|
||||
|
||||
var state = RecorderState.STOPPED
|
||||
var state = RecorderState.IDLE
|
||||
private set
|
||||
|
||||
var onStateChange: ((RecorderState) -> Unit)? = null
|
||||
|
@ -51,9 +51,11 @@ fun Navigation(
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
audioRecorder.bindToService(context)
|
||||
videoRecorder.bindToService(context)
|
||||
|
||||
onDispose {
|
||||
audioRecorder.unbindFromService(context)
|
||||
videoRecorder.unbindFromService(context)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import app.myzel394.alibi.db.AppSettings
|
||||
import app.myzel394.alibi.db.RecordingInformation
|
||||
import app.myzel394.alibi.enums.RecorderState
|
||||
import app.myzel394.alibi.helpers.AudioBatchesFolder
|
||||
import app.myzel394.alibi.services.AudioRecorderService
|
||||
import app.myzel394.alibi.ui.utils.MicrophoneInfo
|
||||
@ -47,8 +48,13 @@ class AudioRecorderModel :
|
||||
onAmplitudeChange()
|
||||
}
|
||||
|
||||
service.clearAllRecordings()
|
||||
service.startRecording()
|
||||
// `onServiceConnected` may be called when reconnecting to the service,
|
||||
// so we only want to actually start the recording if the service is idle and thus
|
||||
// not already recording
|
||||
if (service.state == RecorderState.IDLE) {
|
||||
service.clearAllRecordings()
|
||||
service.startRecording()
|
||||
}
|
||||
|
||||
recorderState = service.state
|
||||
recordingTime = service.recordingTime
|
||||
|
@ -105,6 +105,17 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
||||
|
||||
protected open fun handleIntent(intent: Intent) = intent
|
||||
|
||||
private fun stopOldServices(context: Context) {
|
||||
runCatching {
|
||||
context.unbindService(connection)
|
||||
}
|
||||
|
||||
val intent = Intent(context, intentClass)
|
||||
runCatching {
|
||||
context.stopService(intent)
|
||||
}
|
||||
}
|
||||
|
||||
// If override, call `super` AFTER setting the settings
|
||||
open fun startRecording(
|
||||
context: Context,
|
||||
@ -113,10 +124,7 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
||||
this.settings = settings
|
||||
|
||||
// Clean up
|
||||
runCatching {
|
||||
recorderService?.clearAllRecordings()
|
||||
context.unbindService(connection)
|
||||
}
|
||||
stopOldServices(context)
|
||||
|
||||
notificationDetails = settings.notificationSettings.let {
|
||||
if (it == null)
|
||||
@ -147,10 +155,6 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
||||
|
||||
suspend fun stopRecording(context: Context) {
|
||||
recorderService!!.stopRecording()
|
||||
|
||||
runCatching {
|
||||
context.unbindService(connection)
|
||||
}
|
||||
}
|
||||
|
||||
fun pauseRecording() {
|
||||
@ -164,11 +168,8 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
||||
fun destroyService(context: Context) {
|
||||
recorderService!!.destroy()
|
||||
reset()
|
||||
val intent = Intent(context, intentClass)
|
||||
|
||||
runCatching {
|
||||
context.stopService(intent)
|
||||
}
|
||||
stopOldServices(context)
|
||||
}
|
||||
|
||||
// Bind functions used to manually bind to the service if the app
|
||||
|
@ -39,8 +39,13 @@ class VideoRecorderModel :
|
||||
}
|
||||
|
||||
override fun onServiceConnected(service: VideoRecorderService) {
|
||||
service.clearAllRecordings()
|
||||
service.startRecording()
|
||||
// `onServiceConnected` may be called when reconnecting to the service,
|
||||
// so we only want to actually start the recording if the service is idle and thus
|
||||
// not already recording
|
||||
if (service.state == RecorderState.IDLE) {
|
||||
service.clearAllRecordings()
|
||||
service.startRecording()
|
||||
}
|
||||
|
||||
recorderState = service.state
|
||||
recordingTime = service.recordingTime
|
||||
|
Loading…
x
Reference in New Issue
Block a user