mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Bugfixes for recording behavior
This commit is contained in:
parent
14abd1aee0
commit
e4e8ae0158
@ -154,7 +154,7 @@ data class AudioRecorderSettings(
|
|||||||
else MediaRecorder.OutputFormat.THREE_GPP
|
else MediaRecorder.OutputFormat.THREE_GPP
|
||||||
}
|
}
|
||||||
|
|
||||||
return when(encoder) {
|
return when (encoder) {
|
||||||
MediaRecorder.AudioEncoder.AAC -> MediaRecorder.OutputFormat.AAC_ADTS
|
MediaRecorder.AudioEncoder.AAC -> MediaRecorder.OutputFormat.AAC_ADTS
|
||||||
MediaRecorder.AudioEncoder.AAC_ELD -> MediaRecorder.OutputFormat.AAC_ADTS
|
MediaRecorder.AudioEncoder.AAC_ELD -> MediaRecorder.OutputFormat.AAC_ADTS
|
||||||
MediaRecorder.AudioEncoder.AMR_NB -> MediaRecorder.OutputFormat.AMR_NB
|
MediaRecorder.AudioEncoder.AMR_NB -> MediaRecorder.OutputFormat.AMR_NB
|
||||||
@ -167,6 +167,7 @@ data class AudioRecorderSettings(
|
|||||||
MediaRecorder.OutputFormat.AAC_ADTS
|
MediaRecorder.OutputFormat.AAC_ADTS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaRecorder.AudioEncoder.OPUS -> {
|
MediaRecorder.AudioEncoder.OPUS -> {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
MediaRecorder.OutputFormat.OGG
|
MediaRecorder.OutputFormat.OGG
|
||||||
@ -174,11 +175,12 @@ data class AudioRecorderSettings(
|
|||||||
MediaRecorder.OutputFormat.AAC_ADTS
|
MediaRecorder.OutputFormat.AAC_ADTS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> MediaRecorder.OutputFormat.DEFAULT
|
else -> MediaRecorder.OutputFormat.DEFAULT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMimeType(): String = when(getOutputFormat()) {
|
fun getMimeType(): String = when (getOutputFormat()) {
|
||||||
MediaRecorder.OutputFormat.AAC_ADTS -> "audio/aac"
|
MediaRecorder.OutputFormat.AAC_ADTS -> "audio/aac"
|
||||||
MediaRecorder.OutputFormat.THREE_GPP -> "audio/3gpp"
|
MediaRecorder.OutputFormat.THREE_GPP -> "audio/3gpp"
|
||||||
MediaRecorder.OutputFormat.MPEG_4 -> "audio/mp4"
|
MediaRecorder.OutputFormat.MPEG_4 -> "audio/mp4"
|
||||||
@ -190,7 +192,7 @@ data class AudioRecorderSettings(
|
|||||||
else -> "audio/3gpp"
|
else -> "audio/3gpp"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSamplingRate(): Int = samplingRate ?: when(getOutputFormat()) {
|
fun getSamplingRate(): Int = samplingRate ?: when (getOutputFormat()) {
|
||||||
MediaRecorder.OutputFormat.AAC_ADTS -> 96000
|
MediaRecorder.OutputFormat.AAC_ADTS -> 96000
|
||||||
MediaRecorder.OutputFormat.THREE_GPP -> 44100
|
MediaRecorder.OutputFormat.THREE_GPP -> 44100
|
||||||
MediaRecorder.OutputFormat.MPEG_4 -> 44100
|
MediaRecorder.OutputFormat.MPEG_4 -> 44100
|
||||||
@ -202,11 +204,10 @@ data class AudioRecorderSettings(
|
|||||||
else -> 48000
|
else -> 48000
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEncoder(): Int = encoder ?:
|
fun getEncoder(): Int = encoder ?: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
MediaRecorder.AudioEncoder.AAC
|
||||||
MediaRecorder.AudioEncoder.AAC
|
else
|
||||||
else
|
MediaRecorder.AudioEncoder.AMR_NB
|
||||||
MediaRecorder.AudioEncoder.AMR_NB
|
|
||||||
|
|
||||||
fun setIntervalDuration(duration: Long): AudioRecorderSettings {
|
fun setIntervalDuration(duration: Long): AudioRecorderSettings {
|
||||||
if (duration < 10 * 1000L || duration > 60 * 60 * 1000L) {
|
if (duration < 10 * 1000L || duration > 60 * 60 * 1000L) {
|
||||||
@ -221,7 +222,6 @@ data class AudioRecorderSettings(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setBitRate(bitRate: Int): AudioRecorderSettings {
|
fun setBitRate(bitRate: Int): AudioRecorderSettings {
|
||||||
println("bitRate: $bitRate")
|
|
||||||
if (bitRate !in 1000..320000) {
|
if (bitRate !in 1000..320000) {
|
||||||
throw Exception("Bit rate must be between 1000 and 320000")
|
throw Exception("Bit rate must be between 1000 and 320000")
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,7 @@ class AudioRecorderService : IntervalRecorderService() {
|
|||||||
val filePath: String
|
val filePath: String
|
||||||
get() = "$folder/$counter.${settings!!.fileExtension}"
|
get() = "$folder/$counter.${settings!!.fileExtension}"
|
||||||
|
|
||||||
private fun clearAudioDevice() {
|
/// Tell Android to use the correct bluetooth microphone, if any selected
|
||||||
val audioManger = getSystemService(AUDIO_SERVICE)!! as AudioManager
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
||||||
audioManger.clearCommunicationDevice()
|
|
||||||
} else {
|
|
||||||
audioManger.stopBluetoothSco()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startAudioDevice() {
|
private fun startAudioDevice() {
|
||||||
if (selectedMicrophone == null) {
|
if (selectedMicrophone == null) {
|
||||||
return
|
return
|
||||||
@ -54,6 +45,16 @@ class AudioRecorderService : IntervalRecorderService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearAudioDevice() {
|
||||||
|
val audioManger = getSystemService(AUDIO_SERVICE)!! as AudioManager
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
audioManger.clearCommunicationDevice()
|
||||||
|
} else {
|
||||||
|
audioManger.stopBluetoothSco()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createRecorder(): MediaRecorder {
|
private fun createRecorder(): MediaRecorder {
|
||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
MediaRecorder(this)
|
MediaRecorder(this)
|
||||||
@ -185,7 +186,6 @@ class AudioRecorderService : IntervalRecorderService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
private fun registerMicrophoneListener() {
|
private fun registerMicrophoneListener() {
|
||||||
val audioManager = getSystemService(Context.AUDIO_SERVICE)!! as AudioManager
|
val audioManager = getSystemService(Context.AUDIO_SERVICE)!! as AudioManager
|
||||||
|
|
||||||
|
@ -102,7 +102,6 @@ abstract class RecorderService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RecorderState.IDLE -> {
|
RecorderState.IDLE -> {
|
||||||
stop()
|
|
||||||
onDestroy()
|
onDestroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +148,6 @@ abstract class RecorderService : Service() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|
||||||
stop()
|
stop()
|
||||||
changeState(RecorderState.IDLE)
|
|
||||||
|
|
||||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
NotificationManagerCompat.from(this)
|
NotificationManagerCompat.from(this)
|
||||||
|
@ -151,8 +151,6 @@ fun RecordingStatus(
|
|||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(microphoneStatus) {
|
LaunchedEffect(microphoneStatus) {
|
||||||
println(microphoneStatus)
|
|
||||||
println(previousStatus)
|
|
||||||
if (microphoneStatus != previousStatus && showMicrophoneStatusDialog == null && previousStatus != null) {
|
if (microphoneStatus != previousStatus && showMicrophoneStatusDialog == null && previousStatus != null) {
|
||||||
showMicrophoneStatusDialog = microphoneStatus
|
showMicrophoneStatusDialog = microphoneStatus
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package app.myzel394.alibi.ui.utils
|
package app.myzel394.alibi.ui.utils
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.media.AudioDeviceInfo
|
import android.media.AudioDeviceInfo
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
|
import android.os.Build
|
||||||
|
|
||||||
data class MicrophoneInfo(
|
data class MicrophoneInfo(
|
||||||
val deviceInfo: AudioDeviceInfo,
|
val deviceInfo: AudioDeviceInfo,
|
||||||
@ -24,12 +24,19 @@ data class MicrophoneInfo(
|
|||||||
return MicrophoneInfo(deviceInfo)
|
return MicrophoneInfo(deviceInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
fun fetchDeviceMicrophones(context: Context): List<MicrophoneInfo> {
|
fun fetchDeviceMicrophones(context: Context): List<MicrophoneInfo> {
|
||||||
val audioManager = context.getSystemService(Context.AUDIO_SERVICE)!! as AudioManager
|
val audioManager = context.getSystemService(Context.AUDIO_SERVICE)!! as AudioManager
|
||||||
return audioManager.availableCommunicationDevices.let {
|
val mics =
|
||||||
it.subList(2, it.size)
|
audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS).map(::fromDeviceInfo)
|
||||||
}.map(::fromDeviceInfo)
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
audioManager.availableCommunicationDevices.let {
|
||||||
|
it.subList(2, it.size)
|
||||||
|
}.map(::fromDeviceInfo)
|
||||||
|
} else {
|
||||||
|
audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS).let {
|
||||||
|
it.slice(1 until it.size)
|
||||||
|
}.map(::fromDeviceInfo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user