make chapters selectable

This commit is contained in:
Christian Schabesberger 2024-09-06 14:07:02 +02:00
parent 79f8719ac3
commit 09f32dd893
5 changed files with 15 additions and 7 deletions

View File

@ -95,6 +95,7 @@ interface NewPlayer {
fun movePlaylistItem(fromIndex: Int, toIndex: Int)
fun removePlaylistItem(index: Int)
fun playStream(item: String, playMode: PlayMode)
fun selectChapter(index: Int)
fun playStream(item: String, streamVariant: String, playMode: PlayMode)
data class Builder(val app: Application, val repository: MediaRepository) {
@ -208,7 +209,6 @@ class NewPlayerImpl(
override val currentChapters: StateFlow<List<Chapter>> = mutableCurrentChapter.asStateFlow()
init {
println("gurken init")
internalPlayer.addListener(object : Player.Listener {
override fun onPlayerError(error: PlaybackException) {
launchJobAndCollectError {
@ -339,6 +339,14 @@ class NewPlayerImpl(
}
}
override fun selectChapter(index: Int) {
val chapters = currentChapters.value
assert(index in 0..<chapters.size) {
throw NewPlayerException("Chapter selection out of bound: seleced chapter index: $index, available chapters: ${chapters.size}")
}
val chapter = chapters[index]
currentPosition = chapter.chapterStartInMs
}
private fun internalPlayStream(mediaItem: MediaItem, playMode: PlayMode) {
if (internalPlayer.playbackState == Player.STATE_IDLE) {

View File

@ -56,7 +56,7 @@ interface VideoPlayerViewModel {
fun volumeChange(changeRate: Float)
fun openStreamSelection(selectChapter: Boolean, embeddedUiConfig: EmbeddedUiConfig)
fun closeStreamSelection()
fun chapterSelected(chapter: Chapter)
fun chapterSelected(chapterId: Int)
fun streamSelected(streamId: Int)
fun cycleRepeatMode()
fun toggleShuffle()

View File

@ -463,8 +463,8 @@ class VideoPlayerViewModelImpl @Inject constructor(
updateUiMode(UIModeState.FULLSCREEN_VIDEO)
}
override fun chapterSelected(chapter: Chapter) {
println("gurken chapter selectd: $chapter")
override fun chapterSelected(chapterId: Int) {
newPlayer?.selectChapter(chapterId)
}
override fun streamSelected(streamId: Int) {

View File

@ -84,8 +84,8 @@ open class VideoPlayerViewModelDummy : VideoPlayerViewModel {
println("dummy impl")
}
override fun chapterSelected(chapter: Chapter) {
println("dummp impl chapter selected: $chapter")
override fun chapterSelected(chapterId: Int) {
println("dummp impl chapter selected: $chapterId")
}
override fun streamSelected(streamId: Int) {

View File

@ -100,7 +100,7 @@ fun StreamSelectUI(
chapterStartInMs = chapter.chapterStartInMs,
thumbnail = chapter.thumbnail,
onClicked = {
viewModel.chapterSelected(chapter)
viewModel.chapterSelected(chapterIndex)
},
isCurrentChapter = isActiveChapter(
chapterIndex,