Skip to content

Commit

Permalink
playback: reduce more skipping on tight reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
OxygenCobalt committed Jan 12, 2025
1 parent 2f43113 commit cc6c508
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.oxycblt.auxio.playback.state.ShuffleMode
import org.oxycblt.auxio.playback.state.StateAck
import org.oxycblt.musikr.MusicParent
import org.oxycblt.musikr.Song
import kotlin.math.abs
import timber.log.Timber as L

class ExoPlaybackStateHolder(
Expand Down Expand Up @@ -372,7 +373,6 @@ class ExoPlaybackStateHolder(
) {
var sendNewPlaybackEvent = false
var shouldSeek = false
L.d("invalidating parent ${this.parent?.songs} ${parent?.songs}")
if (this.parent != parent) {
this.parent = parent
sendNewPlaybackEvent = true
Expand All @@ -393,9 +393,12 @@ class ExoPlaybackStateHolder(
}

repeatMode(repeatMode)
// Positions in milliseconds will drift during tight restores (i.e what the music loader
// does to sanitize the state), compare by seconds instead.
if (positionMs.msToSecs() != player.currentPosition.msToSecs() || shouldSeek) {
// See if we differ by more than a second. This allows us to avoid a meaningless seek
// in the case of a "tight restore" (i.e music was reloaded).
// In the case that this is a false positive, it's not very percievable (at least compared
// to skipping when updating the library).
// TODO: Introduce a better state management system rather than do something finicky like this.
if (shouldSeek || abs(player.currentPosition - positionMs) > 1000L) {
player.seekTo(positionMs)
}

Expand Down

0 comments on commit cc6c508

Please sign in to comment.