Tweak synchronized lyrics related code in Lyrics

This commit is contained in:
vfsfitvnm 2022-08-07 12:53:39 +02:00
parent 073a50b34c
commit 6a556e8b56

View file

@ -241,19 +241,19 @@ fun Lyrics(
val synchronizedLyrics = remember(lyrics) {
SynchronizedLyrics(KuGou.Lyrics(lyrics).sentences) {
player.currentPosition
player.currentPosition + 50
}
}
val lazyListState = rememberLazyListState(synchronizedLyrics.index, with (density) { size.roundToPx() } / 6)
LaunchedEffect(synchronizedLyrics) {
val center = with (density) { size.roundToPx() } / 6
while (isActive) {
delay(50)
if (synchronizedLyrics.update()) {
synchronizedLyrics.sentences.getOrNull(synchronizedLyrics.index)?.first?.let {
lazyListState.animateScrollToItem(synchronizedLyrics.index, with (density) { size.roundToPx() } / 6)
}
lazyListState.animateScrollToItem(synchronizedLyrics.index, center)
}
}
}