Skip to content

Commit aa91fb6

Browse files
committed
Turn the quality label text generator into a config option
1 parent 42dc804 commit aa91fb6

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

src/quality/quality.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ Object.assign(mejs.MepDefaults, {
2020
* @type {String}
2121
*/
2222
qualityText: null,
23+
/**
24+
* @type {autoQualityLabelTextGenerator} cb
25+
* @param {object} level - contains at least a width and height field with the resolution of that stream
26+
*/
27+
autoQualityLabelTextGenerator (level) {
28+
// Return it as named qualities
29+
const height = level.height
30+
if (height >= 4320) {
31+
return "8K UHD";
32+
} else if (height >= 2160) {
33+
return "UHD";
34+
} else if (height >= 1440) {
35+
return "QHD";
36+
} else if (height >= 1080) {
37+
return "FHD";
38+
} else if (height >= 720) {
39+
return "HD";
40+
} else {
41+
return "SD";
42+
}
43+
44+
// return it as 1080p, 720p etc.
45+
// return level.height + 'p'
46+
},
2347
/**
2448
* @type {boolean}
2549
*/
@@ -106,8 +130,7 @@ Object.assign(MediaElementPlayer.prototype, {
106130
const levels = media.hlsPlayer.levels;
107131
if (t.options.autoGenerate && levels.length > 1) {
108132
levels.forEach(function (level) {
109-
const height = level.height;
110-
const quality = t.getQualityFromHeight(height);
133+
const quality = t.options.autoQualityLabelTextGenerator(level);
111134
t.addValueToKey(qualityMap, quality, '');
112135
});
113136
t.options.autoHLS = true;
@@ -118,8 +141,7 @@ Object.assign(MediaElementPlayer.prototype, {
118141
const bitrates = media.dashPlayer.getBitrateInfoListFor("video");
119142
if (t.options.autoGenerate && bitrates.length > 1) {
120143
bitrates.forEach(function (level) {
121-
const height = level.height;
122-
const quality = t.getQualityFromHeight(height);
144+
const quality = t.options.autoQualityLabelTextGenerator(level);
123145
t.addValueToKey(qualityMap, quality, '');
124146
});
125147
t.options.autoDash = true;
@@ -455,25 +477,5 @@ Object.assign(MediaElementPlayer.prototype, {
455477
}
456478

457479
return newQuality;
458-
},
459-
460-
/**
461-
* Returns the quality represnetaion base on the height of the loaded video
462-
* @param {Number} height the pixel height of the video
463-
**/
464-
getQualityFromHeight (height) {
465-
if (height >= 4320) {
466-
return "8K UHD";
467-
} else if (height >= 2160) {
468-
return "UHD";
469-
} else if (height >= 1440) {
470-
return "QHD";
471-
} else if (height >= 1080) {
472-
return "FHD";
473-
} else if (height >= 720) {
474-
return "HD";
475-
} else {
476-
return "SD";
477-
}
478480
}
479481
});

0 commit comments

Comments
 (0)