aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/plyr.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-03-17 23:27:40 +1100
committerSam Potts <sam@potts.es>2018-03-17 23:27:40 +1100
commit5db73b13276bf50357cc98896421318de66ab042 (patch)
treeae7d43ee753035458e5927b66eb588ff26d58afd /src/js/plyr.js
parent5cb1628cd8f9d58b97bf1bf774ff89f61ceb31d5 (diff)
downloadplyr-5db73b13276bf50357cc98896421318de66ab042.tar.lz
plyr-5db73b13276bf50357cc98896421318de66ab042.tar.xz
plyr-5db73b13276bf50357cc98896421318de66ab042.zip
Added buffered getter
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r--src/js/plyr.js59
1 files changed, 42 insertions, 17 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 32c8c062..00b7a007 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -293,22 +293,22 @@ class Plyr {
* Types and provider helpers
*/
get isHTML5() {
- return this.provider === providers.html5;
+ return Boolean(this.provider === providers.html5);
}
get isEmbed() {
- return this.isYouTube || this.isVimeo;
+ return Boolean(this.isYouTube || this.isVimeo);
}
get isYouTube() {
- return this.provider === providers.youtube;
+ return Boolean(this.provider === providers.youtube);
}
get isVimeo() {
- return this.provider === providers.vimeo;
+ return Boolean(this.provider === providers.vimeo);
}
get isVideo() {
- return this.type === types.video;
+ return Boolean(this.type === types.video);
}
get isAudio() {
- return this.type === types.audio;
+ return Boolean(this.type === types.audio);
}
/**
@@ -339,21 +339,21 @@ class Plyr {
* Get paused state
*/
get paused() {
- return this.media.paused;
+ return Boolean(this.media.paused);
}
/**
* Get playing state
*/
get playing() {
- return !this.paused && !this.ended && (this.isHTML5 ? this.media.readyState > 2 : true);
+ return Boolean(!this.paused && !this.ended && (this.isHTML5 ? this.media.readyState > 2 : true));
}
/**
* Get ended state
*/
get ended() {
- return this.media.ended;
+ return Boolean(this.media.ended);
}
/**
@@ -435,10 +435,31 @@ class Plyr {
}
/**
+ * Get buffered
+ */
+ get buffered() {
+ const { buffered } = this.media;
+
+ // YouTube / Vimeo return a float between 0-1
+ if (utils.is.number(buffered)) {
+ return buffered;
+ }
+
+ // HTML5
+ // TODO: Handle buffered chunks of the media
+ // (i.e. seek to another section buffers only that section)
+ if (buffered && buffered.length && this.duration > 0) {
+ return buffered.end(0) / this.duration;
+ }
+
+ return 0;
+ }
+
+ /**
* Get seeking status
*/
get seeking() {
- return this.media.seeking;
+ return Boolean(this.media.seeking);
}
/**
@@ -503,7 +524,7 @@ class Plyr {
* Get the current player volume
*/
get volume() {
- return this.media.volume;
+ return Number(this.media.volume);
}
/**
@@ -552,7 +573,7 @@ class Plyr {
* Get current muted state
*/
get muted() {
- return this.media.muted;
+ return Boolean(this.media.muted);
}
/**
@@ -569,12 +590,16 @@ class Plyr {
}
// Get audio tracks
- return this.media.mozHasAudio || Boolean(this.media.webkitAudioDecodedByteCount) || Boolean(this.media.audioTracks && this.media.audioTracks.length);
+ return (
+ Boolean(this.media.mozHasAudio) ||
+ Boolean(this.media.webkitAudioDecodedByteCount) ||
+ Boolean(this.media.audioTracks && this.media.audioTracks.length)
+ );
}
/**
* Set playback speed
- * @param {decimal} speed - the speed of playback (0.5-2.0)
+ * @param {number} speed - the speed of playback (0.5-2.0)
*/
set speed(input) {
let speed = null;
@@ -615,7 +640,7 @@ class Plyr {
* Get current playback speed
*/
get speed() {
- return this.media.playbackRate;
+ return Number(this.media.playbackRate);
}
/**
@@ -715,7 +740,7 @@ class Plyr {
* Get current loop state
*/
get loop() {
- return this.media.loop;
+ return Boolean(this.media.loop);
}
/**
@@ -772,7 +797,7 @@ class Plyr {
* Get the current autoplay state
*/
get autoplay() {
- return this.config.autoplay;
+ return Boolean(this.config.autoplay);
}
/**