diff options
author | Sam Potts <sam@potts.es> | 2020-01-30 14:23:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-30 14:23:40 +0000 |
commit | 58f5380694993891892e4e24ba0904434892e538 (patch) | |
tree | 4de3d7b46d33192a43a0b40c3f3a9a5f90f9b071 /src/js/html5.js | |
parent | 9d512911252cf4835c2b7364cb4ae392cb277a1d (diff) | |
parent | fefcca78052174dce73f8dfe7df5b264edb0653a (diff) | |
download | plyr-58f5380694993891892e4e24ba0904434892e538.tar.lz plyr-58f5380694993891892e4e24ba0904434892e538.tar.xz plyr-58f5380694993891892e4e24ba0904434892e538.zip |
Merge pull request #1662 from sampotts/develop
3.5.7
Diffstat (limited to 'src/js/html5.js')
-rw-r--r-- | src/js/html5.js | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/src/js/html5.js b/src/js/html5.js index b03e9c26..1173bcbe 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,45 @@ 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', () => { + if (player.currentTime === 0) { + return; + } + + player.currentTime = currentTime; + + // Resume playing + if (!paused) { + player.play(); + } + }); + + // Load new source + player.media.load(); + } } // Trigger change event |