refactor: Improve selectedDevice; Use own rememberState; Reset selectedDevice on stop

This commit is contained in:
Myzel394 2023-10-21 19:15:15 +02:00
parent 57424cc1d3
commit a515d2b36c
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
2 changed files with 11 additions and 7 deletions

View File

@ -12,7 +12,7 @@ import android.os.Build
import app.myzel394.alibi.ui.utils.MicrophoneInfo
import java.lang.IllegalStateException
class AudioRecorderService: IntervalRecorderService() {
class AudioRecorderService : IntervalRecorderService() {
var amplitudesAmount = 1000
var selectedDevice: MicrophoneInfo? = null
@ -27,11 +27,11 @@ class AudioRecorderService: IntervalRecorderService() {
val audioManger = getSystemService(AUDIO_SERVICE)!! as AudioManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (selectedDevice == null) {
if (selectedDevice == null) {
audioManger.clearCommunicationDevice()
} else {
audioManger.setCommunicationDevice(selectedDevice!!.deviceInfo)
}
} else {
audioManger.setCommunicationDevice(selectedDevice!!.deviceInfo)
}
} else {
if (selectedDevice == null) {
audioManger.stopBluetoothSco()
@ -104,6 +104,7 @@ class AudioRecorderService: IntervalRecorderService() {
super.stop()
resetRecorder()
selectedDevice = null
}
override fun getAmplitudeAmount(): Int = amplitudesAmount

View File

@ -168,10 +168,13 @@ fun RecordingStatus(
if (microphones.isNotEmpty()) {
MicrophoneSelection(
microphones = microphones,
selectedMicrophone = audioRecorder.recorderService!!.selectedDevice,
selectedMicrophone = audioRecorder.selectedDevice,
onSelect = {
audioRecorder.changeMicrophone(it)
audioRecorder.recorderService!!.startNewCycle()
if (!audioRecorder.isPaused) {
audioRecorder.recorderService!!.startNewCycle()
}
}
)
}