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
This commit is contained in:
1 parent
b8e15ad1f2
commit
887bbdbf84
2 files changed
+15
-4
No files matched your search
+1
-3
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user