Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
The CLI's play with a context reads the whole list before handing it over (the first answer of a big playlist was its first 100 songs, registered as the list and breaking the row index sent for later taps), and its songs count is 0 when the list does not hold the song, which then plays alone
kota-zo8b24fcf01d35
diff --git a/base/app/src/main/java/com/music/spotui/cli/CliReceiver.kt b/base/app/src/main/java/com/music/spotui/cli/CliReceiver.ktindex fc1f3f2d..6f2fee97 100644--- a/base/app/src/main/java/com/music/spotui/cli/CliReceiver.kt+++ b/base/app/src/main/java/com/music/spotui/cli/CliReceiver.kt@@ -201,14 +201,16 @@ class CliReceiver : BroadcastReceiver() {}is CliCommand.Play -> {// With a context, its songs too, as Android Auto and the phone give them: an audio-source- // extension plays the list on from the song, under its name. `songs` says how many were read (0: none).+ // extension plays the list on from the song, under its name. `songs` says how many were+ // handed over (0: none, or a list without the song, which then plays alone as before).val page = c.context?.let { pageOf(it) }val songs = page?.tracks?.takeIf { it.isNotEmpty() }onMain {page?.let { SongPlayer.registerContextName(it.uri, it.name) }SongPlayer.playSong(c.uri, contextUri = c.context, songs = songs)}- if (c.context == null) JsonNull else buildJsonObject { put("songs", songs?.size ?: 0) }+ val id = c.uri.substringAfterLast(':')+ if (c.context == null) JsonNull else buildJsonObject { put("songs", songs?.takeIf { l -> l.any { it.spotifyTrackId == id } }?.size ?: 0) }}CliCommand.Pause -> onMain { SongPlayer.pause(by = "cli"); JsonNull }CliCommand.Resume -> onMain { SongPlayer.play(by = "cli"); JsonNull }@@ -234,7 +236,11 @@ class CliReceiver : BroadcastReceiver() {return CliMask.knownSecrets(m?.settings.orEmpty(), Extensions.settingValues(id), Extensions.storageValues(id))}- /** The playlist, album or Liked Songs [uri] as its first answer gives it; null when it cannot be read. */+ /**+ * The playlist, album or Liked Songs [uri], read to its last song (or what came within+ * [READ_MS]); null when it cannot be read. Seen in review: stopped at its first answer, a big+ * playlist gave its first 100 songs and registered only those as the list (SongPlayer.rowIndex).+ */private suspend fun pageOf(uri: String): ContextPageModel? {val api = Graph.apival id = uri.substringAfterLast(':')@@ -244,8 +250,9 @@ class CliReceiver : BroadcastReceiver() {uri.startsWith("spotify:playlist:") -> api.getPlaylistPage(id)else -> return null}- val first = runCatching { withTimeoutOrNull(READ_MS) { flow.first { it !is Response.Loading } } }.getOrNull()- return (first as? Response.Success)?.data+ var read: ContextPageModel? = null+ runCatching { withTimeoutOrNull(READ_MS) { flow.first { it is Response.Error || (it as? Response.Success)?.data?.also { p -> read = p }?.complete == true } } }+ return read}private suspend fun <T> onMain(block: () -> T): T = withContext(Dispatchers.Main) { block() }