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,36 +60,51 @@ 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();
let rangeErrorCount = 0; globalPlayer.once(Hls.Events.LEVEL_LOADED, (_data) => {
for (const rangeContainer of document.getElementById("range-definitions").children) { let rangeErrorCount = 0;
const rangeStartField = rangeContainer.getElementsByClassName("range-definition-start")[0]; for (const [rangeIndex, rangeData] of rangesData.entries()) {
const rangeEndField = rangeContainer.getElementsByClassName("range-definition-end")[0]; const rangeContainer = rangeDefinitionsElements[rangeIndex];
const rangeStartField = rangeContainer.getElementsByClassName("range-definition-start")[0];
const rangeEndField = rangeContainer.getElementsByClassName("range-definition-end")[0];
if (rangeData.start) {
rangeStartField.value = videoHumanTimeFromDateTime(rangeData.start);
} else {
rangeErrorCount++;
}
const rangeStart = videoPlayerTimeFromVideoHumanTime(rangeStartField.value); if (rangeData.end) {
if (rangeStart === null) { rangeEndField.value = videoHumanTimeFromDateTime(rangeData.end);
rangeErrorCount++; } else {
} else { rangeErrorCount++;
rangeStartField.value = videoHumanTimeFromVideoPlayerTime(rangeStart - startAdjustment); }
} }
if (rangeErrorCount > 0) {
const rangeEnd = videoPlayerTimeFromVideoHumanTime(rangeEndField.value); addError(
if (rangeEnd === null) { "Some ranges couldn't be updated for the new video time endpoints. Please verify the time range values."
rangeErrorCount++; );
} else {
rangeEndField.value = videoHumanTimeFromVideoPlayerTime(rangeEnd - startAdjustment);
} }
}
if (rangeErrorCount > 0) {
addError(
"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