Browse Source

cleanup: remove dead currentPlayPath, fix seekVoice _currentPlayingPath reset

- AudioRecorderManager: removed unused currentPlayPath (duplicate of ViewModel state)
- ChatViewModel: seekVoice now resets _currentPlayingPath on complete (prevents
  pause-on-already-ended after seek finishes)
topo_upd
evgeny 2 months ago
parent
commit
2edd9bcc06
  1. 5
      tools/chatgui-android/app/src/main/java/com/utun/chat/data/AudioRecorderManager.kt
  2. 2
      tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt

5
tools/chatgui-android/app/src/main/java/com/utun/chat/data/AudioRecorderManager.kt

@ -185,7 +185,6 @@ class AudioRecorderManager {
@Volatile var elapsedMs: Int = 0; private set @Volatile var elapsedMs: Int = 0; private set
var pausedElapsedMs: Int = 0; private set var pausedElapsedMs: Int = 0; private set
private var playThread: Thread? = null private var playThread: Thread? = null
private var currentPlayPath: String? = null
fun playVoiceFile(filePath: String, onProgress: ((Float) -> Unit)? = null, onComplete: () -> Unit = {}) { fun playVoiceFile(filePath: String, onProgress: ((Float) -> Unit)? = null, onComplete: () -> Unit = {}) {
playFromPosition(filePath, 0, onProgress, onComplete) playFromPosition(filePath, 0, onProgress, onComplete)
@ -193,7 +192,7 @@ class AudioRecorderManager {
fun playFromPosition(filePath: String, startMs: Int, onProgress: ((Float) -> Unit)? = null, onComplete: () -> Unit = {}) { fun playFromPosition(filePath: String, startMs: Int, onProgress: ((Float) -> Unit)? = null, onComplete: () -> Unit = {}) {
stopPlayback() stopPlayback()
isPaused = false; elapsedMs = startMs; playing = true; currentPlayPath = filePath isPaused = false; elapsedMs = startMs; playing = true
playThread = Thread { playThread = Thread {
try { try {
@ -246,7 +245,7 @@ class AudioRecorderManager {
} catch (e: Exception) { } catch (e: Exception) {
LogManager.addLog("ERROR", "AudioPlayer", "play error: ${e.message}") LogManager.addLog("ERROR", "AudioPlayer", "play error: ${e.message}")
} }
playing = false; isPaused = false; currentPlayPath = null playing = false; isPaused = false
onComplete() onComplete()
}.apply { start() } }.apply { start() }
} }

2
tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt

@ -285,7 +285,7 @@ class ChatViewModel : ViewModel() {
fun seekVoice(filePath: String, seekMs: Int, onDone: () -> Unit) { fun seekVoice(filePath: String, seekMs: Int, onDone: () -> Unit) {
audioRecorder.stopPlayback() audioRecorder.stopPlayback()
_currentPlayingPath = filePath _currentPlayingPath = filePath
audioRecorder.playFromPosition(filePath, seekMs, onComplete = onDone) audioRecorder.playFromPosition(filePath, seekMs, onComplete = { _currentPlayingPath = null; onDone() })
} }
fun clearState() { fun clearState() {

Loading…
Cancel
Save