Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Immersive: the lyrics keep the outgoing song's words and position until half way through a mix, and the player no longer draws in and springs back over an open lyrics or queue panel
kota-zoffafea658bbc
diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricClock.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricClock.ktindex 942dde96..eab20be1 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricClock.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricClock.kt@@ -59,6 +59,9 @@ private const val PAUSED_POLL_MS = 120Lprivate fun playerPosition(): Long = SongPlayer.getCurrentPosition().coerceAtLeast(0L)+/** Where the song whose words are shown is: during the first half of a mix, the song going out. */+internal var lyricsPosition: () -> Long = ::playerPosition+/*** The song position, ticking every frame while [playing].*@@ -69,14 +72,14 @@ private fun playerPosition(): Long = SongPlayer.getCurrentPosition().coerceAtLea*/@Composableinternal fun rememberLyricsPlayhead(trackKey: Any, playing: Boolean): LyricsPlayhead {- val head = remember(trackKey) { LyricsPlayhead(playerPosition()) }+ val head = remember(trackKey) { LyricsPlayhead(lyricsPosition()) }val lifecycle = LocalLifecycleOwner.current.lifecycleLaunchedEffect(head, playing, lifecycle) {lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {if (!playing) {// Not moving: each reading is the truth, including a seek made while paused.while (isActive) {- val position = playerPosition()+ val position = lyricsPosition()head.engine.hold(position, nanosToMs(System.nanoTime()))head.clock.longValue = positionhead.lastReadMs = position@@ -92,7 +95,7 @@ internal fun rememberLyricsPlayhead(trackKey: Any, playing: Boolean): LyricsPlay// System.nanoTime clock; anywhere it is not, the real clock is used.val system = System.nanoTime()val now = nanosToMs(if (abs(system - frameNanos) < SAME_CLOCK_NANOS) frameNanos else system)- val position = playerPosition()+ val position = lyricsPosition()// To play but loading (a seek into a stream, its start): the position stands// still, and so do the words. Carried on at the learned rate, they ran ahead// of the song by the whole wait (seconds with an extension's stream) and thendiff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.ktindex f530422c..a79cc3c6 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/lyrics/ImmersiveLyricsPanel.kt@@ -157,6 +157,11 @@ fun ImmersiveLyricsPanel(modifier: Modifier = Modifier, contentPadding: PaddingVval context = androidx.compose.ui.platform.LocalContext.currentval vm: LyricsViewModel = viewModel()val song = Graph.currentSongState+ // An AutoMix mix or a crossfade: the words of the song going out until half way, at its own+ // position, as the title and the cover (SongBlend). Switched at the start, the new song's words+ // ran over the old song still heard for the whole mix (reported, worst with long mixes).+ val blend = com.music.spotui.ui.components.rememberSongBlend()+ val hold = blend?.outgoingWords == trueval title = song.title.valueval artist = song.singer.value// currentTrackId is plain data, not Compose state: a skip whose title and artist are the same@@ -164,9 +169,17 @@ fun ImmersiveLyricsPanel(modifier: Modifier = Modifier, contentPadding: PaddingVval playingUri = SongPlayer.nowPlaying.value.uri// Loaded as the Classic look does: read again when the lyrics extensions changed (they finish// starting after the app: the song not found by then stayed so until the panel was reopened).- val state = com.music.spotui.ui.screens.rememberLyricsState(vm, title, artist)+ val state = com.music.spotui.ui.screens.rememberLyricsState(vm, title, artist, hold)com.music.spotui.ui.screens.KeepScreenOnForLyrics(Graph.currentSongState.playingState.value && state is LyricsViewModel.State.Loaded)- val trackKey = "$playingUri|${SongPlayer.currentTrackId}|$title|$artist"+ val liveKey = "$playingUri|${SongPlayer.currentTrackId}|$title|$artist"+ // A plain holder (not state): the key of the words shown before the mix began.+ val heldKey = androidx.compose.runtime.remember { arrayOf(liveKey) }+ if (!hold) heldKey[0] = liveKey+ val trackKey = if (hold) heldKey[0] else liveKey+ DisposableEffect(hold, blend) {+ lyricsPosition = if (hold && blend != null) ({ blend.positionMs().coerceAtLeast(0L) }) else ({ SongPlayer.getCurrentPosition().coerceAtLeast(0L) })+ onDispose { lyricsPosition = { SongPlayer.getCurrentPosition().coerceAtLeast(0L) } }+ }val selecting by vm.selecting.collectAsState()val picked by vm.picked.collectAsState()// Back and closing the panel end the picking before anything else.diff --git a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.ktindex 3053f308..608f4613 100644--- a/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt+++ b/base/app/src/main/java/com/music/spotui/ui/immersive/player/ImmersivePlayer.kt@@ -305,7 +305,10 @@ fun ImmersivePlayer(BackHandler(enabled = panel != Panel.NONE) { panel = Panel.NONE }// The wave that leaves the cover when a mix is over, over everything.- BoxWithConstraints(modifier.fillMaxSize().background(Color.Black).mixWave(state.mixPulse, Color.White)) {+ // Not over an open panel: the lyrics or the queue drawing in and springing back with the mix+ // moved the lines being read (reported as particularly bad on the lyrics).+ val mixMotion = state.mixPulse.takeIf { panel == Panel.NONE }+ BoxWithConstraints(modifier.fillMaxSize().background(Color.Black).mixWave(mixMotion, Color.White)) {// Wider than tall (a phone on its side, a tablet), or a large portrait tablet: the cover// beside the controls. Very wide windows (DeX, large tablets): the lyrics and the queue// open in a third pane instead of over the cover.@@ -335,7 +338,7 @@ fun ImmersivePlayer()}// An AutoMix mix: the content draws in with it and springs back after it, the backdrop stays.- Box(Modifier.fillMaxSize().mixSqueeze(state.mixPulse)) {+ Box(Modifier.fillMaxSize().mixSqueeze(mixMotion)) {CompositionLocalProvider(LocalPlayerTint provides tint) {if (landscape) LandscapePlayer(state = state,diff --git a/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.kt b/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.ktindex b17d528f..99f3200d 100644--- a/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.kt+++ b/base/app/src/main/java/com/music/spotui/ui/screens/LyricsScreen.kt@@ -224,13 +224,15 @@ private fun shareLyrics(context: Context, title: String, artist: String, line: S}@Composable-internal fun rememberLyricsState(vm: LyricsViewModel, title: String, artist: String): LyricsViewModel.State {+internal fun rememberLyricsState(vm: LyricsViewModel, title: String, artist: String, hold: Boolean = false): LyricsViewModel.State {// currentTrackId is plain data, not Compose state: the playing item's uri re-runs the load on a skip.val playingUri = SongPlayer.nowPlaying.value.uri// The lyrics extensions changed (one installed, removed…): the song is read again from the new set.val sources by com.music.spotui.data.api.LyricsApi.sourcesTick.collectAsState()var seen by remember { mutableStateOf(sources) }- LaunchedEffect(title, artist, playingUri, SongPlayer.currentTrackId, sources) {+ LaunchedEffect(title, artist, playingUri, SongPlayer.currentTrackId, sources, hold) {+ // The first half of a mix: the words of the song going out stay, the new song's load after it.+ if (hold) return@LaunchedEffectval again = seen != sourcesseen = sourcesSongPlayer.currentLyricsTrack()?.let { vm.load(it, force = again) }