Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
automix: analyses wait for the player's page on a cold start
kota-zo6e8b063790a4
diff --git a/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt b/base/app/src/main/java/com/music/spotui/automix/AutoMix.ktindex 2b2653f3..929d88d6 100644--- a/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt+++ b/base/app/src/main/java/com/music/spotui/automix/AutoMix.kt@@ -243,6 +243,7 @@ object AutoMix {if (cached != null) { synchronized(memory) { memory[k] = cached; refused -= requestId(uri) }; ready() }else pending += uri}+ if (pending.isNotEmpty()) waitForThePage()for (uri in pending) {val id = requestId(uri)if (epoch != cacheEpoch || id !in wanted) continue@@ -256,6 +257,21 @@ object AutoMix {}}+ @Volatile private var pageWaited = false++ /**+ * A cold start: the player's page loads first. A mix is planned long before it is needed, and two+ * songs decoded at once with it took the page from about 3 s to about 20 s on the test phone.+ */+ private fun waitForThePage() {+ if (pageWaited) return+ val end = android.os.SystemClock.elapsedRealtime() + PAGE_WAIT_MS+ while (android.os.SystemClock.elapsedRealtime() < end && !runCatching { app.myspoti.host.android.MyspotiRuntime.api.ready.value }.getOrDefault(false)) Thread.sleep(250)+ pageWaited = true+ }++ private const val PAGE_WAIT_MS = 25_000L+private fun analyse(uri: Uri, epoch: Long): Pair<String, TrackAnalysis>? {val id = requestId(uri)val cancelled = { epoch != cacheEpoch || id !in wanted }