Merge pull request #753 from Bnyro/master

fix chapters
This commit is contained in:
Bnyro 2022-07-10 22:05:19 +02:00 committed by GitHub
commit 8a7d8ce32e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 15 deletions

View File

@ -153,12 +153,6 @@ class MainActivity : AppCompatActivity() {
false
}
/**
* don't remove this line
* this prevents reselected items at the bottomNav to be duplicated in the backstack
*/
binding.bottomNav.setOnItemReselectedListener {}
binding.toolbar.title = ThemeHelper.getStyledAppName(this)
binding.toolbar.setNavigationOnClickListener {

View File

@ -1033,22 +1033,29 @@ class PlayerFragment : Fragment() {
// call the function again in 100ms
exoPlayerView.postDelayed(this::setCurrentChapterName, 100)
val currentPosition = exoPlayer.currentPosition
var chapterName: String? = null
val reversedChapters = chapters.toMutableList()
var chapterName = getCurrentChapterName()
// reverse the chapters to start at the end
reversedChapters.reverse()
reversedChapters.forEach {
// check whether the chapter start is greater than the current player position
if (it.start!! * 1000 >= currentPosition) chapterName = it.title
}
// change the chapter name textView text to the chapterName
if (chapterName != null && chapterName != playerBinding.chapterName.text) {
playerBinding.chapterName.text = chapterName
}
}
// get the name of the currently played chapter
private fun getCurrentChapterName(): String? {
val currentPosition = exoPlayer.currentPosition
var chapterName: String? = null
chapters.forEach {
// check whether the chapter start is greater than the current player position
if (currentPosition >= it.start!! * 1000) {
// save chapter title if found
chapterName = it.title
}
}
return chapterName
}
private fun setMediaSource(
subtitle: MutableList<SubtitleConfiguration>,
videoUri: Uri,