mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Fix encoders
This commit is contained in:
parent
a1895afafb
commit
ad1348d9a5
@ -106,7 +106,7 @@ dependencies {
|
||||
annotationProcessor 'com.google.dagger:hilt-compiler:2.46.1'
|
||||
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
|
||||
|
||||
implementation 'com.arthenica:ffmpeg-kit-min:5.1'
|
||||
implementation 'com.arthenica:ffmpeg-kit-min-gpl:5.1'
|
||||
|
||||
implementation "androidx.datastore:datastore-preferences:1.0.0"
|
||||
|
||||
|
@ -143,11 +143,52 @@ data class AudioRecorderSettings(
|
||||
val outputFormat: Int? = null,
|
||||
val encoder: Int? = null,
|
||||
) {
|
||||
fun getOutputFormat(): Int = outputFormat ?:
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
MediaRecorder.OutputFormat.AAC_ADTS
|
||||
else
|
||||
MediaRecorder.OutputFormat.THREE_GPP
|
||||
fun getOutputFormat(): Int {
|
||||
if (outputFormat != null) {
|
||||
return outputFormat
|
||||
}
|
||||
|
||||
if (encoder == null) {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
MediaRecorder.OutputFormat.AAC_ADTS
|
||||
else MediaRecorder.OutputFormat.THREE_GPP
|
||||
}
|
||||
|
||||
return when(encoder) {
|
||||
MediaRecorder.AudioEncoder.AAC -> MediaRecorder.OutputFormat.AAC_ADTS
|
||||
MediaRecorder.AudioEncoder.AAC_ELD -> MediaRecorder.OutputFormat.AAC_ADTS
|
||||
MediaRecorder.AudioEncoder.AMR_NB -> MediaRecorder.OutputFormat.AMR_NB
|
||||
MediaRecorder.AudioEncoder.AMR_WB -> MediaRecorder.OutputFormat.AMR_WB
|
||||
MediaRecorder.AudioEncoder.HE_AAC -> MediaRecorder.OutputFormat.AAC_ADTS
|
||||
MediaRecorder.AudioEncoder.VORBIS -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
MediaRecorder.OutputFormat.OGG
|
||||
} else {
|
||||
MediaRecorder.OutputFormat.AAC_ADTS
|
||||
}
|
||||
}
|
||||
MediaRecorder.AudioEncoder.OPUS -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
MediaRecorder.OutputFormat.OGG
|
||||
} else {
|
||||
MediaRecorder.OutputFormat.AAC_ADTS
|
||||
}
|
||||
}
|
||||
else -> MediaRecorder.OutputFormat.DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
fun getMimeType(): String = when(getOutputFormat()) {
|
||||
MediaRecorder.OutputFormat.AAC_ADTS -> "audio/aac"
|
||||
MediaRecorder.OutputFormat.THREE_GPP -> "audio/3gpp"
|
||||
MediaRecorder.OutputFormat.MPEG_4 -> "audio/mp4"
|
||||
MediaRecorder.OutputFormat.MPEG_2_TS -> "audio/ts"
|
||||
MediaRecorder.OutputFormat.WEBM -> "audio/webm"
|
||||
MediaRecorder.OutputFormat.AMR_NB -> "audio/amr"
|
||||
MediaRecorder.OutputFormat.AMR_WB -> "audio/amr-wb"
|
||||
MediaRecorder.OutputFormat.OGG -> "audio/ogg"
|
||||
else -> "audio/3gpp"
|
||||
}
|
||||
|
||||
fun getSamplingRate(): Int = samplingRate ?: when(getOutputFormat()) {
|
||||
MediaRecorder.OutputFormat.AAC_ADTS -> 96000
|
||||
@ -229,9 +270,13 @@ data class AudioRecorderSettings(
|
||||
}
|
||||
|
||||
fun isEncoderCompatible(encoder: Int): Boolean {
|
||||
if (outputFormat == null || outputFormat == MediaRecorder.OutputFormat.DEFAULT) {
|
||||
return true
|
||||
}
|
||||
|
||||
val supportedFormats = ENCODER_SUPPORTED_OUTPUT_FORMATS_MAP[encoder]!!
|
||||
|
||||
return supportedFormats.contains(getOutputFormat())
|
||||
return supportedFormats.contains(outputFormat)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -46,7 +46,6 @@ fun StartRecording(
|
||||
audioRecorder: AudioRecorderModel,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val saveFile = rememberFileSaverDialog("audio/*")
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
|
@ -45,7 +45,7 @@ fun OutputFormatTile() {
|
||||
.value
|
||||
val availableOptions = if (settings.audioRecorderSettings.encoder == null)
|
||||
AudioRecorderSettings.OUTPUT_FORMAT_INDEX_TEXT_MAP.keys.toTypedArray()
|
||||
else arrayOf(MediaRecorder.OutputFormat.DEFAULT, *AudioRecorderSettings.ENCODER_SUPPORTED_OUTPUT_FORMATS_MAP[settings.audioRecorderSettings.encoder]!!)
|
||||
else AudioRecorderSettings.ENCODER_SUPPORTED_OUTPUT_FORMATS_MAP[settings.audioRecorderSettings.encoder]!!
|
||||
|
||||
fun updateValue(outputFormat: Int?) {
|
||||
scope.launch {
|
||||
|
12
app/src/main/java/app/myzel394/alibi/ui/effects/settings.kt
Normal file
12
app/src/main/java/app/myzel394/alibi/ui/effects/settings.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package app.myzel394.alibi.ui.effects
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import app.myzel394.alibi.dataStore
|
||||
import app.myzel394.alibi.db.AppSettings
|
||||
|
||||
@Composable
|
||||
fun rememberSettings(): AppSettings {
|
||||
return LocalContext.current.dataStore.data.collectAsState(initial = AppSettings.getDefaultInstance()).value
|
||||
}
|
@ -32,7 +32,10 @@ import app.myzel394.alibi.ui.components.AudioRecorder.molecules.StartRecording
|
||||
import app.myzel394.alibi.ui.enums.Screen
|
||||
import app.myzel394.alibi.ui.utils.rememberFileSaverDialog
|
||||
import app.myzel394.alibi.R
|
||||
import app.myzel394.alibi.dataStore
|
||||
import app.myzel394.alibi.db.AppSettings
|
||||
import app.myzel394.alibi.db.LastRecording
|
||||
import app.myzel394.alibi.ui.effects.rememberSettings
|
||||
import app.myzel394.alibi.ui.models.AudioRecorderModel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ -42,7 +45,8 @@ fun AudioRecorder(
|
||||
navController: NavController,
|
||||
audioRecorder: AudioRecorderModel,
|
||||
) {
|
||||
val saveFile = rememberFileSaverDialog("audio/aac")
|
||||
val settings = rememberSettings()
|
||||
val saveFile = rememberFileSaverDialog(settings.audioRecorderSettings.getMimeType())
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
var isProcessingAudio by remember { mutableStateOf(false) }
|
||||
|
@ -15,8 +15,6 @@ fun rememberFileSaverDialog(mimeType: String): ((File) -> Unit) {
|
||||
var file = remember { mutableStateOf<File?>(null) }
|
||||
|
||||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument(mimeType)) {
|
||||
println("file")
|
||||
println(file)
|
||||
it?.let {
|
||||
context.contentResolver.openOutputStream(it)?.use { outputStream ->
|
||||
file.value!!.inputStream().use { inputStream ->
|
||||
@ -29,8 +27,6 @@ fun rememberFileSaverDialog(mimeType: String): ((File) -> Unit) {
|
||||
}
|
||||
|
||||
return {
|
||||
println("eich")
|
||||
println(it)
|
||||
file.value = it
|
||||
launcher.launch(it.name)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user