Fix issues with updating the ranges when the time range updates

There were a couple issues with this:
- The range data was updated in the wrong direction
- If no adjustments were made, the problem was masked by the range data reapplying from draft data. However, if adjustments were made, the adjustments were overwritten (or, if ranges were added, partially overwritten) by the defaults.
pull/244/head
ElementalAlchemist 3 years ago committed by Christopher Usher
parent 5f79605ee6
commit 394a6c72e2

@ -1,6 +1,7 @@
var googleUser = null; var googleUser = null;
var videoInfo; var videoInfo;
var currentRange = 1; var currentRange = 1;
var globalLoadedRangeData = false;
window.addEventListener("DOMContentLoaded", async (event) => { window.addEventListener("DOMContentLoaded", async (event) => {
commonPageSetup(); commonPageSetup();
@ -39,9 +40,9 @@ window.addEventListener("DOMContentLoaded", async (event) => {
// The video duration isn't precisely the video times, but can be padded by up to the // The video duration isn't precisely the video times, but can be padded by up to the
// segment length on either side. // segment length on either side.
// This makes the assumption that all segments have the same length. const segmentList = getPlaylistData().segments;
const segmentLength = getPlaylistData().segments[0].duration; newDuration += segmentList[0].duration;
newDuration += segmentLength * 2; newDuration += segmentList[segmentList.length - 1].duration;
// Abort for ranges that exceed new times // Abort for ranges that exceed new times
for (const rangeContainer of document.getElementById("range-definitions").children) { for (const rangeContainer of document.getElementById("range-definitions").children) {
@ -74,14 +75,14 @@ window.addEventListener("DOMContentLoaded", async (event) => {
if (rangeStart === null) { if (rangeStart === null) {
rangeErrorCount++; rangeErrorCount++;
} else { } else {
rangeStartField.value = videoHumanTimeFromVideoPlayerTime(startAdjustment + rangeStart); rangeStartField.value = videoHumanTimeFromVideoPlayerTime(rangeStart - startAdjustment);
} }
const rangeEnd = videoPlayerTimeFromVideoHumanTime(rangeEndField.value); const rangeEnd = videoPlayerTimeFromVideoHumanTime(rangeEndField.value);
if (rangeEnd === null) { if (rangeEnd === null) {
rangeErrorCount++; rangeErrorCount++;
} else { } else {
rangeEndField.value = videoHumanTimeFromVideoPlayerTime(startAdjustment + rangeEnd); rangeEndField.value = videoHumanTimeFromVideoPlayerTime(rangeEnd - startAdjustment);
} }
} }
if (rangeErrorCount > 0) { if (rangeErrorCount > 0) {
@ -89,6 +90,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."
); );
} }
rangeDataUpdated();
const waveformImage = document.getElementById("waveform"); const waveformImage = document.getElementById("waveform");
if (newEnd === null) { if (newEnd === null) {
@ -376,6 +378,7 @@ async function initializeVideoInfo() {
const player = getVideoJS(); const player = getVideoJS();
player.on("loadedmetadata", () => { player.on("loadedmetadata", () => {
if (!globalLoadedRangeData) {
const rangeDefinitionsContainer = document.getElementById("range-definitions"); const rangeDefinitionsContainer = document.getElementById("range-definitions");
if (videoInfo.video_ranges && videoInfo.video_ranges.length > 0) { if (videoInfo.video_ranges && videoInfo.video_ranges.length > 0) {
for (let rangeIndex = 0; rangeIndex < videoInfo.video_ranges.length; rangeIndex++) { for (let rangeIndex = 0; rangeIndex < videoInfo.video_ranges.length; rangeIndex++) {
@ -410,6 +413,8 @@ async function initializeVideoInfo() {
} }
} }
rangeDataUpdated(); rangeDataUpdated();
globalLoadedRangeData = true;
}
}); });
player.on("timeupdate", () => { player.on("timeupdate", () => {
const player = getVideoJS(); const player = getVideoJS();

Loading…
Cancel
Save