Fix bandwithSelector and livestream selector broken

This commit is contained in:
Rafael 2022-04-22 08:35:30 -03:00 committed by Thomas Zarebczan
parent 14fc7bae50
commit 6b1bcb34a7
3 changed files with 13 additions and 48 deletions

View file

@ -111,29 +111,6 @@ class HlsQualitySelectorPlugin {
concreteButtonInstance.removeClass('vjs-hidden'); concreteButtonInstance.removeClass('vjs-hidden');
} }
resolveAutoQualityLabel(includeResolution) {
const player = this.player;
const vhs = player.tech(true).vhs;
if (includeResolution && vhs) {
const pixelRatio = this.useDevicePixelRatio ? window.devicePixelRatio || 1 : 1;
const selectedBandwidth = simpleSelector(
vhs.playlists.master,
vhs.systemBandwidth,
parseInt(safeGetComputedStyle(vhs.tech_.el_, 'width'), 10) * pixelRatio,
parseInt(safeGetComputedStyle(vhs.tech_.el_, 'height'), 10) * pixelRatio,
vhs.limitRenditionByPlayerDimensions
);
const quality = selectedBandwidth.attributes.RESOLUTION.height;
return __('Auto (%quality%) --[Video quality popup. Long form.]--', { quality: quality + 'p' });
} else {
return __('Auto --[Video quality. Short form]--');
}
}
resolveOriginalQualityLabel(abbreviatedForm, includeResolution) { resolveOriginalQualityLabel(abbreviatedForm, includeResolution) {
if (includeResolution && this.config.originalHeight) { if (includeResolution && this.config.originalHeight) {
return abbreviatedForm return abbreviatedForm
@ -160,7 +137,7 @@ class HlsQualitySelectorPlugin {
let str; let str;
switch (text) { switch (text) {
case QUALITY_OPTIONS.AUTO: case QUALITY_OPTIONS.AUTO:
str = this.resolveAutoQualityLabel(true); str = QUALITY_OPTIONS.AUTO;
break; break;
case QUALITY_OPTIONS.ORIGINAL: case QUALITY_OPTIONS.ORIGINAL:
str = this.resolveOriginalQualityLabel(true, false); str = this.resolveOriginalQualityLabel(true, false);
@ -227,6 +204,7 @@ class HlsQualitySelectorPlugin {
levelItems = levelItems.map((item) => levelItems = levelItems.map((item) =>
item === nextLowestQualityItem ? this.getQualityMenuItem.call(this, nextLowestQualityItemObj) : item item === nextLowestQualityItem ? this.getQualityMenuItem.call(this, nextLowestQualityItemObj) : item
); );
this._currentQuality = nextLowestQualityItemObj.value;
} }
levelItems.sort((current, next) => { levelItems.sort((current, next) => {
@ -254,7 +232,7 @@ class HlsQualitySelectorPlugin {
levelItems.push( levelItems.push(
this.getQualityMenuItem.call(this, { this.getQualityMenuItem.call(this, {
label: this.resolveAutoQualityLabel(true), label: QUALITY_OPTIONS.AUTO,
value: QUALITY_OPTIONS.AUTO, value: QUALITY_OPTIONS.AUTO,
selected: !defaultQuality ? true : defaultQuality === QUALITY_OPTIONS.AUTO, selected: !defaultQuality ? true : defaultQuality === QUALITY_OPTIONS.AUTO,
}) })

View file

@ -205,19 +205,10 @@ export const lastBandwidthSelector = function() {
const hlsQualitySelector = player.hlsQualitySelector; const hlsQualitySelector = player.hlsQualitySelector;
const originalHeight = hlsQualitySelector.config.originalHeight; const originalHeight = hlsQualitySelector.config.originalHeight;
if (originalHeight && hlsQualitySelector) { if (hlsQualitySelector?.getCurrentQuality() === 'auto') {
if (hlsQualitySelector.getCurrentQuality() === 'auto') { hlsQualitySelector._qualityButton.menuButton_.$('.vjs-icon-placeholder').innerHTML = __('Auto(%quality%) --[Video quality popup. Long form.]--', { quality: selectedBandwidth.attributes.RESOLUTION.height + 'p' });
if (selectedBandwidth.attributes.RESOLUTION.height === originalHeight) {
if (player.claimSrcOriginal && player.currentSrc() !== player.claimSrcOriginal?.src) {
setTimeout(() => {
const currentTime = player.currentTime();
player.src(player.claimSrcOriginal);
player.currentTime(currentTime);
});
}
}
}
} }
return selectedBandwidth; return selectedBandwidth;
}; };

View file

@ -33,8 +33,6 @@ import { lastBandwidthSelector } from './internal/plugins/videojs-http-streaming
// const PLAY_TIMEOUT_LIMIT = 2000; // const PLAY_TIMEOUT_LIMIT = 2000;
const PLAY_POSITION_SAVE_INTERVAL_MS = 15000; const PLAY_POSITION_SAVE_INTERVAL_MS = 15000;
const USE_ORIGINAL_STREAM_FOR_OPTIMIZED_AUTO = false;
type Props = { type Props = {
position: number, position: number,
changeVolume: (number) => void, changeVolume: (number) => void,
@ -388,15 +386,13 @@ function VideoViewer(props: Props) {
player.on('loadedmetadata', () => restorePlaybackRate(player)); player.on('loadedmetadata', () => restorePlaybackRate(player));
// Override "auto" to use non-vhs url when the quality matches. // Override "auto" to use non-vhs url when the quality matches.
if (USE_ORIGINAL_STREAM_FOR_OPTIMIZED_AUTO) { player.on('loadedmetadata', () => {
player.on('loadedmetadata', () => { const vhs = player.tech(true).vhs;
const vhs = player.tech(true).vhs; if (vhs) {
if (vhs) { // https://github.com/videojs/http-streaming/issues/749#issuecomment-606972884
// https://github.com/videojs/http-streaming/issues/749#issuecomment-606972884 vhs.selectPlaylist = lastBandwidthSelector;
vhs.selectPlaylist = lastBandwidthSelector; }
} });
});
}
// used for tracking buffering for watchman // used for tracking buffering for watchman
player.on('tracking:buffered', doTrackingBuffered); player.on('tracking:buffered', doTrackingBuffered);