Show the lyrics on the screen saver when Settings asks for them

Settings gets a Screen saver section: Photos (as before, the default) or
Photos and lyrics. With lyrics on, the saver fetches the playing track's
lyrics (Yandex's, else LRCLIB's) and stacks three lines right above the
song name, on the caption's side and at its edge: the line being sung,
large, between the one before and the one to come. Plain lyrics can't
know the line, so they show three same-size lines about as far in as
the song is.

The block is anchored at its foot and the next line's slot is always
kept, so the lines stay at one distance from the song name whatever
they say; lines crossfade as the song moves on, over a shade on that
side and with a text shadow for photos that are light.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yuriy.pandClaude Opus 5.5 committed 2026-10-19 12:17:37 +06:00
1 parent 81fce4a335
commit 0a08e6923a
8 files changed
+156 -5

No files matched your search

@@ -19,6 +19,26 @@ data class Lyrics(
return lines.indexOfLast { it.atMs != null && it.atMs <= positionMs }.takeIf { it >= 0 } return lines.indexOfLast { it.atMs != null && it.atMs <= positionMs }.takeIf { it >= 0 }
} }
/**
* The few lines a glance from the sofa shows at `positionMs`: synced, the line being sung
* between its neighbours (before the first, just the first, to come); plain, the line as far
* through the words as the song is through its `durationMs`. Null when there's nothing to show.
*/
fun glance(positionMs: Long, durationMs: Long): Glance? {
if (synced) {
if (lines.isEmpty()) return null
val i = current(positionMs) ?: return Glance(null, null, lines.first().text)
return Glance(lines.getOrNull(i - 1)?.text, lines[i].text, lines.getOrNull(i + 1)?.text)
}
val words = lines.map { it.text }.filter { it.isNotBlank() }
if (words.isEmpty() || durationMs <= 0) return null
val i = (positionMs.coerceIn(0, durationMs) * words.size / durationMs).toInt().coerceAtMost(words.size - 1)
return Glance(words.getOrNull(i - 1), words[i], words.getOrNull(i + 1))
}
/** Three lines around now; an empty line is a break in the singing. */
data class Glance(val previous: String?, val current: String?, val next: String?)
companion object { companion object {
/** Plain text: one line per line, blank lines kept as paragraph breaks. */ /** Plain text: one line per line, blank lines kept as paragraph breaks. */
fun fromText(text: String, writers: List<String>, source: LyricsSource = LyricsSource.Yandex) = fun fromText(text: String, writers: List<String>, source: LyricsSource = LyricsSource.Yandex) =
@@ -43,6 +43,8 @@ data class Settings(
val appearance: Appearance = Appearance.System, val appearance: Appearance = Appearance.System,
val fontSize: FontSize = FontSize.Medium, val fontSize: FontSize = FontSize.Medium,
val language: Locale = Locale.System, val language: Locale = Locale.System,
/** Whether the screen saver shows the playing track's lyrics over the photos. */
val saverLyrics: Boolean = false,
) )
class SettingsStore(context: Context) { class SettingsStore(context: Context) {
@@ -56,6 +58,7 @@ class SettingsStore(context: Context) {
appearance = Appearance.entries.firstOrNull { it.key == prefs.getString("appearance", null) } ?: d.appearance, appearance = Appearance.entries.firstOrNull { it.key == prefs.getString("appearance", null) } ?: d.appearance,
fontSize = FontSize.entries.firstOrNull { it.key == prefs.getString("font_size", null) } ?: d.fontSize, fontSize = FontSize.entries.firstOrNull { it.key == prefs.getString("font_size", null) } ?: d.fontSize,
language = Locale.entries.firstOrNull { it.key == prefs.getString("language", null) } ?: d.language, language = Locale.entries.firstOrNull { it.key == prefs.getString("language", null) } ?: d.language,
saverLyrics = prefs.getBoolean("saver_lyrics", d.saverLyrics),
) )
} }
@@ -65,6 +68,7 @@ class SettingsStore(context: Context) {
putString("appearance", settings.appearance.key) putString("appearance", settings.appearance.key)
putString("font_size", settings.fontSize.key) putString("font_size", settings.fontSize.key)
putString("language", settings.language.key) putString("language", settings.language.key)
putBoolean("saver_lyrics", settings.saverLyrics)
} }
} }
@@ -584,6 +584,8 @@ class AppState(
fun setFontSize(fontSize: FontSize) = updateSettings(settings.copy(fontSize = fontSize)) fun setFontSize(fontSize: FontSize) = updateSettings(settings.copy(fontSize = fontSize))
fun setSaverLyrics(on: Boolean) = updateSettings(settings.copy(saverLyrics = on))
/** The activity recreates itself in the new language; Yandex's own titles follow. */ /** The activity recreates itself in the new language; Yandex's own titles follow. */
fun setLanguage(language: Locale) { fun setLanguage(language: Locale) {
val before = contentLanguage val before = contentLanguage
@@ -1,19 +1,23 @@
// The app's own screen saver. While music plays the screen stays on, so the system's saver // The app's own screen saver. While music plays the screen stays on, so the system's saver
// never starts; after the system's screen saver delay without input, photos of the artist and // never starts; after the system's screen saver delay without input, photos of the artist and
// the cover drift across the screen with what's playing. Paused for a while, or with nothing // the cover drift across the screen with what's playing, and the lyrics when Settings asks for
// queued, the app lets go and the TV's own saver and sleep take over again. // them. Paused for a while, or with nothing queued, the app lets go and the TV's own saver and
// sleep take over again.
package it.panov.musyx.tv.ui.screens package it.panov.musyx.tv.ui.screens
import android.content.Context import android.content.Context
import android.os.SystemClock import android.os.SystemClock
import android.provider.Settings import android.provider.Settings
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.Crossfade import androidx.compose.animation.Crossfade
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
@@ -35,8 +39,10 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shadow
import androidx.compose.ui.graphics.TransformOrigin import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
@@ -49,8 +55,10 @@ import androidx.tv.material3.Text
import coil3.SingletonImageLoader import coil3.SingletonImageLoader
import coil3.compose.AsyncImage import coil3.compose.AsyncImage
import coil3.request.ImageRequest import coil3.request.ImageRequest
import it.panov.musyx.tv.api.Lyrics
import it.panov.musyx.tv.api.Track import it.panov.musyx.tv.api.Track
import it.panov.musyx.tv.state.AppState import it.panov.musyx.tv.state.AppState
import it.panov.musyx.tv.state.Loadable
import it.panov.musyx.tv.player.Status import it.panov.musyx.tv.player.Status
import it.panov.musyx.tv.ui.artistsOrUnknown import it.panov.musyx.tv.ui.artistsOrUnknown
import it.panov.musyx.tv.ui.theme.CoverPlaceholder import it.panov.musyx.tv.ui.theme.CoverPlaceholder
@@ -79,6 +87,13 @@ private const val PHOTO_SIZE = 1000
/** Artists whose galleries are fetched, from the start of the track's artist list. */ /** Artists whose galleries are fetched, from the start of the track's artist list. */
private const val GALLERY_ARTISTS = 2 private const val GALLERY_ARTISTS = 2
/** The crossfade from one lyric line to the next. */
private const val LYRIC_FADE_MS = 400
/** The caption's width, and the wider column it shares with the lyrics. */
private val CAPTION_WIDTH = 560.dp
private val LYRICS_WIDTH = 620.dp
/** When the remote was last touched, and whether the screen saver covers the app. */ /** When the remote was last touched, and whether the screen saver covers the app. */
@Stable @Stable
class ScreenSaverState { class ScreenSaverState {
@@ -181,6 +196,10 @@ private fun ScreenSaver(state: AppState, track: Track, galleries: MutableMap<Lon
} }
} }
val showLyrics = state.settings.saverLyrics
LaunchedEffect(track.id, showLyrics) { if (showLyrics) state.wantLyrics(track) }
val lyrics = if (showLyrics) (state.lyrics[track.id] as? Loadable.Loaded)?.value else null
Box(Modifier.fillMaxSize().background(Color.Black)) { Box(Modifier.fillMaxSize().background(Color.Black)) {
Crossfade(slide, animationSpec = tween(PHOTO_FADE_MS), label = "photo") { s -> Crossfade(slide, animationSpec = tween(PHOTO_FADE_MS), label = "photo") { s ->
Photo(s, track.hues) Photo(s, track.hues)
@@ -191,9 +210,34 @@ private fun ScreenSaver(state: AppState, track: Track, galleries: MutableMap<Lon
.background(Brush.verticalGradient(0.45f to Color.Transparent, 1f to Color.Black.copy(alpha = 0.8f))), .background(Brush.verticalGradient(0.45f to Color.Transparent, 1f to Color.Black.copy(alpha = 0.8f))),
) )
// The caption changes sides with each photo, so nothing sits still on the panel. // The caption changes sides with each photo, so nothing sits still on the panel.
// The lyrics ride with it, stacked right above the song name over a shade of their own.
Crossfade(slide.n % 2 == 0, animationSpec = tween(PHOTO_FADE_MS), label = "caption") { left -> Crossfade(slide.n % 2 == 0, animationSpec = tween(PHOTO_FADE_MS), label = "caption") { left ->
Box(Modifier.fillMaxSize()) {
if (lyrics != null) {
val shade = Color.Black.copy(alpha = 0.6f)
Box(
Modifier.fillMaxSize().background(
if (left) {
Brush.horizontalGradient(0f to shade, 0.6f to Color.Transparent)
} else {
Brush.horizontalGradient(0.4f to Color.Transparent, 1f to shade)
},
),
)
}
Box(Modifier.fillMaxSize().padding(horizontal = MusyxTheme.space.safeX, vertical = MusyxTheme.space.safeY)) { Box(Modifier.fillMaxSize().padding(horizontal = MusyxTheme.space.safeX, vertical = MusyxTheme.space.safeY)) {
Caption(state, track, left, Modifier.align(if (left) Alignment.BottomStart else Alignment.BottomEnd)) Column(
Modifier
.align(if (left) Alignment.BottomStart else Alignment.BottomEnd)
.width(if (lyrics != null) LYRICS_WIDTH else CAPTION_WIDTH),
horizontalAlignment = if (left) Alignment.Start else Alignment.End,
) {
if (lyrics != null) {
SaverLyrics(state, lyrics, left, Modifier.fillMaxWidth().padding(bottom = MusyxTheme.space.xl))
}
Caption(state, track, left, Modifier.fillMaxWidth())
}
}
} }
} }
} }
@@ -235,7 +279,7 @@ private fun Caption(state: AppState, track: Track, left: Boolean, modifier: Modi
val p = state.playback.state val p = state.playback.state
val fraction = if (p.durationMs > 0) state.playback.positionMs.toFloat() / p.durationMs else 0f val fraction = if (p.durationMs > 0) state.playback.positionMs.toFloat() / p.durationMs else 0f
Column( Column(
modifier.width(560.dp), modifier,
horizontalAlignment = if (left) Alignment.Start else Alignment.End, horizontalAlignment = if (left) Alignment.Start else Alignment.End,
verticalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp),
) { ) {
@@ -257,3 +301,39 @@ private fun Caption(state: AppState, track: Track, left: Boolean, modifier: Modi
} }
} }
} }
/**
* The line being sung, large, between the one before and the one to come. Plain lyrics can't
* know the line, so all three are the same size and only roughly where the song is. The block
* is anchored at its foot and the next line's slot is always kept, so the lines sit at the same
* distance above the song name whatever they say.
*/
@Composable
private fun SaverLyrics(state: AppState, lyrics: Lyrics, left: Boolean, modifier: Modifier) {
val glance = lyrics.glance(state.playback.positionMs, state.playback.state.durationMs) ?: return
val type = MusyxTheme.type
val align = if (left) TextAlign.Start else TextAlign.End
val shadow = Shadow(Color.Black.copy(alpha = 0.7f), Offset(0f, 2f), blurRadius = 12f)
val side = type.section.copy(shadow = shadow)
val now = if (lyrics.synced) type.displayM.copy(shadow = shadow) else side
AnimatedContent(
glance,
modifier,
transitionSpec = {
fadeIn(tween(LYRIC_FADE_MS)) togetherWith fadeOut(tween(LYRIC_FADE_MS)) using SizeTransform(clip = false)
},
contentAlignment = if (left) Alignment.BottomStart else Alignment.BottomEnd,
label = "lyric",
) { g ->
Column(
Modifier.fillMaxWidth(),
horizontalAlignment = if (left) Alignment.Start else Alignment.End,
verticalArrangement = Arrangement.spacedBy(14.dp),
) {
g.previous?.let { Text(it.ifBlank { "♪" }, style = side, color = Color.White.copy(alpha = 0.45f), textAlign = align, maxLines = 1, overflow = TextOverflow.Ellipsis) }
g.current?.let { Text(it.ifBlank { "♪" }, style = now, color = Color.White, textAlign = align, maxLines = 2, overflow = TextOverflow.Ellipsis) }
val alpha = if (g.current == null || !lyrics.synced) 0.85f else 0.6f
Text(g.next?.ifBlank { "♪" }.orEmpty(), style = side, color = Color.White.copy(alpha = alpha), textAlign = align, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
@@ -1,4 +1,4 @@
// Settings: account, streaming quality, appearance, font size, language, storage. // Settings: account, streaming quality, appearance, font size, language, screen saver, storage.
package it.panov.musyx.tv.ui.screens package it.panov.musyx.tv.ui.screens
import androidx.compose.foundation.background import androidx.compose.foundation.background
@@ -108,6 +108,19 @@ fun SettingsScreen(state: AppState, entry: FocusEntry) {
} }
} }
} }
item(key = "screen-saver") {
Section(stringResource(R.string.settings_screen_saver)) {
ChoiceRow {
Chip(stringResource(R.string.saver_photos), !settings.saverLyrics, { state.setSaverLyrics(false) })
Chip(stringResource(R.string.saver_photos_lyrics), settings.saverLyrics, { state.setSaverLyrics(true) })
}
Text(
stringResource(if (settings.saverLyrics) R.string.saver_photos_lyrics_detail else R.string.saver_photos_detail),
style = MusyxTheme.type.meta,
color = MusyxTheme.colors.muted,
)
}
}
item(key = "storage") { item(key = "storage") {
Section(stringResource(R.string.settings_storage)) { Section(stringResource(R.string.settings_storage)) {
Text(stringResource(R.string.settings_storage_detail), style = MusyxTheme.type.meta, color = MusyxTheme.colors.muted) Text(stringResource(R.string.settings_storage_detail), style = MusyxTheme.type.meta, color = MusyxTheme.colors.muted)
+5
View File
@@ -191,6 +191,11 @@
<string name="font_size_medium">Средний</string> <string name="font_size_medium">Средний</string>
<string name="font_size_large">Крупный</string> <string name="font_size_large">Крупный</string>
<string name="settings_language">Язык</string> <string name="settings_language">Язык</string>
<string name="settings_screen_saver">Заставка</string>
<string name="saver_photos">Фото</string>
<string name="saver_photos_lyrics">Фото и текст</string>
<string name="saver_photos_detail">Пока играет музыка и пульт не трогают, по экрану плывут фото исполнителя и название трека.</string>
<string name="saver_photos_lyrics_detail">Вместе с ними — текст песни: строка, которая звучит сейчас, если текст синхронизирован, иначе примерно то место, до которого дошла песня.</string>
<string name="settings_storage">Хранилище</string> <string name="settings_storage">Хранилище</string>
<string name="settings_storage_detail">Обложки хранятся на диске, чтобы страницы открывались мгновенно. Очистка освободит место, а обложки снова загрузятся по мере просмотра.</string> <string name="settings_storage_detail">Обложки хранятся на диске, чтобы страницы открывались мгновенно. Очистка освободит место, а обложки снова загрузятся по мере просмотра.</string>
<string name="settings_version">Musyx %1$s · неофициальный клиент Яндекс Музыки</string> <string name="settings_version">Musyx %1$s · неофициальный клиент Яндекс Музыки</string>
+5
View File
@@ -204,6 +204,11 @@
<string name="font_size_medium">Medium</string> <string name="font_size_medium">Medium</string>
<string name="font_size_large">Large</string> <string name="font_size_large">Large</string>
<string name="settings_language">Language</string> <string name="settings_language">Language</string>
<string name="settings_screen_saver">Screen saver</string>
<string name="saver_photos">Photos</string>
<string name="saver_photos_lyrics">Photos and lyrics</string>
<string name="saver_photos_detail">While music plays and the remote rests, photos of the artist drift by with what\'s playing.</string>
<string name="saver_photos_lyrics_detail">The lyrics come along too: the line being sung when they\'re synced, else the words about as far in as the song is.</string>
<string name="settings_storage">Storage</string> <string name="settings_storage">Storage</string>
<string name="settings_storage_detail">Covers are kept on disk so pages open instantly next time. Clearing them frees the space; they download again as you browse.</string> <string name="settings_storage_detail">Covers are kept on disk so pages open instantly next time. Clearing them frees the space; they download again as you browse.</string>
<string name="settings_version">Musyx %1$s · unofficial Yandex Music client</string> <string name="settings_version">Musyx %1$s · unofficial Yandex Music client</string>
@@ -367,6 +367,28 @@ class ApiTest {
assertNull(Lyrics.parseStamp("00:01.1234")) assertNull(Lyrics.parseStamp("00:01.1234"))
} }
@Test
fun syncedGlanceIsTheSungLineBetweenItsNeighbours() {
val l = Lyrics.fromLrc("[00:10.00]one\n[00:20.00]\n[00:30.00]three", emptyList())
assertEquals(Lyrics.Glance(null, null, "one"), l.glance(5_000, 60_000))
assertEquals(Lyrics.Glance(null, "one", ""), l.glance(10_000, 60_000))
assertEquals(Lyrics.Glance("one", "", "three"), l.glance(25_000, 60_000))
assertEquals(Lyrics.Glance("", "three", null), l.glance(59_000, 60_000))
assertNull(Lyrics(emptyList(), synced = true, writers = emptyList()).glance(0, 60_000))
}
@Test
fun plainGlanceFollowsTheSongsShareOfTheWords() {
val l = Lyrics.fromText("a\n\nb\nc\nd", emptyList())
assertEquals(Lyrics.Glance(null, "a", "b"), l.glance(0, 100_000))
assertEquals(Lyrics.Glance("a", "b", "c"), l.glance(25_000, 100_000))
assertEquals(Lyrics.Glance("c", "d", null), l.glance(99_000, 100_000))
// Past the end, or with the length unknown, it doesn't guess.
assertEquals(Lyrics.Glance("c", "d", null), l.glance(150_000, 100_000))
assertNull(l.glance(10_000, 0))
assertNull(Lyrics.fromText(" \n", emptyList()).glance(0, 100_000))
}
// ---- LRCLIB ---- // ---- LRCLIB ----
private fun record(duration: Double, synced: String? = null, plain: String? = null, instrumental: Boolean = false) = private fun record(duration: Double, synced: String? = null, plain: String? = null, instrumental: Boolean = false) =