Increase speed limits
This commit is contained in:
@ -25,6 +25,7 @@ import { createElement, hasClass, removeElement, replaceElement, toggleClass, wr
|
|||||||
import { off, on, once, triggerEvent, unbindListeners } from './utils/events';
|
import { off, on, once, triggerEvent, unbindListeners } from './utils/events';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
import loadSprite from './utils/loadSprite';
|
import loadSprite from './utils/loadSprite';
|
||||||
|
import { clamp } from './utils/numbers';
|
||||||
import { cloneDeep, extend } from './utils/objects';
|
import { cloneDeep, extend } from './utils/objects';
|
||||||
import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateRatio } from './utils/style';
|
import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateRatio } from './utils/style';
|
||||||
import { parseUrl } from './utils/urls';
|
import { parseUrl } from './utils/urls';
|
||||||
@ -661,18 +662,9 @@ class Plyr {
|
|||||||
speed = this.config.speed.selected;
|
speed = this.config.speed.selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set min/max
|
// Clamp to min/max
|
||||||
if (speed < 0.1) {
|
const { minimumSpeed: min, maximumSpeed: max } = this;
|
||||||
speed = 0.1;
|
speed = clamp(speed, min, max);
|
||||||
}
|
|
||||||
if (speed > 2.0) {
|
|
||||||
speed = 2.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.config.speed.options.includes(speed)) {
|
|
||||||
this.debug.warn(`Unsupported speed (${speed})`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update config
|
// Update config
|
||||||
this.config.speed.selected = speed;
|
this.config.speed.selected = speed;
|
||||||
@ -690,6 +682,42 @@ class Plyr {
|
|||||||
return Number(this.media.playbackRate);
|
return Number(this.media.playbackRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the minimum allowed speed
|
||||||
|
*/
|
||||||
|
get minimumSpeed() {
|
||||||
|
if (this.isYouTube) {
|
||||||
|
// https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
|
||||||
|
return Math.min(...this.options.speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isVimeo) {
|
||||||
|
// https://github.com/vimeo/player.js/#setplaybackrateplaybackrate-number-promisenumber-rangeerrorerror
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/32320020/1191319
|
||||||
|
return 0.0625;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum allowed speed
|
||||||
|
*/
|
||||||
|
get maximumSpeed() {
|
||||||
|
if (this.isYouTube) {
|
||||||
|
// https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
|
||||||
|
return Math.max(...this.options.speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isVimeo) {
|
||||||
|
// https://github.com/vimeo/player.js/#setplaybackrateplaybackrate-number-promisenumber-rangeerrorerror
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/32320020/1191319
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set playback quality
|
* Set playback quality
|
||||||
* Currently HTML5 & YouTube only
|
* Currently HTML5 & YouTube only
|
||||||
|
17
src/js/utils/numbers.js
Normal file
17
src/js/utils/numbers.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Returns a number whose value is limited to the given range.
|
||||||
|
*
|
||||||
|
* Example: limit the output of this computation to between 0 and 255
|
||||||
|
* (x * 255).clamp(0, 255)
|
||||||
|
*
|
||||||
|
* @param {Number} input
|
||||||
|
* @param {Number} min The lower boundary of the output range
|
||||||
|
* @param {Number} max The upper boundary of the output range
|
||||||
|
* @returns A number in the range [min, max]
|
||||||
|
* @type Number
|
||||||
|
*/
|
||||||
|
export function clamp(input = 0, min = 0, max = 255) {
|
||||||
|
return Math.min(Math.max(input, min), max);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { clamp };
|
Reference in New Issue
Block a user