diff --git a/thrimbletrimmer/scripts/common.js b/thrimbletrimmer/scripts/common.js index 0d72999..a63f212 100644 --- a/thrimbletrimmer/scripts/common.js +++ b/thrimbletrimmer/scripts/common.js @@ -9,6 +9,7 @@ var globalEndTimeString = ""; var globalPlayer = null; var globalSetUpControls = false; +var globalSeekTimer = null; Hls.DefaultConfig.maxBufferHole = 600; @@ -243,6 +244,32 @@ function setUpVideoControls() { videoElement.currentTime = newPosition; playbackPosition.value = newPosition; }); + + /* Sometimes a mysterious issue occurs loading segments of the video when seeking. + * When this happens, twiddling the qualities tends to fix it. Here, we attempt to + * detect this situation and fix it automatically. + */ + videoElement.addEventListener("seeking", (_event) => { + // If we don't get a "seeked" event soon after the "seeking" event, we assume there's + // a loading error. + // To handle this, we set up a timed handler to pick this up. + if (globalSeekTimer !== null) { + clearTimeout(globalSeekTimer); + globalSeekTimer = null; + } + globalSeekTimer = setTimeout(() => { + const currentLevel = globalPlayer.currentLevel; + globalPlayer.currentLevel = -1; + globalPlayer.currentLevel = currentLevel; + }, 500); + }); + videoElement.addEventListener("seeked", (_event) => { + // Since we got the seek, cancel the timed twiddling of qualities + if (globalSeekTimer !== null) { + clearTimeout(globalSeekTimer); + globalSeekTimer = null; + } + }); } function dateTimeMathObjectFromBusTime(busTime) {