diff options
author | Sam Potts <sam@potts.es> | 2018-05-28 10:08:24 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-28 10:08:24 +1000 |
commit | 14b6309aef298a2662e694902d84dda2bc573ba9 (patch) | |
tree | 6b25cd8141de850ccb07b1ef91fe908018789440 /src/js | |
parent | cd51788b980a7bc7b5caaf2d595d2077be4138f5 (diff) | |
parent | fac8a185ba4a945ba33a45cdfd0dd55c53edf532 (diff) | |
download | plyr-14b6309aef298a2662e694902d84dda2bc573ba9.tar.lz plyr-14b6309aef298a2662e694902d84dda2bc573ba9.tar.xz plyr-14b6309aef298a2662e694902d84dda2bc573ba9.zip |
Merge pull request #978 from friday/ie-issues
Fix InvalidStateError and IE11 issues
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/plyr.js | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index 4c984fd7..34b618bd 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -432,21 +432,16 @@ class Plyr { * @param {number} input - where to seek to in seconds. Defaults to 0 (the start) */ set currentTime(input) { - let targetTime = 0; - - if (utils.is.number(input)) { - targetTime = input; + // Bail if media duration isn't available yet + if (!this.duration) { + return; } - // Normalise targetTime - if (targetTime < 0) { - targetTime = 0; - } else if (targetTime > this.duration) { - targetTime = this.duration; - } + // Validate input + const inputIsValid = utils.is.number(input) && input > 0; // Set - this.media.currentTime = targetTime; + this.media.currentTime = inputIsValid ? Math.min(input, this.duration) : 0; // Logging this.debug.log(`Seeking to ${this.currentTime} seconds`); @@ -494,11 +489,11 @@ class Plyr { // Faux duration set via config const fauxDuration = parseFloat(this.config.duration); - // True duration - const realDuration = this.media ? Number(this.media.duration) : 0; + // Media duration can be NaN before the media has loaded + const duration = (this.media || {}).duration || 0; - // If custom duration is funky, use regular duration - return !Number.isNaN(fauxDuration) ? fauxDuration : realDuration; + // If config duration is funky, use regular duration + return fauxDuration || duration; } /** |