aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-01-14 07:25:41 +0000
committerSam Potts <sam@potts.es>2020-01-14 07:25:41 +0000
commit6ffaef35cf667d0e2e14227882a1a8e329b2c2c2 (patch)
treed24c48bea4d563a1f3d68686dc43fd1cbdb4a264 /src
parentff105ee203a77086541487b6634024c81fe76d90 (diff)
downloadplyr-6ffaef35cf667d0e2e14227882a1a8e329b2c2c2.tar.lz
plyr-6ffaef35cf667d0e2e14227882a1a8e329b2c2c2.tar.xz
plyr-6ffaef35cf667d0e2e14227882a1a8e329b2c2c2.zip
Manually merged PR #1607
Diffstat (limited to 'src')
-rw-r--r--src/js/config/defaults.js2
-rw-r--r--src/js/html5.js70
2 files changed, 42 insertions, 30 deletions
diff --git a/src/js/config/defaults.js b/src/js/config/defaults.js
index 197554a2..969c78d1 100644
--- a/src/js/config/defaults.js
+++ b/src/js/config/defaults.js
@@ -70,6 +70,8 @@ const defaults = {
quality: {
default: 576,
options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240],
+ forced: false,
+ onChange: null,
},
// Set loops
diff --git a/src/js/html5.js b/src/js/html5.js
index b03e9c26..a0825cf6 100644
--- a/src/js/html5.js
+++ b/src/js/html5.js
@@ -30,6 +30,11 @@ const html5 = {
// Get quality levels
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
return html5.getSources
.call(this)
@@ -60,36 +65,41 @@ const html5 = {
return source && Number(source.getAttribute('size'));
},
set(input) {
- // 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
- if (!source) {
- return;
- }
-
- // Get current state
- const { currentTime, paused, preload, readyState } = player.media;
-
- // Set new source
- player.media.src = source.getAttribute('src');
-
- // Prevent loading if preload="none" and the current source isn't loaded (#1044)
- if (preload !== 'none' || readyState) {
- // Restore time
- player.once('loadedmetadata', () => {
- player.currentTime = currentTime;
-
- // Resume playing
- if (!paused) {
- player.play();
- }
- });
-
- // Load new source
- player.media.load();
+ // If we're using an an external handler...
+ if (player.config.quality.forced && is.function(player.config.quality.onChange)) {
+ player.config.quality.onChange(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
+ if (!source) {
+ return;
+ }
+
+ // Get current state
+ const { currentTime, paused, preload, readyState } = player.media;
+
+ // Set new source
+ player.media.src = source.getAttribute('src');
+
+ // Prevent loading if preload="none" and the current source isn't loaded (#1044)
+ if (preload !== 'none' || readyState) {
+ // Restore time
+ player.once('loadedmetadata', () => {
+ player.currentTime = currentTime;
+
+ // Resume playing
+ if (!paused) {
+ player.play();
+ }
+ });
+
+ // Load new source
+ player.media.load();
+ }
}
// Trigger change event