mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-19 07:15:25 +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 lateinit var recordingTimeTimer: ScheduledExecutorService
|
||||||
private var notificationDetails: RecorderNotificationHelper.NotificationDetails? = null
|
private var notificationDetails: RecorderNotificationHelper.NotificationDetails? = null
|
||||||
|
|
||||||
var state = RecorderState.STOPPED
|
var state = RecorderState.IDLE
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var onStateChange: ((RecorderState) -> Unit)? = null
|
var onStateChange: ((RecorderState) -> Unit)? = null
|
||||||
|
@ -51,9 +51,11 @@ fun Navigation(
|
|||||||
|
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
audioRecorder.bindToService(context)
|
audioRecorder.bindToService(context)
|
||||||
|
videoRecorder.bindToService(context)
|
||||||
|
|
||||||
onDispose {
|
onDispose {
|
||||||
audioRecorder.unbindFromService(context)
|
audioRecorder.unbindFromService(context)
|
||||||
|
videoRecorder.unbindFromService(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
import app.myzel394.alibi.db.AppSettings
|
import app.myzel394.alibi.db.AppSettings
|
||||||
import app.myzel394.alibi.db.RecordingInformation
|
import app.myzel394.alibi.db.RecordingInformation
|
||||||
|
import app.myzel394.alibi.enums.RecorderState
|
||||||
import app.myzel394.alibi.helpers.AudioBatchesFolder
|
import app.myzel394.alibi.helpers.AudioBatchesFolder
|
||||||
import app.myzel394.alibi.services.AudioRecorderService
|
import app.myzel394.alibi.services.AudioRecorderService
|
||||||
import app.myzel394.alibi.ui.utils.MicrophoneInfo
|
import app.myzel394.alibi.ui.utils.MicrophoneInfo
|
||||||
@ -47,8 +48,13 @@ class AudioRecorderModel :
|
|||||||
onAmplitudeChange()
|
onAmplitudeChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `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.clearAllRecordings()
|
||||||
service.startRecording()
|
service.startRecording()
|
||||||
|
}
|
||||||
|
|
||||||
recorderState = service.state
|
recorderState = service.state
|
||||||
recordingTime = service.recordingTime
|
recordingTime = service.recordingTime
|
||||||
|
@ -105,6 +105,17 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
|||||||
|
|
||||||
protected open fun handleIntent(intent: Intent) = intent
|
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
|
// If override, call `super` AFTER setting the settings
|
||||||
open fun startRecording(
|
open fun startRecording(
|
||||||
context: Context,
|
context: Context,
|
||||||
@ -113,10 +124,7 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
|||||||
this.settings = settings
|
this.settings = settings
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
runCatching {
|
stopOldServices(context)
|
||||||
recorderService?.clearAllRecordings()
|
|
||||||
context.unbindService(connection)
|
|
||||||
}
|
|
||||||
|
|
||||||
notificationDetails = settings.notificationSettings.let {
|
notificationDetails = settings.notificationSettings.let {
|
||||||
if (it == null)
|
if (it == null)
|
||||||
@ -147,10 +155,6 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
|||||||
|
|
||||||
suspend fun stopRecording(context: Context) {
|
suspend fun stopRecording(context: Context) {
|
||||||
recorderService!!.stopRecording()
|
recorderService!!.stopRecording()
|
||||||
|
|
||||||
runCatching {
|
|
||||||
context.unbindService(connection)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pauseRecording() {
|
fun pauseRecording() {
|
||||||
@ -164,11 +168,8 @@ abstract class BaseRecorderModel<I, T : IntervalRecorderService<I>, B : BatchesF
|
|||||||
fun destroyService(context: Context) {
|
fun destroyService(context: Context) {
|
||||||
recorderService!!.destroy()
|
recorderService!!.destroy()
|
||||||
reset()
|
reset()
|
||||||
val intent = Intent(context, intentClass)
|
|
||||||
|
|
||||||
runCatching {
|
stopOldServices(context)
|
||||||
context.stopService(intent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind functions used to manually bind to the service if the app
|
// Bind functions used to manually bind to the service if the app
|
||||||
|
@ -39,8 +39,13 @@ class VideoRecorderModel :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceConnected(service: VideoRecorderService) {
|
override fun onServiceConnected(service: VideoRecorderService) {
|
||||||
|
// `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.clearAllRecordings()
|
||||||
service.startRecording()
|
service.startRecording()
|
||||||
|
}
|
||||||
|
|
||||||
recorderState = service.state
|
recorderState = service.state
|
||||||
recordingTime = service.recordingTime
|
recordingTime = service.recordingTime
|
||||||
|
Loading…
x
Reference in New Issue
Block a user