Browse Source

voice: play/pause toggle, stop previous on new track

- ViewModel: _currentPlayingPath tracks active track. Tap same → stop.
  Tap different → stop old, play new. onComplete clears currentPlayingPath.
- AudioRecorderManager: stopPlayback() already called at start (existing)
- VoiceBubble: simplified click, always sends to ViewModel for state management
topo_upd
evgeny 2 months ago
parent
commit
887bbdbf84
  1. 4
      tools/chatgui-android/app/src/main/java/com/utun/chat/ui/components/MessageBubble.kt
  2. 15
      tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt

4
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

15
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() {

Loading…
Cancel
Save