Fix interpretation of times located in a hole in the video segments

pull/248/head
ElementalAlchemist 3 years ago committed by Mike Lang
parent 5a9f4502c2
commit e2487f61c0

@ -10,6 +10,7 @@ var globalEndTimeString = "";
var globalPlayer = null; var globalPlayer = null;
Hls.DefaultConfig.maxBufferHole = 600; Hls.DefaultConfig.maxBufferHole = 600;
Hls.DefaultConfig.debug = true;
const VIDEO_FRAMES_PER_SECOND = 30; const VIDEO_FRAMES_PER_SECOND = 30;

@ -410,9 +410,10 @@ async function initializeVideoInfo() {
rangeEndField.value = videoHumanTimeFromWubloaderTime(globalEndTimeString); rangeEndField.value = videoHumanTimeFromWubloaderTime(globalEndTimeString);
} }
} }
videoElement.removeEventListener("durationchange", handleInitialSetupForDuration); rangeDataUpdated();
videoElement.removeEventListener("loadedmetadata", handleInitialSetupForDuration);
}; };
videoElement.addEventListener("durationchange", handleInitialSetupForDuration); videoElement.addEventListener("loadedmetadata", handleInitialSetupForDuration);
videoElement.addEventListener("durationchange", (_event) => { videoElement.addEventListener("durationchange", (_event) => {
// Every time this is updated, we need to update based on the new video duration // Every time this is updated, we need to update based on the new video duration
rangeDataUpdated(); rangeDataUpdated();
@ -986,12 +987,26 @@ function setCurrentRangeEndToVideoTime() {
function videoPlayerTimeFromWubloaderTime(wubloaderTime) { function videoPlayerTimeFromWubloaderTime(wubloaderTime) {
const wubloaderDateTime = dateTimeFromWubloaderTime(wubloaderTime); const wubloaderDateTime = dateTimeFromWubloaderTime(wubloaderTime);
const segmentList = getSegmentList(); const segmentList = getSegmentList();
for (const segment of segmentList) { for (let segmentIndex = 0; segmentIndex < segmentList.length - 1; segmentIndex++) {
const segmentStart = DateTime.fromISO(segment.rawProgramDateTime, { zone: "utc" }); const thisSegment = segmentList[segmentIndex];
const segmentEnd = segmentStart.plus({ seconds: segment.duration }); const nextSegment = segmentList[segmentIndex + 1];
if (segmentStart <= wubloaderDateTime && segmentEnd > wubloaderDateTime) { const segmentStartTime = DateTime.fromISO(thisSegment.rawProgramDateTime);
return segment.start + wubloaderDateTime.diff(segmentStart).as("seconds"); const nextSegmentStartTime = DateTime.fromISO(nextSegment.rawProgramDateTime);
} if (segmentStartTime <= wubloaderDateTime && nextSegmentStartTime > wubloaderDateTime) {
let offset = wubloaderDateTime.diff(segmentStartTime).as("seconds");
// If there's a hole in the video and this wubloader time is in the hole, this will end up
// at a random point. We can fix that by capping the offset at the segment duration.
if (offset > thisSegment.duration) {
offset = thisSegment.duration;
}
return thisSegment.start + offset;
}
}
const lastSegment = segmentList[segmentList.length - 1];
const lastSegmentStartTime = DateTime.fromISO(lastSegment.rawProgramDateTime);
const lastSegmentEndTime = lastSegmentStartTime.plus({ seconds: lastSegment.duration });
if (lastSegmentStartTime <= wubloaderDateTime && wubloaderDateTime <= lastSegmentEndTime) {
return segment.start + wubloaderDateTime.diff(lastSegmentStartTime).as("seconds");
} }
return null; return null;
} }

Loading…
Cancel
Save