Skip to content

Commit

Permalink
fix(player): Keep the player paused while loading tracks (#1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
Secozzi authored Jan 18, 2025
1 parent 9773a91 commit e1cc45f
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class PlayerViewModel @JvmOverloads constructor(
private val _paused = MutableStateFlow(false)
val paused = _paused.asStateFlow()

// False because the video shouldn't start paused
private val _pausedState = MutableStateFlow<Boolean?>(false)
val pausedState = _pausedState.asStateFlow()

private val _controlsShown = MutableStateFlow(!playerPreferences.hideControls().get())
val controlsShown = _controlsShown.asStateFlow()
private val _seekBarShown = MutableStateFlow(!playerPreferences.hideControls().get())
Expand Down Expand Up @@ -400,7 +404,7 @@ class PlayerViewModel @JvmOverloads constructor(

isLoadingTracks.update { _ -> true }
updateIsLoadingEpisode(false)
unpause()
setPausedState()
}

@Immutable
Expand Down Expand Up @@ -454,6 +458,10 @@ class PlayerViewModel @JvmOverloads constructor(

val idx = videoList.value.indexOf(video)

updatePausedState()
// Pause until everything has loaded
pause()

activity.setVideoList(
qualityIndex = idx,
videos = videoList.value,
Expand Down Expand Up @@ -526,6 +534,22 @@ class PlayerViewModel @JvmOverloads constructor(
_readAhead.update { value.toFloat() }
}

private fun updatePausedState() {
_pausedState.update { _ -> paused.value }
}

private fun setPausedState() {
pausedState.value?.let {
if (it) {
pause()
} else {
unpause()
}

_pausedState.update { _ -> null }
}
}

fun pauseUnpause() {
if (paused.value) {
unpause()
Expand Down

0 comments on commit e1cc45f

Please sign in to comment.