mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Improve microphone selection
This commit is contained in:
parent
69b4207124
commit
027e41d6b6
@ -1,24 +1,20 @@
|
||||
package app.myzel394.alibi.services
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.AudioDeviceInfo
|
||||
import android.media.AudioManager
|
||||
import android.media.MediaRecorder
|
||||
import android.media.MediaRecorder.OnErrorListener
|
||||
import android.media.MediaRecorder.getAudioSourceMax
|
||||
import android.os.Build
|
||||
import app.myzel394.alibi.ui.utils.MicrophoneInfo
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
class AudioRecorderService : IntervalRecorderService() {
|
||||
var amplitudesAmount = 1000
|
||||
var selectedDevice: MicrophoneInfo? = null
|
||||
var selectedMicrophone: MicrophoneInfo? = null
|
||||
|
||||
var recorder: MediaRecorder? = null
|
||||
private set
|
||||
var onError: () -> Unit = {}
|
||||
var onSelectedMicrophoneChange: (MicrophoneInfo?) -> Unit = {}
|
||||
|
||||
val filePath: String
|
||||
get() = "$folder/$counter.${settings!!.fileExtension}"
|
||||
@ -27,13 +23,13 @@ class AudioRecorderService : IntervalRecorderService() {
|
||||
val audioManger = getSystemService(AUDIO_SERVICE)!! as AudioManager
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (selectedDevice == null) {
|
||||
if (selectedMicrophone == null) {
|
||||
audioManger.clearCommunicationDevice()
|
||||
} else {
|
||||
audioManger.setCommunicationDevice(selectedDevice!!.deviceInfo)
|
||||
audioManger.setCommunicationDevice(selectedMicrophone!!.deviceInfo)
|
||||
}
|
||||
} else {
|
||||
if (selectedDevice == null) {
|
||||
if (selectedMicrophone == null) {
|
||||
audioManger.stopBluetoothSco()
|
||||
} else {
|
||||
audioManger.startBluetoothSco()
|
||||
@ -104,7 +100,7 @@ class AudioRecorderService : IntervalRecorderService() {
|
||||
super.stop()
|
||||
|
||||
resetRecorder()
|
||||
selectedDevice = null
|
||||
selectedMicrophone = null
|
||||
}
|
||||
|
||||
override fun getAmplitudeAmount(): Int = amplitudesAmount
|
||||
@ -118,4 +114,9 @@ class AudioRecorderService : IntervalRecorderService() {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fun changeMicrophone(microphone: MicrophoneInfo?) {
|
||||
selectedMicrophone = microphone
|
||||
onSelectedMicrophoneChange(microphone)
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
package app.myzel394.alibi.ui.components.AudioRecorder.organisms
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandHorizontally
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@ -13,22 +11,8 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Pause
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Save
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LargeFloatingActionButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@ -37,28 +21,17 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.myzel394.alibi.R
|
||||
import app.myzel394.alibi.ui.BIG_PRIMARY_BUTTON_SIZE
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.ConfirmDeletionDialog
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.DeleteButton
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.PauseResumeButton
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.RealtimeAudioVisualizer
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.RecordingTime
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.atoms.SaveButton
|
||||
import app.myzel394.alibi.ui.components.AudioRecorder.molecules.MicrophoneSelection
|
||||
import app.myzel394.alibi.ui.components.atoms.Pulsating
|
||||
import app.myzel394.alibi.ui.models.AudioRecorderModel
|
||||
import app.myzel394.alibi.ui.utils.KeepScreenOn
|
||||
import app.myzel394.alibi.ui.utils.MicrophoneInfo
|
||||
import app.myzel394.alibi.ui.utils.formatDuration
|
||||
import kotlinx.coroutines.delay
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@ -168,7 +141,7 @@ fun RecordingStatus(
|
||||
if (microphones.isNotEmpty()) {
|
||||
MicrophoneSelection(
|
||||
microphones = microphones,
|
||||
selectedMicrophone = audioRecorder.selectedDevice,
|
||||
selectedMicrophone = audioRecorder.selectedMicrophone,
|
||||
onSelect = {
|
||||
audioRecorder.changeMicrophone(it)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user