From 4e35fed5f2ceda8a641fdc138876bcc8d4da3d2a Mon Sep 17 00:00:00 2001 From: ElementalAlchemist Date: Sun, 7 Nov 2021 12:12:42 -0600 Subject: [PATCH] Handle when the video stops playing due to load issues when seeking --- thrimbletrimmer/scripts/common.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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) {