Add synchronized lyrics (#126)

This commit is contained in:
vfsfitvnm
2022-08-03 21:08:40 +02:00
parent 4a16bc6960
commit 194864bcb4
16 changed files with 866 additions and 38 deletions

View File

@@ -0,0 +1,33 @@
package it.vfsfitvnm.vimusic.utils
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import it.vfsfitvnm.synchronizedlyrics.parseSentences
class SynchronizedLyrics(text: String, private val positionProvider: () -> Long) {
val sentences = parseSentences(text)
var index by mutableStateOf(currentIndex)
private set
private val currentIndex: Int
get() {
var index = -1
for (item in sentences) {
if (item.first >= positionProvider()) break
index++
}
return index
}
fun update(): Boolean {
val newIndex = currentIndex
return if (newIndex != index) {
index = newIndex
true
} else {
false
}
}
}