fix: no chapters shown if video highlight is the only chapter

This commit is contained in:
Bnyro 2024-09-25 13:59:15 +02:00
parent 5dc0e98054
commit aa2fd8384d
2 changed files with 19 additions and 13 deletions

View File

@ -17,6 +17,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.PowerManager
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.PixelCopy
@ -1103,6 +1104,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
// init the chapters recyclerview
chaptersViewModel.chaptersLiveData.value = streams.chapters
chaptersViewModel.chaptersLiveData.observe(viewLifecycleOwner) {
binding.player.setCurrentChapterName()
}
if (PlayerHelper.relatedStreamsEnabled) {
val relatedLayoutManager = binding.relatedRecView.layoutManager as LinearLayoutManager
@ -1197,10 +1201,6 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
chaptersViewModel.chaptersLiveData.postValue(
chaptersViewModel.chapters.plus(highlightChapter).sortedBy { it.start }
)
withContext(Dispatchers.Main) {
binding.player.setCurrentChapterName()
}
}
private fun getSubtitleConfigs(): List<SubtitleConfiguration> = streams.subtitles.map {
@ -1478,12 +1478,15 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
listener = null
)
} else {
baseBottomSheet.setSimpleItems(audioLanguages, preselectedItem = audioLanguagesAndRoleFlags.firstOrNull {
val format = viewModel.player.audioFormat
format?.language == it.first && format?.roleFlags == it.second
}?.let {
PlayerHelper.getAudioTrackNameFromFormat(context, it)
},) { index ->
baseBottomSheet.setSimpleItems(
audioLanguages,
preselectedItem = audioLanguagesAndRoleFlags.firstOrNull {
val format = viewModel.player.audioFormat
format?.language == it.first && format?.roleFlags == it.second
}?.let {
PlayerHelper.getAudioTrackNameFromFormat(context, it)
},
) { index ->
val selectedAudioFormat = audioLanguagesAndRoleFlags[index]
viewModel.trackSelector.updateParameters {
setPreferredAudioLanguage(selectedAudioFormat.first)

View File

@ -250,7 +250,11 @@ abstract class CustomExoPlayerView(
}
}
// set the name of the video chapter in the exoPlayerView
/**
* Set the name of the video chapter in the [CustomExoPlayerView]
* @param forceUpdate Update the current chapter name no matter if the seek bar is scrubbed
* @param enqueueNew set a timeout to automatically repeat this function again in 100ms
*/
fun setCurrentChapterName(forceUpdate: Boolean = false, enqueueNew: Boolean = true) {
val player = player ?: return
val chapters = chaptersViewModel.chapters
@ -267,8 +271,7 @@ abstract class CustomExoPlayerView(
if (scrubbingTimeBar && !forceUpdate) return
val currentIndex = PlayerHelper.getCurrentChapterIndex(player.currentPosition, chapters)
val newChapterName = currentIndex?.let { chapters[it].title.trim() }
?: context.getString(R.string.no_chapter)
val newChapterName = currentIndex?.let { chapters[it].title.trim() }.orEmpty()
chaptersViewModel.currentChapterIndex.updateIfChanged(currentIndex ?: return)
// change the chapter name textView text to the chapterName