Skip to content

Commit 7e8f840

Browse files
committed
Merge branch 'quality-add-autoQualityLabelTextGenerator-function-option'
2 parents adfd652 + aa91fb6 commit 7e8f840

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
*/
@@ -114,8 +138,7 @@ Object.assign(MediaElementPlayer.prototype, {
114138
const levels = media.hlsPlayer.levels;
115139
if (t.options.autoGenerateQualityOptionsFromManifest && levels.length > 1) {
116140
levels.forEach(function (level) {
117-
const height = level.height;
118-
const quality = t.getQualityFromHeight(height);
141+
const quality = t.options.autoQualityLabelTextGenerator(level);
119142
t.addValueToKey(qualityMap, quality, '');
120143
});
121144
t.options.autoHLS = true;
@@ -126,8 +149,7 @@ Object.assign(MediaElementPlayer.prototype, {
126149
const bitrates = media.dashPlayer.getBitrateInfoListFor("video");
127150
if (t.options.autoGenerateQualityOptionsFromManifest && bitrates.length > 1) {
128151
bitrates.forEach(function (level) {
129-
const height = level.height;
130-
const quality = t.getQualityFromHeight(height);
152+
const quality = t.options.autoQualityLabelTextGenerator(level);
131153
t.addValueToKey(qualityMap, quality, '');
132154
});
133155
t.options.autoDash = true;
@@ -464,25 +486,5 @@ Object.assign(MediaElementPlayer.prototype, {
464486
}
465487

466488
return newQuality;
467-
},
468-
469-
/**
470-
* Returns the quality represnetaion base on the height of the loaded video
471-
* @param {Number} height the pixel height of the video
472-
**/
473-
getQualityFromHeight (height) {
474-
if (height >= 4320) {
475-
return "8K UHD";
476-
} else if (height >= 2160) {
477-
return "UHD";
478-
} else if (height >= 1440) {
479-
return "QHD";
480-
} else if (height >= 1080) {
481-
return "FHD";
482-
} else if (height >= 720) {
483-
return "HD";
484-
} else {
485-
return "SD";
486-
}
487489
}
488490
});

0 commit comments

Comments
 (0)