return android
This commit is contained in:
@@ -21,7 +21,6 @@ import cn.learningpad.oraltrainer.sdk.SentenceBoundaryApiCallback
|
||||
import cn.learningpad.oraltrainer.sdk.SentenceBoundaryApiResult
|
||||
import cn.learningpad.oraltrainer.sdk.TrainingMediaItem
|
||||
import cn.learningpad.oraltrainer.sdk.TrainingVideoSummary
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class MainActivity : Activity() {
|
||||
private lateinit var sdk: OralTrainerSdk
|
||||
@@ -363,43 +362,12 @@ class MainActivity : Activity() {
|
||||
if (!progressBarDragging) {
|
||||
bindings.timeText.text =
|
||||
"${PlaybackFormat.time(snapshot.positionMs)} / ${PlaybackFormat.time(snapshot.durationMs)}"
|
||||
bindings.progressBar.progress = if (controller.config.continuousPlayback) {
|
||||
PlaybackFormat.progress(snapshot)
|
||||
} else {
|
||||
sentenceProgress(snapshot)
|
||||
}
|
||||
bindings.progressBar.progress = PlaybackFormat.progress(snapshot)
|
||||
}
|
||||
bindings.speedText.text = PlaybackFormat.speed(snapshot.playbackSpeed)
|
||||
bindings.statusText.text = PlaybackFormat.status(snapshot)
|
||||
}
|
||||
|
||||
private fun sentenceCount(): Int {
|
||||
return controller.currentTrainingItem()?.sentences?.size?.takeIf { it > 0 }
|
||||
?: screenState.currentSentenceCount
|
||||
}
|
||||
|
||||
private fun sentenceProgress(snapshot: PlaybackSnapshot): Int {
|
||||
val count = sentenceCount()
|
||||
val index = snapshot.sentenceIndex ?: return 0
|
||||
if (count <= 1) return 0
|
||||
return (index * PROGRESS_MAX.toFloat() / (count - 1)).roundToInt()
|
||||
.coerceIn(0, PROGRESS_MAX)
|
||||
}
|
||||
|
||||
private fun sentenceForProgress(progress: Int): Triple<Int, SentenceBoundary?, Int> {
|
||||
val sentences = controller.currentTrainingItem()?.sentences.orEmpty()
|
||||
if (sentences.isEmpty()) {
|
||||
return Triple(0, null, 0)
|
||||
}
|
||||
val index = if (sentences.size == 1) {
|
||||
0
|
||||
} else {
|
||||
(progress.toFloat() / PROGRESS_MAX * (sentences.size - 1)).roundToInt()
|
||||
.coerceIn(0, sentences.lastIndex)
|
||||
}
|
||||
return Triple(index, sentences.getOrNull(index), sentences.size)
|
||||
}
|
||||
|
||||
private fun applySentence(sentence: SentenceBoundary?) {
|
||||
if (!bindings.hasPlayerChrome) return
|
||||
if (sentence == null) {
|
||||
@@ -431,21 +399,9 @@ class MainActivity : Activity() {
|
||||
|
||||
override fun onSeekProgressPreview(progress: Int) {
|
||||
if (!bindings.hasPlayerChrome) return
|
||||
if (controller.config.continuousPlayback) {
|
||||
val duration = controller.snapshot().durationMs
|
||||
bindings.timeText.text =
|
||||
"${PlaybackFormat.time(PlaybackFormat.seekPosition(progress, duration))} / " +
|
||||
PlaybackFormat.time(duration)
|
||||
return
|
||||
}
|
||||
val (index, sentence, count) = sentenceForProgress(progress)
|
||||
val duration = controller.snapshot().durationMs
|
||||
bindings.timeText.text =
|
||||
if (sentence == null) {
|
||||
"暂无句子边界"
|
||||
} else {
|
||||
"第 ${index + 1}/$count 句 " +
|
||||
"${PlaybackFormat.time(sentence.startMs)}-${PlaybackFormat.time(sentence.endMs)}"
|
||||
}
|
||||
"${PlaybackFormat.time(PlaybackFormat.seekPosition(progress, duration))} / ${PlaybackFormat.time(duration)}"
|
||||
}
|
||||
|
||||
override fun onSeekStart() {
|
||||
@@ -454,13 +410,9 @@ class MainActivity : Activity() {
|
||||
|
||||
override fun onSeekStop(progress: Int) {
|
||||
progressBarDragging = false
|
||||
if (controller.config.continuousPlayback) {
|
||||
val duration = controller.snapshot().durationMs
|
||||
controller.seekTo(PlaybackFormat.seekPosition(progress, duration))
|
||||
return
|
||||
}
|
||||
val (_, sentence, _) = sentenceForProgress(progress)
|
||||
sentence?.let { controller.seekTo(it.startMs) }
|
||||
controller.seekTo(
|
||||
PlaybackFormat.seekPosition(progress, controller.snapshot().durationMs),
|
||||
)
|
||||
}
|
||||
|
||||
override fun onContinuousPlaybackChanged(enabled: Boolean) {
|
||||
|
||||
Reference in New Issue
Block a user