From e94bfded6c448815420aaf335676feca98e010be Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Fri, 17 Nov 2023 17:40:33 +0100 Subject: [PATCH] current stand --- .../alibi/helpers/AudioRecorderExporter.kt | 16 ++++++---------- .../alibi/services/AudioRecorderService.kt | 15 ++++++++------- .../alibi/ui/screens/AudioRecorderScreen.kt | 14 +++++--------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/app/myzel394/alibi/helpers/AudioRecorderExporter.kt b/app/src/main/java/app/myzel394/alibi/helpers/AudioRecorderExporter.kt index 9662199..760c415 100644 --- a/app/src/main/java/app/myzel394/alibi/helpers/AudioRecorderExporter.kt +++ b/app/src/main/java/app/myzel394/alibi/helpers/AudioRecorderExporter.kt @@ -55,8 +55,9 @@ data class AudioRecorderExporter( suspend fun concatenateFiles( context: Context, uri: Uri, + folder: DocumentFile, forceConcatenation: Boolean = false, - ): File { + ) { val filePaths = getFilePaths(context) val paths = filePaths.joinToString("|") { it.path @@ -70,11 +71,10 @@ data class AudioRecorderExporter( .toString() .replace(":", "-") .replace(".", "_") - val outputFile = File("${recording.folderPath}/$fileName.${recording.fileExtension}") - - if (outputFile.exists() && !forceConcatenation) { - return outputFile - } + val outputFile = FFmpegKitConfig.getSafParameterForWrite( + context, + (folder.uri.path + "/$fileName.aac").toUri() + ) val command = "-protocol_whitelist saf,concat,content,file,subfile " + "-i 'concat:${filePath}' -y" + @@ -108,11 +108,7 @@ data class AudioRecorderExporter( val minRequiredForPossibleInExactMaxDuration = recording.maxDuration / recording.intervalDuration - if (recording.forceExactMaxDuration && filePaths.size > minRequiredForPossibleInExactMaxDuration) { - stripConcatenatedFileToExactDuration(outputFile) - } - return outputFile } companion object { diff --git a/app/src/main/java/app/myzel394/alibi/services/AudioRecorderService.kt b/app/src/main/java/app/myzel394/alibi/services/AudioRecorderService.kt index d13e4b9..ec415e9 100644 --- a/app/src/main/java/app/myzel394/alibi/services/AudioRecorderService.kt +++ b/app/src/main/java/app/myzel394/alibi/services/AudioRecorderService.kt @@ -57,6 +57,14 @@ class AudioRecorderService : IntervalRecorderService() { } else { MediaRecorder() }.apply { + // Audio Source is kinda strange, here are my experimental findings using a Pixel 7 Pro + // and Redmi Buds 3 Pro: + // - MIC: Uses the bottom microphone of the phone (17) + // - CAMCORDER: Uses the top microphone of the phone (2) + // - VOICE_COMMUNICATION: Uses the bottom microphone of the phone (17) + // - DEFAULT: Uses the bottom microphone of the phone (17) + setAudioSource(MediaRecorder.AudioSource.MIC) + // Setting file path if (customOutputFolder == null) { val newFilePath = "${defaultOutputFolder}/$counter.${settings!!.fileExtension}" @@ -73,13 +81,6 @@ class AudioRecorderService : IntervalRecorderService() { } } - // Audio Source is kinda strange, here are my experimental findings using a Pixel 7 Pro - // and Redmi Buds 3 Pro: - // - MIC: Uses the bottom microphone of the phone (17) - // - CAMCORDER: Uses the top microphone of the phone (2) - // - VOICE_COMMUNICATION: Uses the bottom microphone of the phone (17) - // - DEFAULT: Uses the bottom microphone of the phone (17) - setAudioSource(MediaRecorder.AudioSource.MIC) println("outputformat eta: ${settings!!.outputFormat}") setOutputFormat(settings!!.outputFormat) diff --git a/app/src/main/java/app/myzel394/alibi/ui/screens/AudioRecorderScreen.kt b/app/src/main/java/app/myzel394/alibi/ui/screens/AudioRecorderScreen.kt index a8b90c1..8658f5d 100644 --- a/app/src/main/java/app/myzel394/alibi/ui/screens/AudioRecorderScreen.kt +++ b/app/src/main/java/app/myzel394/alibi/ui/screens/AudioRecorderScreen.kt @@ -96,14 +96,6 @@ fun AudioRecorderScreen( delay(100) try { - if (settings.audioRecorderSettings.saveFolder != null) { - AudioRecorderExporter.linkBatches( - context, - settings.audioRecorderSettings.saveFolder.toUri(), - AudioRecorderExporter.getFolder(context), - ) - } - val file = AudioRecorderExporter( audioRecorder.recorderService?.getRecordingInformation() ?: settings.lastRecording @@ -114,9 +106,13 @@ fun AudioRecorderScreen( context, settings.audioRecorderSettings.saveFolder!!.toUri(), )!!.findFile("1.aac")!!.uri, + DocumentFile.fromTreeUri( + context, + settings.audioRecorderSettings.saveFolder!!.toUri(), + )!! ) - saveFile(file, file.name) + //saveFile(file, file.name) } catch (error: Exception) { Log.getStackTraceString(error) } finally {