From 9de42e5611f88dc4940c2357241c1df7c5e059b5 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Mon, 5 Aug 2024 22:34:41 +0200 Subject: [PATCH] Fix audio processing when saving Related to #112 Update the `saveRecording` function in `RecorderEventsHandler.kt` to handle the case where there is only one batch and skip processing. * Add a check to see if there is only one batch and skip concatenation if true. * Modify the `saveRecording` function to use the single batch file path if there is only one batch. * Update the `saveAudioFile` and `saveVideoFile` calls to use the single batch file path if there is only one batch. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Myzel394/Alibi/issues/112?shareId=XXXX-XXXX-XXXX-XXXX). --- .../organisms/RecorderEventsHandler.kt | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/RecorderEventsHandler.kt b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/RecorderEventsHandler.kt index ce137e96..6da10a77 100644 --- a/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/RecorderEventsHandler.kt +++ b/app/src/main/java/app/myzel394/alibi/ui/components/RecorderScreen/organisms/RecorderEventsHandler.kt @@ -176,14 +176,18 @@ fun RecorderEventsHandler( else -> throw Exception("Unknown recorder type") } - batchesFolder.concatenate( - recording.recordingStart, - recording.fileExtension, - durationPerBatchInMilliseconds = settings.intervalDuration, - onProgress = { percentage -> - processingProgress = percentage - } - ) + val outputFile = if (batchesFolder.getBatchesForFFmpeg().size == 1) { + batchesFolder.getBatchesForFFmpeg().first() + } else { + batchesFolder.concatenate( + recording.recordingStart, + recording.fileExtension, + durationPerBatchInMilliseconds = settings.intervalDuration, + onProgress = { percentage -> + processingProgress = percentage + } + ) + } // Save file val name = batchesFolder.getName( @@ -196,19 +200,13 @@ fun RecorderEventsHandler( when (batchesFolder) { is AudioBatchesFolder -> { saveAudioFile( - batchesFolder.asInternalGetOutputFile( - recording.recordingStart, - recording.fileExtension, - ), name + outputFile, name ) } is VideoBatchesFolder -> { saveVideoFile( - batchesFolder.asInternalGetOutputFile( - recording.recordingStart, - recording.fileExtension, - ), name + outputFile, name ) } } @@ -368,4 +366,4 @@ fun RecorderEventsHandler( showRecorderError = false }, ) -} \ No newline at end of file +}