mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Properly stop foreground service
This commit is contained in:
parent
3e41030315
commit
8dcefc59eb
@ -37,7 +37,6 @@ class AudioRecorderModel: ViewModel() {
|
|||||||
val progress: Float
|
val progress: Float
|
||||||
get() = (recordingTime!! / recorderService!!.settings!!.maxDuration).toFloat()
|
get() = (recordingTime!! / recorderService!!.settings!!.maxDuration).toFloat()
|
||||||
|
|
||||||
private var intent: Intent? = null
|
|
||||||
var recorderService: AudioRecorderService? = null
|
var recorderService: AudioRecorderService? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
@ -86,15 +85,13 @@ class AudioRecorderModel: ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun startRecording(context: Context) {
|
fun startRecording(context: Context) {
|
||||||
reset()
|
|
||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
context.unbindService(connection)
|
context.unbindService(connection)
|
||||||
}
|
}
|
||||||
|
|
||||||
intent = Intent(context, AudioRecorderService::class.java)
|
val intent = Intent(context, AudioRecorderService::class.java)
|
||||||
ContextCompat.startForegroundService(context, intent!!)
|
ContextCompat.startForegroundService(context, intent)
|
||||||
context.bindService(intent!!, connection, Context.BIND_AUTO_CREATE)
|
context.bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopRecording(context: Context, saveAsLastRecording: Boolean = true) {
|
fun stopRecording(context: Context, saveAsLastRecording: Boolean = true) {
|
||||||
@ -104,9 +101,11 @@ class AudioRecorderModel: ViewModel() {
|
|||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
context.unbindService(connection)
|
context.unbindService(connection)
|
||||||
context.stopService(intent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val intent = Intent(context, AudioRecorderService::class.java)
|
||||||
|
context.stopService(intent)
|
||||||
|
|
||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user