From 4b88a2abfd14fb2704aa10f24b3e185eb2e50ac1 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:32:31 +0300 Subject: [PATCH] multiplatform: voice playing fix (#3046) --- .../chat/simplex/common/platform/RecAndPlay.android.kt | 6 +++--- .../kotlin/chat/simplex/common/model/ChatModel.kt | 4 ++++ .../kotlin/chat/simplex/common/platform/RecAndPlay.kt | 2 +- .../chat/simplex/common/platform/RecAndPlay.desktop.kt | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) 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 ebc1b416b5..5996193abb 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 @@ -134,7 +134,7 @@ actual object AudioPlayer: AudioPlayerInterface { // Returns real duration of the track private fun start(fileSource: CryptoFile, seek: Int? = null, onProgressUpdate: (position: Int?, state: TrackState) -> Unit): Int? { - val absoluteFilePath = getAppFilePath(fileSource.filePath) + val absoluteFilePath = if (fileSource.isAbsolutePath) fileSource.filePath else getAppFilePath(fileSource.filePath) if (!File(absoluteFilePath).exists()) { Log.e(TAG, "No such file: ${fileSource.filePath}") return null @@ -272,10 +272,10 @@ actual object AudioPlayer: AudioPlayerInterface { } } - override fun duration(filePath: String): Int? { + override fun duration(unencryptedFilePath: String): Int? { var res: Int? = null kotlin.runCatching { - helperPlayer.setDataSource(filePath) + helperPlayer.setDataSource(unencryptedFilePath) helperPlayer.prepare() helperPlayer.start() helperPlayer.stop() diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index fc0867aad6..cdabe71449 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -2089,6 +2089,10 @@ data class CryptoFile( val filePath: String, val cryptoArgs: CryptoFileArgs? ) { + + val isAbsolutePath: Boolean + get() = File(filePath).isAbsolute + companion object { fun plain(f: String): CryptoFile = CryptoFile(f, null) } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/RecAndPlay.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/RecAndPlay.kt index 2d6bb2a371..0e0f769487 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/RecAndPlay.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/RecAndPlay.kt @@ -29,7 +29,7 @@ interface AudioPlayerInterface { fun stop(fileName: String?) fun pause(audioPlaying: MutableState, pro: MutableState) fun seekTo(ms: Int, pro: MutableState, filePath: String?) - fun duration(filePath: String): Int? + fun duration(unencryptedFilePath: String): Int? } expect object AudioPlayer: AudioPlayerInterface diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/RecAndPlay.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/RecAndPlay.desktop.kt index 6e85ea91c6..8e6a7d7ef9 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/RecAndPlay.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/RecAndPlay.desktop.kt @@ -42,7 +42,7 @@ actual object AudioPlayer: AudioPlayerInterface { /*LALAL*/ } - override fun duration(filePath: String): Int? { + override fun duration(unencryptedFilePath: String): Int? { /*LALAL*/ return null }