Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions src/quality/quality.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ Object.assign(mejs.MepDefaults, {
* @type {String}
*/
qualityText: null,
/**
* @type {autoQualityLabelTextGenerator} cb
* @param {object} level - contains at least a width and height field with the resolution of that stream
*/
autoQualityLabelTextGenerator (level) {
// Return it as named qualities
const height = level.height
if (height >= 4320) {
return "8K UHD";
} else if (height >= 2160) {
return "UHD";
} else if (height >= 1440) {
return "QHD";
} else if (height >= 1080) {
return "FHD";
} else if (height >= 720) {
return "HD";
} else {
return "SD";
}

// return it as 1080p, 720p etc.
// return level.height + 'p'
},
/**
* @type {boolean}
*/
Expand Down Expand Up @@ -106,8 +130,7 @@ Object.assign(MediaElementPlayer.prototype, {
const levels = media.hlsPlayer.levels;
if (t.options.autoGenerate && levels.length > 1) {
levels.forEach(function (level) {
const height = level.height;
const quality = t.getQualityFromHeight(height);
const quality = t.options.autoQualityLabelTextGenerator(level);
t.addValueToKey(qualityMap, quality, '');
});
t.options.autoHLS = true;
Expand All @@ -118,8 +141,7 @@ Object.assign(MediaElementPlayer.prototype, {
const bitrates = media.dashPlayer.getBitrateInfoListFor("video");
if (t.options.autoGenerate && bitrates.length > 1) {
bitrates.forEach(function (level) {
const height = level.height;
const quality = t.getQualityFromHeight(height);
const quality = t.options.autoQualityLabelTextGenerator(level);
t.addValueToKey(qualityMap, quality, '');
});
t.options.autoDash = true;
Expand Down Expand Up @@ -455,25 +477,5 @@ Object.assign(MediaElementPlayer.prototype, {
}

return newQuality;
},

/**
* Returns the quality represnetaion base on the height of the loaded video
* @param {Number} height the pixel height of the video
**/
getQualityFromHeight (height) {
if (height >= 4320) {
return "8K UHD";
} else if (height >= 2160) {
return "UHD";
} else if (height >= 1440) {
return "QHD";
} else if (height >= 1080) {
return "FHD";
} else if (height >= 720) {
return "HD";
} else {
return "SD";
}
}
});