fix: correct replay action to prevent reloading same file
This commit is contained in:
+16
-12
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user