From 3106108f0496e09b318321e30997fba2b3abd942 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 24 Oct 2023 16:51:29 -0700 Subject: [PATCH] video: catch quality change errors Signed-off-by: Varun Patil --- src/components/viewer/PsVideo.ts | 63 ++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/components/viewer/PsVideo.ts b/src/components/viewer/PsVideo.ts index 80f57388..f7d28d39 100644 --- a/src/components/viewer/PsVideo.ts +++ b/src/components/viewer/PsVideo.ts @@ -341,38 +341,45 @@ class VideoContentSetup { options: qualityNums, forced: true, onChange: (quality: number) => { - qualityList = content.videojs?.qualityLevels?.(); - if (!qualityList || !content.videojs) return; + // Changing the quality sometimes throws strange + // DOMExceptions; don't let this stop Plyr from being + // constructed altogether. + try { + qualityList = content.videojs?.qualityLevels?.(); + if (!qualityList || !content.videojs) return; - const isHLS = content.videojs.src(undefined)?.includes('m3u8'); + const isHLS = content.videojs.src(undefined)?.includes('m3u8'); - if (quality === -2) { - // Direct playback - // Prevent any useless transcodes + if (quality === -2) { + // Direct playback + // Prevent any useless transcodes + for (let i = 0; i < qualityList.length; ++i) { + qualityList[i].enabled = false; + } + + // Set the source to the original video + if (isHLS) { + content.videojs.src(this.getDirectSrc(content)); + } + return; + } else { + // Set source to HLS + if (!isHLS) { + content.videojs.src(this.getHLSsrc(content)); + } + } + + // Enable only the selected quality for (let i = 0; i < qualityList.length; ++i) { - qualityList[i].enabled = false; + const { width, height, label } = qualityList[i]; + const pixels = Math.min(width!, height!); + qualityList[i].enabled = + !quality || // auto + pixels === quality || // exact match + (label?.includes('max.m3u8') && quality === -1); // max } - - // Set the source to the original video - if (isHLS) { - content.videojs.src(this.getDirectSrc(content)); - } - return; - } else { - // Set source to HLS - if (!isHLS) { - content.videojs.src(this.getHLSsrc(content)); - } - } - - // Enable only the selected quality - for (let i = 0; i < qualityList.length; ++i) { - const { width, height, label } = qualityList[i]; - const pixels = Math.min(width!, height!); - qualityList[i].enabled = - !quality || // auto - pixels === quality || // exact match - (label?.includes('max.m3u8') && quality === -1); // max + } catch (e) { + console.error('Error changing quality', e); } }, };