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) {
viewModelScope.launch {
subtitle.value =
try {
val content = resourceReader.read(resourcePath = resourcePath)
subtitleRepository.getSubtitle(content = content)
} catch (exception: Exception) {
logger.error(
message = "Failed to load subtitle: $resourcePath",
throwable = exception,
)
Subtitle(emptyList())
}
subtitle.value = try {
val content = resourceReader.read(resourcePath = resourcePath)
subtitleRepository.getSubtitle(content = content)
} catch (exception: Exception) {
logger.error(
message = "Failed to load subtitle: $resourcePath",
throwable = exception,
)
Subtitle(emptyList())
}
}
}
fun performMainPlayAction() {
when (uiState.value.playbackState) {
PlaybackState.PLAYING -> audioPlayer.pause()
PlaybackState.ENDED -> filePath?.let { play(it) }
PlaybackState.ENDED -> replay()
PlaybackState.PAUSED, PlaybackState.IDLE -> audioPlayer.play()
}
}
fun replay() {
audioPlayer.seekTo(0.milliseconds)
audioPlayer.play()
}
fun seekToTimePart(progress: Float) {
val position = (progress.toDouble() * uiState.value.playbackTiming.durationMs).milliseconds
audioPlayer.seekTo(position)