From 014e82138e4ebd2b6af583bada6ba047decab24b Mon Sep 17 00:00:00 2001 From: nholtman Date: Mon, 8 Apr 2024 14:52:53 +0200 Subject: [PATCH] Add option hslQualityChangeStrategy, set option to nextLevel instead of currentLevel. This means that the next fragment will load with the set quality instead of the current. This results in smoother playback when compared to currentLevel --- src/quality/quality.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/quality/quality.js b/src/quality/quality.js index 97b5cd5..b0194b7 100644 --- a/src/quality/quality.js +++ b/src/quality/quality.js @@ -24,6 +24,10 @@ Object.assign(mejs.MepDefaults, { * @type {boolean} */ autoGenerate: false, + /** + * @type {String} + */ + hslQualityChangeStrategy: 'nextLevel', /** * @type {boolean} */ @@ -415,13 +419,14 @@ Object.assign(MediaElementPlayer.prototype, { * @param {MediaElement} media */ switchHLSQuality (player, media) { + const t = this; const radios = player.qualitiesContainer.querySelectorAll('input[type="radio"]'); for (let index = 0; index < radios.length; index++) { if (radios[index].checked) { if (index === 0 ) { - media.hlsPlayer.currentLevel = -1; + media.hlsPlayer[t.options.hslQualityChangeStrategy] = -1; } else { - media.hlsPlayer.currentLevel = index - 1; + media.hlsPlayer[t.options.hslQualityChangeStrategy] = index - 1; } } }