Skip to content

Commit

Permalink
Doesn't disable smooth seeking if smooth seeking is already enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Jan 10, 2024
1 parent a219379 commit 72a4889
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,33 @@ class SmoothProgressTrackerState(
private val player: Pillarbox,
coroutineScope: CoroutineScope
) : ProgressTrackerState {
private var initialSeekParameters = player.seekParameters
private var storedSeekParameters = player.seekParameters
private var storedPlayWhenReady = player.playWhenReady
private var storedSmoothSeeking = player.smoothSeekingEnabled
private val simpleProgressTrackerState = SimpleProgressTrackerState(player, coroutineScope)
private var startChanging = false
private var storedPlayWhenReady = player.playWhenReady
override val progress: StateFlow<Duration> = simpleProgressTrackerState.progress

override fun onChanged(progress: Duration) {
simpleProgressTrackerState.onChanged(progress)
if (!startChanging) {
player.setSeekParameters(SeekParameters.CLOSEST_SYNC)
player.smoothSeekingEnabled = true
startChanging = true
storedPlayWhenReady = player.playWhenReady
storedSmoothSeeking = player.smoothSeekingEnabled
storedSeekParameters = player.seekParameters
player.setSeekParameters(SeekParameters.CLOSEST_SYNC)
player.smoothSeekingEnabled = true
player.playWhenReady = false
}
player.seekTo(progress.inWholeMilliseconds)
}

override fun onFinished() {
startChanging = false
simpleProgressTrackerState.onFinished()
player.playWhenReady = storedPlayWhenReady
startChanging = false
player.smoothSeekingEnabled = false
player.setSeekParameters(initialSeekParameters)
player.smoothSeekingEnabled = storedSmoothSeeking
player.setSeekParameters(storedSeekParameters)
}

private companion object {
Expand Down

0 comments on commit 72a4889

Please sign in to comment.