aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/plyr.js
diff options
context:
space:
mode:
authorAlbin Larsson <mail@albinlarsson.com>2018-05-28 00:33:17 +0200
committerAlbin Larsson <mail@albinlarsson.com>2018-05-28 00:57:07 +0200
commitfac8a185ba4a945ba33a45cdfd0dd55c53edf532 (patch)
tree6b25cd8141de850ccb07b1ef91fe908018789440 /src/js/plyr.js
parentc69aa8a42b7f55276d35bf64a08e869654c3b0ce (diff)
downloadplyr-fac8a185ba4a945ba33a45cdfd0dd55c53edf532.tar.lz
plyr-fac8a185ba4a945ba33a45cdfd0dd55c53edf532.tar.xz
plyr-fac8a185ba4a945ba33a45cdfd0dd55c53edf532.zip
Simplify currentTime setter and bail when media hasn't loaded
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r--src/js/plyr.js17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 21c00fd3..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`);