I need to handle cases when the chapter times overlap one another so that I can display the correct text for that chapter. For example, I have the following chapter array:
"chapters": Array[3][
{
"name": "Recap & Intro",
"start": 0,
"end": 145000,
"skippable": true,
"canSkipOnAutoplay": true
},
{
"name": "Intro",
"start": 53000,
"end": 145000,
"skippable": true
},
{
"name": "Credits",
"start": 3498000,
"skippable": true,
"canSkipOnAutoplay": true,
"showUpNext": true
}
],
So I've done this to check whether or not I'm in the current chapter:
function isInChapter(chapter as Object) as Boolean
return m.top.videoPosition >= chapter.start and m.top.videoPosition < chapter.end
end function
Unfortunately, this doesn't account for the above case where the Recap & Intro overlap time with the Intro.
I've been trying something like this:
function chapterForCurrentVideoPosition(unused = invalid) as Object
videoNode = m.top.videoContentNode
if videoNode = invalid
return invalid
end if
for i = 0 to (videoNode.chapters.count() - 1)
chapter = videoNode.chapters[i]
if isInChapter(chapter)
if m.top.videoPosition >= videoNode.chapters[i + 1].start
exit for
end if
return chapter
end if
end for
return invalid
end function
But I end up with a strange loop case where the chapters become out of whack around position = 53, which is the start of Intro.
The debug logs look something like this (Note: I removed the debug statements from the above code for simplification):
]
VideoSkipChapterButton: ---for loop count down: 0
VideoSkipChapterButton: ===chapter.start: 0
VideoSkipChapterButton: ===chapter.end: 145
VideoSkipChapterButton: Is in chapter, returning Recap & Intro.
VideoSkipChapterButton: ===chapter.end: 145
.start: 53
VideoPlayerScreen: updateSkipChapterShouldHideIfChapterChanged
VideoPlayerScreen: updateCurrentChapter
]
VideoSkipChapterButton: ---for loop count down: 0
VideoSkipChapterButton: ===chapter.start: 0
VideoSkipChapterButton: ===chapter.end: 145
VideoSkipChapterButton: Is in chapter, returning Recap & Intro.
VideoSkipChapterButton: ===chapter.end: 145
.start: 53
]
VideoSkipChapterButton: ---for loop count down: 0
VideoSkipChapterButton: ===chapter.start: 0
VideoSkipChapterButton: ===chapter.end: 145
VideoSkipChapterButton: Is in chapter, returning Recap & Intro.
VideoSkipChapterButton: ===chapter.end: 145
.start: 53
VideoPlayerScreen: onVideoPositionChanged: 53.09
]
VideoSkipChapterButton: ---for loop count down: 0
VideoSkipChapterButton: ===chapter.start: 0
VideoSkipChapterButton: ===chapter.end: 145
VideoSkipChapterButton: Is in chapter, returning Recap & Intro.
VideoSkipChapterButton: ===chapter.end: 145
.start: 53
VideoSkipChapterButton: ===i = 0
VideoSkipChapterButton: Could not find a chapter.
VideoPlayerScreen: ---shouldShowSkipChapterButton: false
VideoPlayerScreen: ---m.settingsGroup.visible = false
VideoPlayerScreen: ---m.skipChapterShouldHide = true
]
VideoSkipChapterButton: ---for loop count down: 0
VideoSkipChapterButton: ===chapter.start: 0
VideoSkipChapterButton: ===chapter.end: 145
VideoSkipChapterButton: Is in chapter, returning Recap & Intro.
VideoSkipChapterButton: ===chapter.end: 145
.start: 53
VideoSkipChapterButton: ===i = 0
VideoSkipChapterButton: Could not find a chapter.
VideoPlayerScreen: updateSkipChapterShouldHideIfChapterChanged
VideoPlayerScreen: updateCurrentChapter
]
VideoSkipChapterButton: ---for loop count down: 0
VideoSkipChapterButton: ===chapter.start: 0
VideoSkipChapterButton: ===chapter.end: 145
VideoSkipChapterButton: Is in chapter, returning Recap & Intro.
VideoSkipChapterButton: ===chapter.end: 145
.start: 53
VideoSkipChapterButton: ===i = 0
VideoSkipChapterButton: Could not find a chapter.
Not sure what I'm doing wrong. Can anyone advise?
Cheers