Fix switch again

This commit is contained in:
Rafael 2022-04-26 21:00:34 -03:00 committed by Thomas Zarebczan
parent 3ac57776e9
commit 4669246b55

View file

@ -46,6 +46,15 @@ class HlsQualitySelectorPlugin {
// Listen for source changes // Listen for source changes
this.player.on('loadedmetadata', (e) => { this.player.on('loadedmetadata', (e) => {
// if there was a quality option selected to default to, set it using the setQuality function
// as if it was being clicked on, on loadedmetadata
if (this.player.qualityToSet && !this.player.switchedFromDefaultQuality) {
this.setQuality(this.player.qualityToSet);
// Add this attribute to the video player so later it can be checked and avoid switching again
// Since this is only for initial load, based on the default quality setting
this.player.switchedFromDefaultQuality = true;
}
this.updatePlugin(); this.updatePlugin();
}); });
} }
@ -198,7 +207,6 @@ class HlsQualitySelectorPlugin {
value: currentHeight, value: currentHeight,
selected: true, selected: true,
}; };
this.setQuality(currentHeight);
} }
levelItems.push(levelItem); levelItems.push(levelItem);
@ -225,9 +233,6 @@ class HlsQualitySelectorPlugin {
}); });
if (!player.isLivestream) { if (!player.isLivestream) {
const videoEl = document.querySelector('.vjs-tech');
const didSwitch = videoEl.getAttribute('switched-from-default');
levelItems.push( levelItems.push(
this.getQualityMenuItem.call(this, { this.getQualityMenuItem.call(this, {
label: this.resolveOriginalQualityLabel(false, true), label: this.resolveOriginalQualityLabel(false, true),
@ -235,11 +240,8 @@ class HlsQualitySelectorPlugin {
selected: defaultQuality ? defaultQuality === QUALITY_OPTIONS.ORIGINAL : false, selected: defaultQuality ? defaultQuality === QUALITY_OPTIONS.ORIGINAL : false,
}) })
); );
if (defaultQuality === QUALITY_OPTIONS.ORIGINAL && !didSwitch) { if (defaultQuality === QUALITY_OPTIONS.ORIGINAL && !player.switchedFromDefaultQuality) {
this.swapSrcTo(QUALITY_OPTIONS.ORIGINAL); this.swapSrcTo(QUALITY_OPTIONS.ORIGINAL);
// Add this attribute to the video player so later it can be checked and avoid switching again
// Since this is only for initial load, based on the default quality setting
videoEl.setAttribute('switched-from-default', true);
} }
} }
@ -251,9 +253,12 @@ class HlsQualitySelectorPlugin {
}) })
); );
this.setButtonInnerText( // initial button inner text based on default quality setting, or next lowest
nextLowestQualityItemObj ? nextLowestQualityItemObj.label : defaultQuality || QUALITY_OPTIONS.AUTO if (!this.player.switchedFromDefaultQuality) {
); this.setButtonInnerText(
nextLowestQualityItemObj ? nextLowestQualityItemObj.label : defaultQuality || QUALITY_OPTIONS.AUTO
);
}
if (this._qualityButton) { if (this._qualityButton) {
this._qualityButton.createItems = function () { this._qualityButton.createItems = function () {
@ -261,6 +266,13 @@ class HlsQualitySelectorPlugin {
}; };
this._qualityButton.update(); this._qualityButton.update();
} }
if (defaultQuality) {
this.player.qualityToSet =
nextLowestQualityItemObj?.value ||
(defaultQuality === QUALITY_OPTIONS.ORIGINAL && QUALITY_OPTIONS.ORIGINAL) ||
QUALITY_OPTIONS.AUTO;
}
} }
swapSrcTo(mode = QUALITY_OPTIONS.ORIGINAL) { swapSrcTo(mode = QUALITY_OPTIONS.ORIGINAL) {