fix: correct replay action to prevent reloading same file

This commit is contained in:
2026-06-22 13:47:29 +02:00
parent 5e3dc3059b
commit 38d6107423
@@ -95,28 +95,32 @@ class PlayerViewModel(
fun loadSubtitle(resourcePath: String) { fun loadSubtitle(resourcePath: String) {
viewModelScope.launch { viewModelScope.launch {
subtitle.value = subtitle.value = try {
try { val content = resourceReader.read(resourcePath = resourcePath)
val content = resourceReader.read(resourcePath = resourcePath) subtitleRepository.getSubtitle(content = content)
subtitleRepository.getSubtitle(content = content) } catch (exception: Exception) {
} catch (exception: Exception) { logger.error(
logger.error( message = "Failed to load subtitle: $resourcePath",
message = "Failed to load subtitle: $resourcePath", throwable = exception,
throwable = exception, )
) Subtitle(emptyList())
Subtitle(emptyList()) }
}
} }
} }
fun performMainPlayAction() { fun performMainPlayAction() {
when (uiState.value.playbackState) { when (uiState.value.playbackState) {
PlaybackState.PLAYING -> audioPlayer.pause() PlaybackState.PLAYING -> audioPlayer.pause()
PlaybackState.ENDED -> filePath?.let { play(it) } PlaybackState.ENDED -> replay()
PlaybackState.PAUSED, PlaybackState.IDLE -> audioPlayer.play() PlaybackState.PAUSED, PlaybackState.IDLE -> audioPlayer.play()
} }
} }
fun replay() {
audioPlayer.seekTo(0.milliseconds)
audioPlayer.play()
}
fun seekToTimePart(progress: Float) { fun seekToTimePart(progress: Float) {
val position = (progress.toDouble() * uiState.value.playbackTiming.durationMs).milliseconds val position = (progress.toDouble() * uiState.value.playbackTiming.durationMs).milliseconds
audioPlayer.seekTo(position) audioPlayer.seekTo(position)