Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading