Skip to content

Native Android client for Spotify, built with Jetpack Compose

Immersive: the glass is redrawn five times a second once a page has settled, so a late cover, a row scrolled sideways or an animated header no longer leaves it on an old picture of the page; Spotify's stream quality is asked for over half a minute instead of the first 5 s, so the Immersive player (composed from the song's start) shows it; a failed extension install logs its whole exception chain

kota-zo340d40d4f2aa
diff --git a/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt b/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt
index 5d267b87..2f3b29f4 100644
--- a/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/components/PlayerSheets.kt
@@ -151,13 +151,18 @@ fun playingSourceLabel(): String {
* page once the song has loaded (it reports the stream a moment after the start); "" on another
* device or while it is not known. Same line, same tap (the quality sheet) as an extension's source.
*/
+/** How many times (every 2 s, about half a minute) the page is asked for the stream it plays. */
+private const val QUALITY_TRIES = 15
+
@Composable
private fun spotifyQualityLabel(uri: String): String {
if (SongPlayer.activeDevice.value != null || uri.isBlank()) return ""
val label by androidx.compose.runtime.produceState("", uri) {
value = ""
- for (wait in longArrayOf(1500, 3500)) {
- kotlinx.coroutines.delay(wait)
+ // The Immersive player is composed from the song's start, before the page has loaded the
+ // stream (later still after a pause or a slow start): asked again until it is known.
+ repeat(QUALITY_TRIES) { i ->
+ kotlinx.coroutines.delay(if (i == 0) 1500L else 2000L)
val (bitrate, mime) = app.myspoti.host.android.MyspotiRuntime.spotify.player.audioInfo()
if (bitrate > 0) { value = "${codecName(mime)} · ${bitrate / 1000} kbit/s"; return@produceState }
}
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdropModifier.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdropModifier.kt
index b446e09a..fcd50592 100644
--- a/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdropModifier.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/shell/backdrop/backdrops/LayerBackdropModifier.kt
@@ -114,12 +114,21 @@ private class LayerBackdropNode(
// two places and its damage counts in one. A page that just arrived fills in over its first
// moments (its data, its covers), so the glass is redrawn on every frame while it settles.
// Only then: a page animating on its own (a playing row) does not keep the blur running.
+ // Past that, the same holds for anything that changes without the page itself redrawing (a
+ // cover that loads late, a row of cards scrolled sideways, an animated header): the glass
+ // is redrawn a few times a second so it never keeps an old picture of the page for long.
+ // Driven by frames, so nothing runs while the app is in the background.
coroutineScope.launch {
val end = android.os.SystemClock.uptimeMillis() + SETTLE_MS
while (android.os.SystemClock.uptimeMillis() < end) {
androidx.compose.runtime.withFrameNanos { }
(registeredIn ?: backdrop).moves++
}
+ while (true) {
+ kotlinx.coroutines.delay(REFRESH_MS)
+ androidx.compose.runtime.withFrameNanos { }
+ (registeredIn ?: backdrop).moves++
+ }
}
}
@@ -147,3 +156,6 @@ private class LayerBackdropNode(
/** How long a page that just arrived keeps redrawing the glass as it fills in. */
private const val SETTLE_MS = 3_000L
+
+/** How often, once settled, the glass is redrawn over what the page shows now. */
+private const val REFRESH_MS = 200L
diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/ExtensionParts.kt b/base/app/src/main/java/com/music/spotui/ui/screens/ExtensionParts.kt
index 4c435cf8..5dda7e88 100644
--- a/base/app/src/main/java/com/music/spotui/ui/screens/ExtensionParts.kt
+++ b/base/app/src/main/java/com/music/spotui/ui/screens/ExtensionParts.kt
@@ -125,6 +125,8 @@ private val installScope = kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.
/** A failure said in a toast; a cancelled job (its screen closed) is not one. */
internal fun toastError(ctx: Context, t: Throwable) {
if (t is kotlinx.coroutines.CancellationException) return
+ // The whole chain in the log: a cancellation wrapped in another exception still shows here.
+ app.myspoti.host.android.Logbook.log("ext: not installed: " + generateSequence(t) { it.cause }.take(4).joinToString(" <- ") { "${it.javaClass.name}: ${it.message}" })
Toast.makeText(ctx.applicationContext, ctx.getString(R.string.extensions_error, t.message ?: t.toString()), Toast.LENGTH_LONG).show()
}