Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.
Kotlin alternativeandroidandroid-applicationclientglassmorphisminnertubelibrespotliquid-glassspotifyspotify-connectspotifyapiyoutube-musicyoutube-playerytdlnis
Queue a song and let it arrive in its own time
Lelonio0a66eec41514
diff --git a/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.kt b/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.ktindex 9d41189..9501572 100644--- a/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.kt+++ b/app/src/main/java/dev/lelonio/square/backend/SpotifyBackend.kt@@ -3,6 +3,7 @@ package dev.lelonio.square.backendimport androidx.media3.common.Playerimport androidx.media3.common.util.UnstableApiimport dev.lelonio.square.SquareApplication+import dev.lelonio.square.backend.lyrics.Losslessimport dev.lelonio.square.data.Catalogimport dev.lelonio.square.data.CatalogPlaylistimport dev.lelonio.square.data.CatalogTrackdiff --git a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.ktindex e48f542..e8e2681 100644--- a/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt+++ b/app/src/main/java/dev/lelonio/square/playback/LibrespotPlayer.kt@@ -825,8 +825,17 @@ class LibrespotPlayer(mediaItems: List<MediaItem>,): ListenableFuture<*> {queue.addFromMediaItems(index, mediaItems)- engineQueueStale = truereapplyShuffle()+ // The engine is told now, not at the end of the song.+ //+ // Left for later, the track a listener queued was not in the engine's+ // list when the current one ended: the engine moved to its own next+ // track and this side had to skip to the queued one after the fact,+ // which is a cut — the change of track the listener hears when they+ // press skip, in the middle of a crossfade they did not. Handed over as+ // an order, the queued track simply *is* what comes next, and the end+ // of the song dissolves into it like any other.+ pushOrder()onQueueChanged()invalidateState()return Futures.immediateVoidFuture()@@ -834,8 +843,11 @@ class LibrespotPlayer(override fun handleRemoveMediaItems(fromIndex: Int, toIndex: Int): ListenableFuture<*> {queue.remove(fromIndex, toIndex)- engineQueueStale = truereapplyShuffle()+ // A track taken out of the queue is gone from the engine's list too, and+ // for the same reason as above: otherwise it plays anyway when the+ // current song ends, and this side skips past it afterwards.+ pushOrder()onQueueChanged()invalidateState()return Futures.immediateVoidFuture()@@ -1097,22 +1109,30 @@ class LibrespotPlayer(// Handed over as an order rather than as a load. A load would restart// the decoder, and a reordering of what comes later has no business// interrupting the song that is playing.- if (queue.items.isNotEmpty()) {- engineIndex = queue.currentIndex- runCatching {- NativeBridge.setQueueOrder(queue.items.map { it.uri }, queue.currentIndex)- }- .onFailure {- // Left for the next skip to sort out, which rebuilds the- // queue wholesale: better a load then than a wrong order now.- android.util.Log.w("SquarePlayer", "could not reorder: ${it.message}")- engineQueueStale = true- }- }+ pushOrder()invalidateState()return Futures.immediateVoidFuture()}+ /**+ * Hands the engine the running order, without touching what is playing.+ *+ * A load would restart the decoder; a change to what comes *after* the+ * current track has no business interrupting it. When it cannot be sent the+ * queue is marked stale, and the next skip rebuilds it wholesale — better a+ * load then than a wrong order now.+ */+ private fun pushOrder() {+ if (queue.items.isEmpty()) return+ engineIndex = queue.currentIndex+ runCatching {+ NativeBridge.setQueueOrder(queue.items.map { it.uri }, queue.currentIndex)+ }.onFailure {+ android.util.Log.w("SquarePlayer", "could not reorder: ${it.message}")+ engineQueueStale = true+ }+ }+override fun handleSetRepeatMode(repeatMode: @Player.RepeatMode Int): ListenableFuture<*> {this.repeatMode = repeatModeengine("repeat") {diff --git a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt b/app/src/main/java/dev/lelonio/square/ui/SquareApp.ktindex e1585de..f61a865 100644--- a/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt+++ b/app/src/main/java/dev/lelonio/square/ui/SquareApp.kt@@ -587,7 +587,17 @@ fun SquareApp(val creditsLoading by viewModel.creditsLoading.collectAsStateWithLifecycle()var lyrics by remember { mutableStateOf<Lyrics?>(null) }- var lyricsLoading by remember { mutableStateOf(false) }++ /**+ * The track [lyrics] is the answer for.+ *+ * A flag set at the top of the fetch is not enough to say whether an answer+ * is in yet: between the track changing and the effect that fetches for it+ * starting, the flag still reads as it did for the track before — long+ * enough for the panel to say a song has no words before anybody has asked.+ * Naming the track the answer belongs to leaves no such moment.+ */+ var lyricsFor by remember { mutableStateOf<String?>(null) }// One small question per track: is this one saved? The player draws a heart// from the answer, and there is no other way to know without reading the@@ -599,8 +609,11 @@ fun SquareApp(LaunchedEffect(playback.mediaId) {val uri = playback.mediaIdlyrics = null- if (uri == null) return@LaunchedEffect- lyricsLoading = true+ lyricsFor = null+ if (uri == null) {+ lyricsFor = null+ return@LaunchedEffect+ }// Behind the song as well; see awaitAudible. The panel shows its own// spinner meanwhile, so the wait is visible rather than blank.awaitAudible(localState)@@ -614,7 +627,7 @@ fun SquareApp(durationMs = playback.durationMs,)}.getOrNull()- lyricsLoading = false+ lyricsFor = uri}// The language the app is read in. Changing it re-creates the activity,@@ -1582,11 +1595,16 @@ fun SquareApp(},queue = queue,lyrics = lyrics,- lyricsLoading = lyricsLoading,+ // Loading until the answer in hand is this+ // track's, which covers the wait before the+ // fetch has even begun.+ lyricsLoading = playback.mediaId != null &&+ lyricsFor != playback.mediaId,credits = credits,creditsLoading = creditsLoading,onWantCredits = viewModel::loadCredits,onPlayQueueItem = { player?.seekTo(it, 0L) },+ onRemoveQueueItem = { player?.removeMediaItem(it) },reverb = reverb,// Speed and pitch are set as a pair because// PlaybackParameters carries both; changing one@@ -2042,6 +2060,7 @@ fun SquareApp(}}}+ }}/**diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.ktindex 36a8976..7e08f39 100644--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerPanel.kt@@ -62,6 +62,7 @@ import com.adamglin.phosphoricons.regular.VinylRecordimport com.adamglin.phosphoricons.fill.Infoimport com.adamglin.phosphoricons.regular.Infoimport com.adamglin.phosphoricons.regular.X+import dev.lelonio.square.ui.glass.pressable/** Which panel is open below the transport controls. */enum class PlayerPanel {@@ -302,6 +303,21 @@ internal fun QueueList(overflow = TextOverflow.Ellipsis,)}++ // Not on the track being played: taking that one out is a+ // different act — it is a skip — and it already has a button.+ if (!entry.isCurrent) {+ Icon(+ PhosphorIcons.Regular.X,+ contentDescription = stringResource(R.string.remove_from_queue),+ tint = GlassInkDim,+ modifier = Modifier+ .clip(RoundedCornerShape(50))+ .pressable({ onRemove(entry.index) }, pressedScale = 0.86f)+ .padding(10.dp)+ .size(16.dp),+ )+ }}}}diff --git a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.ktindex ddb0878..3a193dc 100644--- a/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt+++ b/app/src/main/java/dev/lelonio/square/ui/player/PlayerScreen.kt@@ -82,7 +82,9 @@ import kotlinx.coroutines.withContextimport dev.lelonio.square.backend.spotify.panelAtimport androidx.core.graphics.scaleimport dev.lelonio.square.ui.glass.pressable+import dev.lelonio.square.ui.glass.LocalGlassEffectConfigimport dev.lelonio.square.ui.glass.backdrop.Backdrop+import dev.lelonio.square.ui.glass.liquidGlassimport dev.lelonio.square.ui.glass.backdrop.backdrops.layerBackdropimport dev.lelonio.square.ui.glass.backdrop.backdrops.rememberCombinedBackdropimport dev.lelonio.square.ui.glass.backdrop.backdrops.rememberLayerBackdrop@@ -99,6 +101,7 @@ import com.adamglin.phosphoricons.Fillimport com.adamglin.phosphoricons.Regularimport com.adamglin.phosphoricons.fill.Heartimport com.adamglin.phosphoricons.fill.Pause+import com.adamglin.phosphoricons.fill.MicrophoneStageimport com.adamglin.phosphoricons.fill.Playimport com.adamglin.phosphoricons.fill.SkipBackimport com.adamglin.phosphoricons.fill.SkipForward@@ -174,6 +177,8 @@ fun PlayerScreen(/** Asked for when the credits panel is opened, and not before. */onWantCredits: (String?) -> Unit,onPlayQueueItem: (Int) -> Unit,+ /** Drops one track out of the queue, by index. */+ onRemoveQueueItem: (Int) -> Unit,/** The music video for this track, when the catalogue has one. */videoFileId: String? = null,/** Whether the listener has asked to watch rather than listen. */@@ -737,7 +742,7 @@ fun PlayerScreen(}Stage.QUEUE -> Box(Modifier.fillMaxSize()) {- QueueList(queue, onPlayQueueItem)+ QueueList(queue, onPlayQueueItem, onRemoveQueueItem)}Stage.DEVICES -> Box(@@ -785,6 +790,7 @@ fun PlayerScreen(}}}+ }Spacer(Modifier.height(20.dp))@@ -844,7 +850,6 @@ fun PlayerScreen()}}- Spacer(Modifier.height(14.dp))}// Title and artist on their own capsule, with the two