Manually merged PR #1607

This commit is contained in:
Sam Potts 2020-01-14 07:25:41 +00:00
parent ff105ee203
commit 6ffaef35cf
2 changed files with 36 additions and 24 deletions

View File

@ -70,6 +70,8 @@ const defaults = {
quality: { quality: {
default: 576, default: 576,
options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240], options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240],
forced: false,
onChange: null,
}, },
// Set loops // Set loops

View File

@ -30,6 +30,11 @@ const html5 = {
// Get quality levels // Get quality levels
getQualityOptions() { getQualityOptions() {
// Whether we're forcing all options (e.g. for streaming)
if (this.config.quality.forced) {
return this.config.quality.options;
}
// Get sizes from <source> elements // Get sizes from <source> elements
return html5.getSources return html5.getSources
.call(this) .call(this)
@ -60,36 +65,41 @@ const html5 = {
return source && Number(source.getAttribute('size')); return source && Number(source.getAttribute('size'));
}, },
set(input) { set(input) {
// Get sources // If we're using an an external handler...
const sources = html5.getSources.call(player); if (player.config.quality.forced && is.function(player.config.quality.onChange)) {
// Get first match for requested size player.config.quality.onChange(input);
const source = sources.find(s => Number(s.getAttribute('size')) === input); } else {
// Get sources
const sources = html5.getSources.call(player);
// Get first match for requested size
const source = sources.find(s => Number(s.getAttribute('size')) === input);
// No matching source found // No matching source found
if (!source) { if (!source) {
return; return;
} }
// Get current state // Get current state
const { currentTime, paused, preload, readyState } = player.media; const { currentTime, paused, preload, readyState } = player.media;
// Set new source // Set new source
player.media.src = source.getAttribute('src'); player.media.src = source.getAttribute('src');
// Prevent loading if preload="none" and the current source isn't loaded (#1044) // Prevent loading if preload="none" and the current source isn't loaded (#1044)
if (preload !== 'none' || readyState) { if (preload !== 'none' || readyState) {
// Restore time // Restore time
player.once('loadedmetadata', () => { player.once('loadedmetadata', () => {
player.currentTime = currentTime; player.currentTime = currentTime;
// Resume playing // Resume playing
if (!paused) { if (!paused) {
player.play(); player.play();
} }
}); });
// Load new source // Load new source
player.media.load(); player.media.load();
}
} }
// Trigger change event // Trigger change event