playback: reduce more skipping on tight reloads
This commit is contained in:
parent
2f43113ce2
commit
cc6c5084ff
1 changed files with 7 additions and 4 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue