aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-02-10 18:34:05 +0000
committerSam Potts <sam@potts.es>2020-02-10 18:34:05 +0000
commit1619510dcf9e3ccc1693caa20a173aaf2789e346 (patch)
tree900d8a12a10ded90a058600ad459d3ed048c3ad1 /src
parentff8dedd4ec2235131a630635ec7927c75d0a3c16 (diff)
downloadplyr-1619510dcf9e3ccc1693caa20a173aaf2789e346.tar.lz
plyr-1619510dcf9e3ccc1693caa20a173aaf2789e346.tar.xz
plyr-1619510dcf9e3ccc1693caa20a173aaf2789e346.zip
Speed settings logic improvements
Diffstat (limited to 'src')
-rw-r--r--src/js/controls.js11
-rw-r--r--src/js/html5.js6
-rw-r--r--src/js/media.js2
-rw-r--r--src/js/plugins/vimeo.js17
-rw-r--r--src/js/plugins/youtube.js4
-rw-r--r--src/js/utils/arrays.js8
6 files changed, 22 insertions, 26 deletions
diff --git a/src/js/controls.js b/src/js/controls.js
index 1cce51f6..66ec7139 100644
--- a/src/js/controls.js
+++ b/src/js/controls.js
@@ -9,7 +9,7 @@ import captions from './captions';
import html5 from './html5';
import support from './support';
import { repaint, transitionEndEvent } from './utils/animation';
-import { dedupe, fillRange } from './utils/arrays';
+import { dedupe } from './utils/arrays';
import browser from './utils/browser';
import {
createElement,
@@ -1053,13 +1053,8 @@ const controls = {
const type = 'speed';
const list = this.elements.settings.panels.speed.querySelector('[role="menu"]');
- // Determine options to display
- // Vimeo and YouTube limit to 0.5x-2x
- if (this.isVimeo || this.isYouTube) {
- this.options.speed = fillRange(0.5, 2, 0.25).filter(s => this.config.speed.options.includes(s));
- } else {
- this.options.speed = this.config.speed.options;
- }
+ // Filter out invalid speeds
+ this.options.speed = this.options.speed.filter(o => o >= this.minimumSpeed && o <= this.maximumSpeed);
// Toggle the pane and tab
const toggle = !is.empty(this.options.speed) && this.options.speed.length > 1;
diff --git a/src/js/html5.js b/src/js/html5.js
index d1e82489..0591a709 100644
--- a/src/js/html5.js
+++ b/src/js/html5.js
@@ -42,13 +42,16 @@ const html5 = {
.filter(Boolean);
},
- extend() {
+ setup() {
if (!this.isHTML5) {
return;
}
const player = this;
+ // Set speed options from config
+ player.options.speed = player.config.speed.options;
+
// Set aspect ratio if fixed
if (!is.empty(this.config.ratio)) {
setAspectRatio.call(player);
@@ -93,7 +96,6 @@ const html5 = {
if (preload !== 'none' || readyState) {
// Restore time
player.once('loadedmetadata', () => {
-
player.speed = playbackRate;
player.currentTime = currentTime;
diff --git a/src/js/media.js b/src/js/media.js
index cd1533d0..8c08456d 100644
--- a/src/js/media.js
+++ b/src/js/media.js
@@ -49,7 +49,7 @@ const media = {
}
if (this.isHTML5) {
- html5.extend.call(this);
+ html5.setup.call(this);
} else if (this.isYouTube) {
youtube.setup.call(this);
} else if (this.isVimeo) {
diff --git a/src/js/plugins/vimeo.js b/src/js/plugins/vimeo.js
index 7d796858..fa965d8e 100644
--- a/src/js/plugins/vimeo.js
+++ b/src/js/plugins/vimeo.js
@@ -42,23 +42,28 @@ function assurePlaybackState(play) {
const vimeo = {
setup() {
+ const player = this;
+
// Add embed class for responsive
- toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
+ toggleClass(player.elements.wrapper, player.config.classNames.embed, true);
+
+ // Set speed options from config
+ player.options.speed = player.config.speed.options;
// Set intial ratio
- setAspectRatio.call(this);
+ setAspectRatio.call(player);
// Load the SDK if not already
if (!is.object(window.Vimeo)) {
- loadScript(this.config.urls.vimeo.sdk)
+ loadScript(player.config.urls.vimeo.sdk)
.then(() => {
- vimeo.ready.call(this);
+ vimeo.ready.call(player);
})
.catch(error => {
- this.debug.warn('Vimeo SDK (player.js) failed to load', error);
+ player.debug.warn('Vimeo SDK (player.js) failed to load', error);
});
} else {
- vimeo.ready.call(this);
+ vimeo.ready.call(player);
}
},
diff --git a/src/js/plugins/youtube.js b/src/js/plugins/youtube.js
index ba5d8de9..8c65b1dc 100644
--- a/src/js/plugins/youtube.js
+++ b/src/js/plugins/youtube.js
@@ -297,7 +297,9 @@ const youtube = {
});
// Get available speeds
- player.options.speed = instance.getAvailablePlaybackRates();
+ const speeds = instance.getAvailablePlaybackRates();
+ // Filter based on config
+ player.options.speed = speeds.filter(s => player.config.speed.options.includes(s));
// Set the tabindex to avoid focus entering iframe
if (player.supported.ui) {
diff --git a/src/js/utils/arrays.js b/src/js/utils/arrays.js
index c0d69626..69ef242c 100644
--- a/src/js/utils/arrays.js
+++ b/src/js/utils/arrays.js
@@ -21,11 +21,3 @@ export function closest(array, value) {
return array.reduce((prev, curr) => (Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev));
}
-
-export function fillRange(start, end, step = 1) {
- const len = Math.floor((end - start) / step) + 1;
-
- return Array(len)
- .fill()
- .map((_, idx) => start + idx * step);
-}