diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/MessageBubble.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/MessageBubble.kt index 5a35bf69..a1cbec90 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/MessageBubble.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/MessageBubble.kt @@ -107,11 +107,9 @@ private fun VoiceBubble(message: Message, textColor: Color, onPlay: (String, () Box( modifier = Modifier.size(32.dp).background(Color.White, CircleShape) .clickable { - if (!playing && message.filePath.isNotEmpty()) { + if (message.filePath.isNotEmpty()) { playing = true; elapsedMs = 0; progress = 0f onPlay(message.filePath, onDone) - } else { - playing = false; onDone() } }, contentAlignment = Alignment.Center diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt index f0d6dca0..9ece7926 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt @@ -264,9 +264,22 @@ class ChatViewModel : ViewModel() { NativeLib.voiceSetCompressorConfig(maxGainDb, lookbackMs, lookaheadMs, riseRate, targetLevelDb) } + private var _currentPlayingPath: String? = null + fun playVoiceMessage(filePath: String, onComplete: () -> Unit) { + if (_currentPlayingPath == filePath) { + audioRecorder.stopPlayback() + _currentPlayingPath = null + onComplete() + return + } + audioRecorder.stopPlayback() + _currentPlayingPath = filePath LogManager.addLog("INFO", "VM", "play voice: $filePath") - audioRecorder.playVoiceFile(filePath, onComplete = onComplete) + audioRecorder.playVoiceFile(filePath, onComplete = { + _currentPlayingPath = null + onComplete() + }) } fun clearState() {