fix autoplay crash

This commit is contained in:
Bnyro 2022-08-21 10:05:40 +02:00
parent ef816aa53e
commit 676d356dca

View File

@ -1294,42 +1294,44 @@ class PlayerFragment : BaseFragment() {
}
private fun initializeChapters() {
if (chapters.isNotEmpty()) {
// enable chapters in the video description
binding.chaptersRecView.layoutManager =
LinearLayoutManager(
context,
LinearLayoutManager.HORIZONTAL,
false
)
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
binding.chaptersRecView.visibility = View.VISIBLE
if (chapters.isEmpty()) return
// enable chapters in the video description
binding.chaptersRecView.layoutManager =
LinearLayoutManager(
context,
LinearLayoutManager.HORIZONTAL,
false
)
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
binding.chaptersRecView.visibility = View.VISIBLE
// enable the chapters dialog in the player
val titles = mutableListOf<String>()
chapters.forEach {
titles += it.title!!
}
playerBinding.chapterLL.visibility = View.VISIBLE
playerBinding.chapterLL.setOnClickListener {
if (viewModel.isFullscreen.value!!) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.chapters)
.setItems(titles.toTypedArray()) { _, index ->
val position = chapters[index].start!! * 1000
exoPlayer.seekTo(position)
}
.show()
} else {
toggleDescription()
}
}
setCurrentChapterName()
// enable the chapters dialog in the player
val titles = mutableListOf<String>()
chapters.forEach {
titles += it.title!!
}
playerBinding.chapterLL.visibility = View.VISIBLE
playerBinding.chapterLL.setOnClickListener {
if (viewModel.isFullscreen.value!!) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.chapters)
.setItems(titles.toTypedArray()) { _, index ->
val position = chapters[index].start!! * 1000
exoPlayer.seekTo(position)
}
.show()
} else {
toggleDescription()
}
}
setCurrentChapterName()
}
// set the name of the video chapter in the exoPlayerView
private fun setCurrentChapterName() {
// return if chapters are ampty to avoid crashes
if (chapters.isEmpty()) return
// call the function again in 100ms
exoPlayerView.postDelayed(this::setCurrentChapterName, 100)