Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Skipping while paused costs no audio keys

Lelonio24c12e9a1b87
diff --git a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt
index 9f7903d..f7898ff 100644
--- a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt
+++ b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt
@@ -624,6 +624,18 @@ class LibrespotPlayer(
/** A skip already handed to the engine, still to be confirmed by an event. */
private var skipInFlight = false
+ /**
+ * A skip made while paused, held until play is pressed.
+ *
+ * Every load is an audio key, and Spotify meters those per account: a
+ * listener paging through the queue with the music paused was spending
+ * one on every song they passed, none of which they heard, and the
+ * refusals that followed landed on the song they finally pressed play on.
+ * The screen moves at once; the engine is told when there is something to
+ * hear.
+ */
+ private var deferredSkip = false
+
/**
* Moves to a track, without making the user wait for the engine.
*
@@ -654,6 +666,20 @@ class LibrespotPlayer(
// C.TIME_UNSET for "wherever it starts", which as a number is very
// negative and made the bar draw itself backwards.
this.positionMs = positionMs.coerceAtLeast(0)
+
+ // Paused: nothing is loaded until play; see deferredSkip. Held as a
+ // pending skip so what the engine says about the track it is still on
+ // does not pull the screen back to it.
+ if (!playWhenReady && !deviceGone && engineIndex >= 0) {
+ deferredSkip = queue.currentIndex != engineIndex || this.positionMs > 0
+ skipPending = deferredSkip
+ handler.removeCallbacks(settleSkip)
+ handler.removeCallbacks(skipGaveUp)
+ playbackState = Player.STATE_READY
+ invalidateState()
+ return
+ }
+
playbackState = Player.STATE_BUFFERING
skipPending = true
invalidateState()
@@ -815,6 +841,24 @@ class LibrespotPlayer(
return Futures.immediateVoidFuture()
}
+ // A skip made while paused goes out now, playing: the track the
+ // engine holds is not the one on the screen. One load for however
+ // many songs were passed.
+ if (deferredSkip) {
+ deferredSkip = false
+ if (queue.currentIndex == engineIndex && positionMs == 0L) {
+ skipPending = false
+ } else {
+ playbackState = Player.STATE_BUFFERING
+ skipInFlight = true
+ invalidateState()
+ handler.removeCallbacks(skipGaveUp)
+ handler.postDelayed(skipGaveUp, SKIP_CONFIRM_MS)
+ pushQueue(startPlaying = true, positionMs = positionMs.toInt())
+ return Futures.immediateVoidFuture()
+ }
+ }
+
// If no track is currently loaded but queue exists, load the queue.
// Otherwise, unpause the existing loaded track immediately via NativeBridge.play().
if (currentMediaItem == null && queue.items.isNotEmpty()) {