make chapters selectable
This commit is contained in:
parent
79f8719ac3
commit
09f32dd893
|
@ -95,6 +95,7 @@ interface NewPlayer {
|
||||||
fun movePlaylistItem(fromIndex: Int, toIndex: Int)
|
fun movePlaylistItem(fromIndex: Int, toIndex: Int)
|
||||||
fun removePlaylistItem(index: Int)
|
fun removePlaylistItem(index: Int)
|
||||||
fun playStream(item: String, playMode: PlayMode)
|
fun playStream(item: String, playMode: PlayMode)
|
||||||
|
fun selectChapter(index: Int)
|
||||||
fun playStream(item: String, streamVariant: String, playMode: PlayMode)
|
fun playStream(item: String, streamVariant: String, playMode: PlayMode)
|
||||||
|
|
||||||
data class Builder(val app: Application, val repository: MediaRepository) {
|
data class Builder(val app: Application, val repository: MediaRepository) {
|
||||||
|
@ -208,7 +209,6 @@ class NewPlayerImpl(
|
||||||
override val currentChapters: StateFlow<List<Chapter>> = mutableCurrentChapter.asStateFlow()
|
override val currentChapters: StateFlow<List<Chapter>> = mutableCurrentChapter.asStateFlow()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
println("gurken init")
|
|
||||||
internalPlayer.addListener(object : Player.Listener {
|
internalPlayer.addListener(object : Player.Listener {
|
||||||
override fun onPlayerError(error: PlaybackException) {
|
override fun onPlayerError(error: PlaybackException) {
|
||||||
launchJobAndCollectError {
|
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) {
|
private fun internalPlayStream(mediaItem: MediaItem, playMode: PlayMode) {
|
||||||
if (internalPlayer.playbackState == Player.STATE_IDLE) {
|
if (internalPlayer.playbackState == Player.STATE_IDLE) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ interface VideoPlayerViewModel {
|
||||||
fun volumeChange(changeRate: Float)
|
fun volumeChange(changeRate: Float)
|
||||||
fun openStreamSelection(selectChapter: Boolean, embeddedUiConfig: EmbeddedUiConfig)
|
fun openStreamSelection(selectChapter: Boolean, embeddedUiConfig: EmbeddedUiConfig)
|
||||||
fun closeStreamSelection()
|
fun closeStreamSelection()
|
||||||
fun chapterSelected(chapter: Chapter)
|
fun chapterSelected(chapterId: Int)
|
||||||
fun streamSelected(streamId: Int)
|
fun streamSelected(streamId: Int)
|
||||||
fun cycleRepeatMode()
|
fun cycleRepeatMode()
|
||||||
fun toggleShuffle()
|
fun toggleShuffle()
|
||||||
|
|
|
@ -463,8 +463,8 @@ class VideoPlayerViewModelImpl @Inject constructor(
|
||||||
updateUiMode(UIModeState.FULLSCREEN_VIDEO)
|
updateUiMode(UIModeState.FULLSCREEN_VIDEO)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterSelected(chapter: Chapter) {
|
override fun chapterSelected(chapterId: Int) {
|
||||||
println("gurken chapter selectd: $chapter")
|
newPlayer?.selectChapter(chapterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun streamSelected(streamId: Int) {
|
override fun streamSelected(streamId: Int) {
|
||||||
|
|
|
@ -84,8 +84,8 @@ open class VideoPlayerViewModelDummy : VideoPlayerViewModel {
|
||||||
println("dummy impl")
|
println("dummy impl")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterSelected(chapter: Chapter) {
|
override fun chapterSelected(chapterId: Int) {
|
||||||
println("dummp impl chapter selected: $chapter")
|
println("dummp impl chapter selected: $chapterId")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun streamSelected(streamId: Int) {
|
override fun streamSelected(streamId: Int) {
|
||||||
|
|
|
@ -100,7 +100,7 @@ fun StreamSelectUI(
|
||||||
chapterStartInMs = chapter.chapterStartInMs,
|
chapterStartInMs = chapter.chapterStartInMs,
|
||||||
thumbnail = chapter.thumbnail,
|
thumbnail = chapter.thumbnail,
|
||||||
onClicked = {
|
onClicked = {
|
||||||
viewModel.chapterSelected(chapter)
|
viewModel.chapterSelected(chapterIndex)
|
||||||
},
|
},
|
||||||
isCurrentChapter = isActiveChapter(
|
isCurrentChapter = isActiveChapter(
|
||||||
chapterIndex,
|
chapterIndex,
|
||||||
|
|
Loading…
Reference in New Issue