Skip to content

Native Android client for Spotify, built with Jetpack Compose

Seek bar: seek with the song shown, mix motion follows the mix length

kota-zo7e99c649d56b
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.kt b/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.kt
index 6522e0bd..483415c8 100644
--- a/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/components/AutoMixVisuals.kt
@@ -145,9 +145,14 @@ fun rememberMixPulse(cue: LocalPlayer.MixCue?): MixPulse? {
val k = if (com.music.spotui.automix.AutoMix.pulseLevel == 1) 0.55f else 1f
withFrameNanos { now ->
val cue = LocalPlayer.mixCue.value
- // Drawn in a quarter over the 8 s before the mix, the rest along it.
+ // Drawn in a quarter over the 8 s before the mix, the rest along it. A quick mix (a cut,
+ // a skip) moves as far as its length allows: the whole draw-in and the spring back
+ // squeezed into a second or two read as a jolt. A skip has no run-up: from nothing.
val target = cue?.let {
- if (it.mixing) 0.25f + 0.75f * smooth(LocalPlayer.fadeProgress())
+ val depth = ((it.endMs - it.exitMs) / 8_000f).coerceIn(0.3f, 1f)
+ val from = if (it.skip) 0f else 0.25f
+ depth * if (it.mixing) from + (1 - from) * smooth(LocalPlayer.fadeProgress())
+ else if (it.skip) 0f
else 0.25f * smooth(((LocalPlayer.position() - (it.exitMs - 8_000)) / 8_000f).coerceIn(0f, 1f))
}
p.step(now, LocalPlayer.mixPulse() * k, target?.times(k))
diff --git a/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.kt b/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.kt
index 08ab16d0..5c087885 100644
--- a/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/look/ThinSlider.kt
@@ -36,6 +36,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -110,6 +111,10 @@ fun ThinSlider(
/** The mix's beat, 0..1, read in the draw: the stretch thickens and glows with it. */
) {
var dragging by remember { mutableStateOf(false) }
+ // The gesture loop below starts once; it calls the latest callbacks, not the first ones (a
+ // seek computed with the song shown when the player opened went past a shorter song's end).
+ val change by rememberUpdatedState(onValueChange)
+ val finished by rememberUpdatedState(onValueChangeFinished)
val height by animateDpAsState(
targetValue = if (dragging) activeHeight else idleHeight,
animationSpec = spring(
@@ -154,7 +159,7 @@ fun ThinSlider(
awaitEachGesture {
val down = awaitFirstDown(requireUnconsumed = false)
dragging = true
- onValueChange((down.position.x / size.width).coerceIn(0f, 1f))
+ change((down.position.x / size.width).coerceIn(0f, 1f))
while (true) {
val event = awaitPointerEvent()
@@ -164,13 +169,13 @@ fun ThinSlider(
break
}
if (pointer.positionChanged()) {
- onValueChange((pointer.position.x / size.width).coerceIn(0f, 1f))
+ change((pointer.position.x / size.width).coerceIn(0f, 1f))
pointer.consume()
}
}
dragging = false
- onValueChangeFinished?.invoke()
+ finished?.invoke()
}
},
contentAlignment = Alignment.Center,