mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
fix: don't show the highlight as chapter for the whole remaining video
This commit is contained in:
parent
c4983aa00d
commit
c30def8c16
@ -10,5 +10,12 @@ data class ChapterSegment(
|
||||
val image: String = "",
|
||||
val start: Long,
|
||||
// Used only for video highlights
|
||||
@Transient var drawable: Drawable? = null
|
||||
)
|
||||
@Transient var highlightDrawable: Drawable? = null
|
||||
) {
|
||||
companion object {
|
||||
/**
|
||||
* Length to show for a highlight in seconds
|
||||
*/
|
||||
const val HIGHLIGHT_LENGTH = 10L
|
||||
}
|
||||
}
|
||||
|
@ -533,7 +533,16 @@ object PlayerHelper {
|
||||
*/
|
||||
fun getCurrentChapterIndex(exoPlayer: ExoPlayer, chapters: List<ChapterSegment>): Int? {
|
||||
val currentPosition = exoPlayer.currentPosition / 1000
|
||||
return chapters.indexOfLast { currentPosition >= it.start }.takeIf { it >= 0 }
|
||||
return chapters
|
||||
.filter {
|
||||
it.highlightDrawable == null ||
|
||||
// remove the video highlight if it's already longer ago than [ChapterSegment.HIGHLIGHT_LENGTH],
|
||||
// otherwise the SponsorBlock highlight would be shown from its starting point to the end
|
||||
(currentPosition - it.start) < ChapterSegment.HIGHLIGHT_LENGTH
|
||||
}
|
||||
.sortedBy { it.start }
|
||||
.indexOfLast { currentPosition >= it.start }
|
||||
.takeIf { it >= 0 }
|
||||
}
|
||||
|
||||
fun getPosition(videoId: String, duration: Long?): Long? {
|
||||
|
@ -28,16 +28,21 @@ class ChaptersAdapter(
|
||||
override fun onBindViewHolder(holder: ChaptersViewHolder, position: Int) {
|
||||
val chapter = chapters[position]
|
||||
holder.binding.apply {
|
||||
if (chapter.drawable != null) {
|
||||
chapterImage.setImageDrawable(chapter.drawable)
|
||||
if (chapter.highlightDrawable != null) {
|
||||
chapterImage.setImageDrawable(chapter.highlightDrawable)
|
||||
} else {
|
||||
ImageHelper.loadImage(chapter.image, chapterImage)
|
||||
}
|
||||
chapterTitle.text = chapter.title
|
||||
timeStamp.text = DateUtils.formatElapsedTime(chapter.start)
|
||||
|
||||
val chapterEnd = chapters.getOrNull(position + 1)?.start
|
||||
?: (exoPlayer.duration / 1000)
|
||||
val playerDurationSeconds = exoPlayer.duration / 1000
|
||||
val chapterEnd = if (chapter.highlightDrawable == null) {
|
||||
chapters.getOrNull(position + 1)?.start ?: playerDurationSeconds
|
||||
} else {
|
||||
// the duration for chapters is hardcoded, since it's not provided by the SB API
|
||||
minOf(chapter.start + ChapterSegment.HIGHLIGHT_LENGTH, playerDurationSeconds)
|
||||
}
|
||||
val durationSpan = chapterEnd - chapter.start
|
||||
duration.text = root.context.getString(
|
||||
R.string.duration_span,
|
||||
|
@ -1175,7 +1175,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
val highlightChapter = ChapterSegment(
|
||||
title = getString(R.string.chapters_videoHighlight),
|
||||
start = highlight.segmentStartAndEnd.first.toLong(),
|
||||
drawable = frame?.toDrawable(requireContext().resources)
|
||||
highlightDrawable = frame?.toDrawable(requireContext().resources)
|
||||
)
|
||||
chapters.add(highlightChapter)
|
||||
chapters.sortBy { it.start }
|
||||
|
Loading…
x
Reference in New Issue
Block a user