Skip to content

Native Android client for Spotify, built with Jetpack Compose

A picked song waits 5 s at most for the extensions, then Spotify plays it: a source whose server timed out held the tap silent 12 s (up to 15); the extensions are asked again for the next songs, and one timing out several times in a row is set aside a while

kota-zocc4b8e0d68a5
diff --git a/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt b/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt
index b3926e40..5e364865 100644
--- a/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt
+++ b/base/app/src/main/java/com/music/spotui/extensions/ExtensionAudio.kt
@@ -10,6 +10,7 @@ import com.music.spotui.di.LocalPlayer
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
+import kotlinx.coroutines.withTimeoutOrNull
import java.util.concurrent.ConcurrentHashMap
/**
@@ -185,9 +186,16 @@ object ExtensionAudio {
// A downloaded song plays from its file whatever the extensions have: asked first, a miss (after
// up to 13 s) sent a song marked downloaded to Spotify's stream.
if (!OfflineStore.isDownloaded(picked.spotifyTrackId)) {
- val first = known[picked.spotifyTrackId]?.takeIf { it.fresh }?.stream ?: withContext(Dispatchers.IO) {
- Extensions.audio(Extensions.trackInfo(picked.spotifyTrackId, picked.title, picked.singer, picked.album, picked.durationMs.toLong(), picked.coverUri))
- } ?: return false
+ // A tap waits [Extensions.PICK_AUDIO_MS] for the extensions, then Spotify plays the song.
+ // The outer bound also covers a wait in the extension's queue or for extensions still loading.
+ val first = known[picked.spotifyTrackId]?.takeIf { it.fresh }?.stream ?: withTimeoutOrNull(Extensions.PICK_AUDIO_MS + 1_000) {
+ withContext(Dispatchers.IO) {
+ Extensions.audio(Extensions.trackInfo(picked.spotifyTrackId, picked.title, picked.singer, picked.album, picked.durationMs.toLong(), picked.coverUri), timeoutMs = Extensions.PICK_AUDIO_MS)
+ }
+ } ?: run {
+ app.myspoti.host.android.Logbook.log("audio: no extension audio for ${picked.title} within ${Extensions.PICK_AUDIO_MS / 1000} s: Spotify plays it")
+ return false
+ }
keep(picked.spotifyTrackId, first)
}
val (list, at) = AudioRoute.queue(songs, picked)
diff --git a/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt b/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt
index bc49c980..e79af07d 100644
--- a/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt
+++ b/base/app/src/main/java/com/music/spotui/extensions/Extensions.kt
@@ -97,6 +97,12 @@ object Extensions {
const val LYRICS_MS = HookBudgets.LYRICS
/** An audio-source hook call. */
const val AUDIO_MS = HookBudgets.AUDIO
+ /**
+ * An audio-source call for a song the user just picked: past it Spotify plays the song (seen:
+ * a source whose server timed out held the tap silent 12 s, up to [AUDIO_MS]). The extension
+ * is asked again for the next songs; one timing out several times in a row is set aside a while.
+ */
+ const val PICK_AUDIO_MS = 5_000L
/** A download-source hook call (an extension may try several places). */
const val DOWNLOAD_MS = HookBudgets.DOWNLOAD
private const val TRACK_MS = HookBudgets.TRACK