Skip to content

Commit

Permalink
Merge pull request #143 from wingman-jr-addon/broken-yt-dog-house
Browse files Browse the repository at this point in the history
Catching video loading event-not-called issue with a timeout, cleanin…
  • Loading branch information
wingman-jr-addon authored Aug 14, 2021
2 parents eae9991 + aa617b1 commit 549682a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions background_video.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,10 @@ async function vidYtMp4Listener(details, mimeType, parsedUrl) {
let cpn = parsedUrl.searchParams.get('cpn');
let videoChainId = 'yt-mp4-'+cpn+'-'+details.requestId;
let rangeRaw = parsedUrl.searchParams.get('range');
if(rangeRaw === undefined || rangeRaw === null) {
console.warn(`YTFMP4: For request ${details.requestId} ${cpn}, failed to get the range, aborting. URL: ${details.url}`);
return details;
}
console.info('YTVMP4: Starting request '+details.requestId+' '+cpn+', '+rangeRaw);
let splitIndex = rangeRaw.indexOf('-'); //e.g. range=0-3200
let rangeStart = parseInt(rangeRaw.substr(0, splitIndex));
Expand Down
16 changes: 16 additions & 0 deletions processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,29 @@ function procGetBufferedRangesString(video) {
return result;
}

const VIDEO_LOAD_TIMEOUT_MS = 5000;
const procVideoLoadedData = (video,url,seekTime) => new Promise( (resolve, reject) => {
let isResolved = false;
video.addEventListener('error', ()=>reject(video.error), {once: true});
video.addEventListener('seeked', () => {
video.width = video.videoWidth;
video.height = video.videoHeight;
isResolved = true;
resolve();
} , {once:true});
//Note that the URL is in memory, not remote
//making a small timeout a reasonable choice
//Without the below, there was at least one URL
//that simply didn't fire the expected events,
//so this acts as a safeguard
let timeoutId = setTimeout(() => {
clearTimeout(timeoutId);
if(isResolved) {
return;
}
console.warn(`MLV: Timed out`);
reject(`MLV: Timed out in ${VIDEO_LOAD_TIMEOUT_MS} ms`);
}, VIDEO_LOAD_TIMEOUT_MS);
video.src = url;
video.currentTime = seekTime;
});
Expand Down

0 comments on commit 549682a

Please sign in to comment.