Skip to content

Commit 0aa886d

Browse files
authored
feat(UI): Show the quality mark when using src= (#8511)
1 parent fefe61f commit 0aa886d

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

ui/resolution_selection.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ shaka.ui.ResolutionSelection = class extends shaka.ui.SettingsMenu {
145145
const track = tracks.find((track) => track.active);
146146
if (!track) {
147147
if (this.overflowQualityMark) {
148-
this.overflowQualityMark.textContent = '';
149-
this.overflowQualityMark.style.display = 'none';
148+
const stats = this.player.getStats();
149+
const mark = this.getQualityMark_(stats.width, stats.height);
150+
this.overflowQualityMark.textContent = mark;
151+
this.overflowQualityMark.style.display = mark !== '' ? '' : 'none';
150152
}
151153
return;
152154
}
@@ -165,7 +167,7 @@ shaka.ui.ResolutionSelection = class extends shaka.ui.SettingsMenu {
165167
}
166168

167169
/** @type {string} */
168-
const mark = this.getQualityMark_(track);
170+
const mark = this.getQualityMark_(track.width, track.height);
169171
this.qualityMark.textContent = mark;
170172
this.qualityMark.style.display = mark !== '' ? '' : 'none';
171173
if (this.overflowQualityMark) {
@@ -175,34 +177,37 @@ shaka.ui.ResolutionSelection = class extends shaka.ui.SettingsMenu {
175177
}
176178

177179
/**
178-
* @param {!shaka.extern.VideoTrack} track
180+
* @param {?number} width
181+
* @param {?number} height
179182
* @return {string}
180183
* @private
181184
*/
182-
getQualityMark_(track) {
183-
let trackHeight = track.height || 0;
184-
let trackWidth = track.width || 0;
185+
getQualityMark_(width, height) {
186+
if (!width || !height) {
187+
return '';
188+
}
189+
let trackHeight = height;
190+
let trackWidth = width;
185191
if (trackHeight > trackWidth) {
186192
// Vertical video.
187193
[trackWidth, trackHeight] = [trackHeight, trackWidth];
188194
}
189-
let height = trackHeight;
190195
const aspectRatio = trackWidth / trackHeight;
191196
if (aspectRatio > (16 / 9)) {
192-
height = Math.round(trackWidth * 9 / 16);
197+
trackHeight = Math.round(trackWidth * 9 / 16);
193198
}
194199
const qualityMarks = this.controls.getConfig().qualityMarks;
195-
if (height >= 8640) {
196-
return height + 'p';
197-
} else if (height >= 4320) {
200+
if (trackHeight >= 8640) {
201+
return trackHeight + 'p';
202+
} else if (trackHeight >= 4320) {
198203
return qualityMarks['4320'];
199-
} else if (height >= 2160) {
204+
} else if (trackHeight >= 2160) {
200205
return qualityMarks['2160'];
201-
} else if (height >= 1440) {
206+
} else if (trackHeight >= 1440) {
202207
return qualityMarks['1440'];
203-
} else if (height >= 1080) {
208+
} else if (trackHeight >= 1080) {
204209
return qualityMarks['1080'];
205-
} else if (height >= 720) {
210+
} else if (trackHeight >= 720) {
206211
return qualityMarks['720'];
207212
}
208213
return '';
@@ -409,7 +414,7 @@ shaka.ui.ResolutionSelection = class extends shaka.ui.SettingsMenu {
409414
}
410415
button.appendChild(span);
411416

412-
const mark = this.getQualityMark_(track);
417+
const mark = this.getQualityMark_(track.width, track.height);
413418
if (mark !== '') {
414419
const markEl = shaka.util.Dom.createHTMLElement('sup');
415420
markEl.classList.add('shaka-quality-mark');

0 commit comments

Comments
 (0)