refresh borders of sentences

This commit is contained in:
2026-08-30 11:57:23 +08:00
parent 7cdc637527
commit 0b85a2ed57
3 changed files with 50 additions and 3 deletions

View File

@@ -141,6 +141,28 @@ class OralTrainerController internal constructor(
loadItems(listOf(item))
}
/**
* Replaces sentences without preparing/reloading media, preserving playback
* position and state so a background boundary refresh can apply immediately.
*/
fun updateSentences(mediaId: String, sentences: List<SentenceBoundary>): Boolean {
val index = mediaItems.indexOfFirst { it.id == mediaId }
if (index < 0) {
return false
}
val updatedItem = mediaItems[index].copy(sentences = sentences)
if (mediaItems[index] == updatedItem) {
return true
}
mediaItems[index] = updatedItem
if (index == player.currentMediaItemIndex) {
listeners.forEach { it.onMediaChanged(updatedItem) }
notifySentenceIfChanged(force = true)
notifySnapshot()
}
return true
}
fun play() {
player.play()
}

View File

@@ -111,6 +111,7 @@ class SentenceBoundaryApi internal constructor(
connection.requestMethod = "GET"
connection.connectTimeout = config.connectTimeoutMs
connection.readTimeout = config.readTimeoutMs
connection.useCaches = false
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("User-Agent", config.userAgent)
val statusCode = connection.responseCode