fix: correct replay action to prevent reloading same file
This commit is contained in:
+7
-3
@@ -95,8 +95,7 @@ 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) {
|
||||||
@@ -112,11 +111,16 @@ class PlayerViewModel(
|
|||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user