diff --git a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/RecAndPlay.android.kt b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/RecAndPlay.android.kt index b89719b2e..f99dea77c 100644 --- a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/RecAndPlay.android.kt +++ b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/RecAndPlay.android.kt @@ -284,9 +284,11 @@ actual object AudioPlayer: AudioPlayerInterface { kotlin.runCatching { helperPlayer.setDataSource(unencryptedFilePath) helperPlayer.prepare() - helperPlayer.start() - helperPlayer.stop() - res = helperPlayer.duration + if (helperPlayer.duration <= 0) { + Log.e(TAG, "Duration of audio is incorrect: ${helperPlayer.duration}") + } else { + res = helperPlayer.duration + } helperPlayer.reset() } return res diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt index 59e43557e..959ded42b 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ComposeView.kt @@ -776,7 +776,11 @@ fun ComposeView( .collect { when(it) { is RecordingState.Started -> onAudioAdded(it.filePath, it.progressMs, false) - is RecordingState.Finished -> onAudioAdded(it.filePath, it.durationMs, true) + is RecordingState.Finished -> if (it.durationMs > 300) { + onAudioAdded(it.filePath, it.durationMs, true) + } else { + cancelVoice() + } is RecordingState.NotStarted -> {} } }