aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2016-05-01 12:00:37 +1000
committerSam Potts <me@sampotts.me>2016-05-01 12:00:37 +1000
commit44bb6c077c25dab701548bff98682f61c9d80d6e (patch)
tree59a50c459a673db3e20b621f74cf72ca9fb46e57 /src
parente11a58a841ca7d2e0f92beaa1f2dc78bb85d0251 (diff)
downloadplyr-44bb6c077c25dab701548bff98682f61c9d80d6e.tar.lz
plyr-44bb6c077c25dab701548bff98682f61c9d80d6e.tar.xz
plyr-44bb6c077c25dab701548bff98682f61c9d80d6e.zip
Fixed merge
Diffstat (limited to 'src')
-rw-r--r--src/js/plyr.js99
1 files changed, 75 insertions, 24 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 9dfaf7e0..3b89d6fe 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -42,6 +42,7 @@
iconUrl: '',
clickToPlay: true,
hideControls: true,
+ showPosterOnEnd: false,
tooltips: {
controls: false,
seek: true
@@ -1827,9 +1828,9 @@
// Seek to time
// The input parameter can be an event or a number
function _seek(input) {
- var targetTime = 0,
- paused = plyr.media.paused,
- duration = _getDuration();
+ var targetTime = 0,
+ paused = plyr.media.paused,
+ duration = _getDuration();
// Explicit position
if (typeof input === 'number') {
@@ -1850,10 +1851,8 @@
targetTime = duration;
}
- // Update progress
- if (plyr.progress && plyr.progress.played) {
- plyr.progress.played.value = ((100 / duration) * targetTime);
- }
+ // Update seek range and progress
+ _updateSeekDisplay(targetTime);
// Set the current time
// Try/catch incase the media isn't set and we're calling seek() from source() and IE moans
@@ -1901,10 +1900,18 @@
// Get the duration (or custom if set)
function _getDuration() {
// It should be a number, but parse it just incase
- var duration = parseInt(config.duration);
+ var duration = parseInt(config.duration),
+
+ // True duration
+ mediaDuration = 0;
+
+ // Only if duration available
+ if(plyr.media.duration !== null && !isNaN(plyr.media.duration)) {
+ mediaDuration = plyr.media.duration;
+ }
// If custom duration is funky, use regular duration
- return (isNaN(duration) ? plyr.media.duration : duration);
+ return (isNaN(duration) ? mediaDuration : duration);
}
// Check playing state
@@ -2156,7 +2163,6 @@
// Update <progress> elements
function _updateProgress(event) {
var progress = plyr.progress.played,
- text = false,
value = 0,
duration = _getDuration();
@@ -2177,8 +2183,7 @@
// Check buffer status
case 'playing':
case 'progress':
- progress = plyr.progress.buffer.bar;
- text = plyr.progress.buffer.text;
+ progress = plyr.progress.buffer;
value = (function() {
var buffered = plyr.media.buffered;
@@ -2199,11 +2204,27 @@
}
// Set values
- if (progress) {
+ _setProgress(progress, value);
+ }
+
+ // Set <progress> value
+ function _setProgress(progress, value) {
+ if (typeof value === 'undefined') {
+ value = 0;
+ }
+
+ // One progress element passed
+ if (progress instanceof HTMLElement) {
progress.value = value;
}
- if (text) {
- text.innerHTML = value;
+ // Object of progress + text element
+ else {
+ if (progress.bar) {
+ progress.bar.value = value;
+ }
+ if (progress.text) {
+ progress.text.innerHTML = value;
+ }
}
}
@@ -2271,10 +2292,33 @@
_updateProgress(event);
}
+ // Update seek range and progress
+ function _updateSeekDisplay(time) {
+ // Default to 0
+ if (typeof time !== 'number') {
+ time = 0;
+ }
+
+ var duration = _getDuration(),
+ value = _getPercentage(time, duration);
+
+ // Update progress
+ if (plyr.progress && plyr.progress.played) {
+ plyr.progress.played.value = value;
+ }
+
+ // Update seek range input
+ if (plyr.buttons && plyr.buttons.seek) {
+ plyr.buttons.seek.value = value;
+ }
+ }
+
// Update hover tooltip for seeking
function _updateSeekTooltip(event) {
+ var duration = _getDuration();
+
// Bail if setting not true
- if (!config.tooltips.seek || plyr.browser.touch || !plyr.progress.container) {
+ if (!config.tooltips.seek || !plyr.progress.container || duration === 0) {
return;
}
@@ -2305,7 +2349,7 @@
}
// Display the time a click would seek to
- _updateTimeDisplay(((_getDuration() / 100) * percent), plyr.progress.tooltip);
+ _updateTimeDisplay(((duration / 100) * percent), plyr.progress.tooltip);
// Set position
plyr.progress.tooltip.style.left = percent + "%";
@@ -2423,13 +2467,11 @@
// Pause playback
_pause();
- // Set seek input to 0
- if (plyr.buttons && plyr.buttons.seek) {
- plyr.buttons.seek.value = 0;
- }
- if (plyr.progress && plyr.progress.played) {
- plyr.progress.played.value = 0;
- }
+ // Update seek range and progress
+ _updateSeekDisplay();
+
+ // Reset buffer progress
+ _setProgress(plyr.progress.buffer);
// Cancel current network requests
_cancelRequests();
@@ -2722,6 +2764,15 @@
// Reset UI
_checkPlaying();
+
+ // Show poster on end
+ if(config.showPosterOnEnd) {
+ // Seek to 0
+ _seek(0);
+
+ // Re-load media
+ plyr.media.load();
+ }
});
// Check for buffer progress