video: catch quality change errors
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/888/head
parent
6d1fa55a0f
commit
3106108f04
|
@ -341,38 +341,45 @@ class VideoContentSetup {
|
||||||
options: qualityNums,
|
options: qualityNums,
|
||||||
forced: true,
|
forced: true,
|
||||||
onChange: (quality: number) => {
|
onChange: (quality: number) => {
|
||||||
qualityList = content.videojs?.qualityLevels?.();
|
// Changing the quality sometimes throws strange
|
||||||
if (!qualityList || !content.videojs) return;
|
// 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) {
|
if (quality === -2) {
|
||||||
// Direct playback
|
// Direct playback
|
||||||
// Prevent any useless transcodes
|
// 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) {
|
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
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
// Set the source to the original video
|
console.error('Error changing quality', e);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue