namlu
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2018
02:33 AM
Recognising overlapping chapter times
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:
So I've done this to check whether or not I'm in the current chapter:
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:
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):
Not sure what I'm doing wrong. Can anyone advise?
Cheers
"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
1 REPLY 1
namlu
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2018
04:06 PM
Re: Recognising overlapping chapter times
Was able to fix by checking for the chapters in descending order rather than ascending. This removed the complexity of having to get the start time for the upcoming and comparing it to the current video time.
function chapterForCurrentVideoPosition(unused = invalid) as Object
videoNode = m.top.videoContentNode
if videoNode = invalid
return invalid
end if
descChapters = videoNode.chapters
descChapters.sortBy("start", "r")
for each chapter in descChapters
if isInChapter(chapter)
return chapter
end if
end for
return invalid
end function