Correctly handle padding of range times when padding video load time over holes

pull/260/head
ElementalAlchemist 3 years ago committed by Mike Lang
parent 0709082af7
commit e2fb245da2

@ -60,28 +60,43 @@ window.addEventListener("DOMContentLoaded", async (event) => {
} }
} }
const rangesData = [];
const rangeDefinitionsElements = document.getElementById("range-definitions").children;
for (const rangeContainer of rangeDefinitionsElements) {
const rangeStartField = rangeContainer.getElementsByClassName("range-definition-start")[0];
const rangeEndField = rangeContainer.getElementsByClassName("range-definition-end")[0];
const rangeStartTimeString = rangeStartField.value;
const rangeEndTimeString = rangeEndField.value;
const rangeStartTime = dateTimeFromVideoHumanTime(rangeStartTimeString);
const rangeEndTime = dateTimeFromVideoHumanTime(rangeEndTimeString);
rangesData.push({ start: rangeStartTime, end: rangeEndTime });
}
globalStartTimeString = wubloaderTimeFromDateTime(newStart); globalStartTimeString = wubloaderTimeFromDateTime(newStart);
globalEndTimeString = wubloaderTimeFromDateTime(newEnd); globalEndTimeString = wubloaderTimeFromDateTime(newEnd);
updateSegmentPlaylist(); updateSegmentPlaylist();
globalPlayer.once(Hls.Events.LEVEL_LOADED, (_data) => {
let rangeErrorCount = 0; let rangeErrorCount = 0;
for (const rangeContainer of document.getElementById("range-definitions").children) { for (const [rangeIndex, rangeData] of rangesData.entries()) {
const rangeContainer = rangeDefinitionsElements[rangeIndex];
const rangeStartField = rangeContainer.getElementsByClassName("range-definition-start")[0]; const rangeStartField = rangeContainer.getElementsByClassName("range-definition-start")[0];
const rangeEndField = rangeContainer.getElementsByClassName("range-definition-end")[0]; const rangeEndField = rangeContainer.getElementsByClassName("range-definition-end")[0];
const rangeStart = videoPlayerTimeFromVideoHumanTime(rangeStartField.value); if (rangeData.start) {
if (rangeStart === null) { rangeStartField.value = videoHumanTimeFromDateTime(rangeData.start);
rangeErrorCount++;
} else { } else {
rangeStartField.value = videoHumanTimeFromVideoPlayerTime(rangeStart - startAdjustment); rangeErrorCount++;
} }
const rangeEnd = videoPlayerTimeFromVideoHumanTime(rangeEndField.value); if (rangeData.end) {
if (rangeEnd === null) { rangeEndField.value = videoHumanTimeFromDateTime(rangeData.end);
rangeErrorCount++;
} else { } else {
rangeEndField.value = videoHumanTimeFromVideoPlayerTime(rangeEnd - startAdjustment); rangeErrorCount++;
} }
} }
if (rangeErrorCount > 0) { if (rangeErrorCount > 0) {
@ -89,7 +104,7 @@ window.addEventListener("DOMContentLoaded", async (event) => {
"Some ranges couldn't be updated for the new video time endpoints. Please verify the time range values." "Some ranges couldn't be updated for the new video time endpoints. Please verify the time range values."
); );
} }
globalPlayer.once(Hls.Events.LEVEL_LOADED, (_data) => {
rangeDataUpdated(); rangeDataUpdated();
}); });
@ -1044,6 +1059,34 @@ function dateTimeFromVideoPlayerTime(videoPlayerTime) {
return wubloaderDateTime.plus({ seconds: offset }); return wubloaderDateTime.plus({ seconds: offset });
} }
function videoPlayerTimeFromDateTime(dateTime) {
const segmentList = getSegmentList();
for (const segment of segmentList) {
const segmentStart = DateTime.fromISO(segment.rawProgramDateTime);
const segmentEnd = segmentStart.plus({ seconds: segment.duration });
if (dateTime >= segmentStart && dateTime <= segmentEnd) {
return segment.start + dateTime.diff(segmentStart).as("seconds");
}
}
return null;
}
function dateTimeFromVideoHumanTime(videoHumanTime) {
const videoPlayerTime = videoPlayerTimeFromVideoHumanTime(videoHumanTime);
if (videoPlayerTime === null) {
return null;
}
return dateTimeFromVideoPlayerTime(videoPlayerTime);
}
function videoHumanTimeFromDateTime(dateTime) {
const videoPlayerTime = videoPlayerTimeFromDateTime(dateTime);
if (videoPlayerTime === null) {
return null;
}
return videoHumanTimeFromVideoPlayerTime(videoPlayerTime);
}
function wubloaderTimeFromVideoPlayerTime(videoPlayerTime) { function wubloaderTimeFromVideoPlayerTime(videoPlayerTime) {
const dt = dateTimeFromVideoPlayerTime(videoPlayerTime); const dt = dateTimeFromVideoPlayerTime(videoPlayerTime);
return wubloaderTimeFromDateTime(dt); return wubloaderTimeFromDateTime(dt);

Loading…
Cancel
Save