mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
fix autoplay crash
This commit is contained in:
parent
ef816aa53e
commit
676d356dca
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user