add chapters for full screen mode

This commit is contained in:
Bnyro 2022-07-09 18:51:09 +02:00
parent ff6d738580
commit b38cb661d0
5 changed files with 42 additions and 3 deletions

View File

@ -27,7 +27,7 @@ class ChaptersAdapter(
chapterTitle.text = chapter.title
root.setOnClickListener {
val chapterStart = chapter.start!!.toLong() * 1000 // s -> ms
val chapterStart = chapter.start!! * 1000 // s -> ms
exoPlayer.seekTo(chapterStart)
}
}

View File

@ -335,6 +335,7 @@ class PlayerFragment : Fragment() {
binding.linLayout.visibility = View.GONE
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen_exit)
playerBinding.exoTitle.visibility = View.VISIBLE
playerBinding.chapterName.visibility = View.VISIBLE
val mainActivity = activity as MainActivity
val fullscreenOrientationPref = PreferenceHelper
@ -372,6 +373,7 @@ class PlayerFragment : Fragment() {
binding.linLayout.visibility = View.VISIBLE
playerBinding.fullscreen.setImageResource(R.drawable.ic_fullscreen)
playerBinding.exoTitle.visibility = View.INVISIBLE
playerBinding.chapterName.visibility = View.INVISIBLE
scaleControls(1F)
@ -938,10 +940,31 @@ class PlayerFragment : Fragment() {
private fun initializeChapters(chapters: List<ChapterSegment>) {
if (chapters.isNotEmpty()) {
// enable chapters in the video description
binding.chaptersRecView.layoutManager =
LinearLayoutManager(this.context, LinearLayoutManager.HORIZONTAL, false)
LinearLayoutManager(
context,
LinearLayoutManager.HORIZONTAL,
false
)
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
binding.chaptersRecView.visibility = View.VISIBLE
// enable chapters in the player
val titles = mutableListOf<String>()
chapters.forEach {
titles += it.title!!
}
playerBinding.chapterName.text = chapters[0].title
playerBinding.chapterName.setOnClickListener{
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.chapters)
.setItems(titles.toTypedArray()) { _, index ->
val position = chapters[index].start!! * 1000
exoPlayer.seekTo(position)
}
.show()
}
}
}

View File

@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
data class ChapterSegment(
var title: String?,
var image: String?,
var start: Int?
var start: Long?
) {
constructor() : this("", "", -1)
}

View File

@ -136,6 +136,21 @@
android:id="@id/exo_duration"
style="@style/ExoStyledControls.TimeText.Duration" />
<LinearLayout
android:id="@+id/chapter_fullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/chapter_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:textSize="16sp"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout

View File

@ -229,4 +229,5 @@
<string name="twitter">Twitter</string>
<string name="turnInternetOn">Please connect to the internet by turning on WiFi or mobile data.</string>
<string name="open">Open …</string>
<string name="chapters">Chapters</string>
</resources>