playback: reduce more skipping on tight reloads

This commit is contained in:
Alexander Capehart 2025-01-11 19:15:18 -07:00
parent 2f43113ce2
commit cc6c5084ff
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47

View file

@ -59,6 +59,7 @@ import org.oxycblt.auxio.playback.state.ShuffleMode
import org.oxycblt.auxio.playback.state.StateAck import org.oxycblt.auxio.playback.state.StateAck
import org.oxycblt.musikr.MusicParent import org.oxycblt.musikr.MusicParent
import org.oxycblt.musikr.Song import org.oxycblt.musikr.Song
import kotlin.math.abs
import timber.log.Timber as L import timber.log.Timber as L
class ExoPlaybackStateHolder( class ExoPlaybackStateHolder(
@ -372,7 +373,6 @@ class ExoPlaybackStateHolder(
) { ) {
var sendNewPlaybackEvent = false var sendNewPlaybackEvent = false
var shouldSeek = false var shouldSeek = false
L.d("invalidating parent ${this.parent?.songs} ${parent?.songs}")
if (this.parent != parent) { if (this.parent != parent) {
this.parent = parent this.parent = parent
sendNewPlaybackEvent = true sendNewPlaybackEvent = true
@ -393,9 +393,12 @@ class ExoPlaybackStateHolder(
} }
repeatMode(repeatMode) repeatMode(repeatMode)
// Positions in milliseconds will drift during tight restores (i.e what the music loader // See if we differ by more than a second. This allows us to avoid a meaningless seek
// does to sanitize the state), compare by seconds instead. // in the case of a "tight restore" (i.e music was reloaded).
if (positionMs.msToSecs() != player.currentPosition.msToSecs() || shouldSeek) { // 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) player.seekTo(positionMs)
} }