Compare commits

..

10 Commits

Author SHA1 Message Date
3bccc0da01 v3.0.0 2018-03-17 23:33:25 +11:00
a0173d991e Removed beta message 2018-03-17 23:31:34 +11:00
600f0eb8a3 Merge branch 'beta'
# Conflicts:
#	readme.md
2018-03-17 23:30:16 +11:00
5db73b1327 Added buffered getter 2018-03-17 23:27:40 +11:00
5cb1628cd8 Vimeo fix 2018-03-15 10:29:05 +11:00
c74b75e8e1 3.0.0-beta.20 2018-03-13 23:35:17 +11:00
e0562752ea Merge pull request #795 from frogg/patch-1
Added link that explains Webkit's autoplay blocker
2018-03-10 23:29:22 +11:00
e6db374a72 Added link that explains Webkit's autoplay blocker 2018-02-24 16:19:55 +01:00
ab7f277a1b Merge pull request #769 from redxtech/add-vue-plyr-to-readme
Add vue-plyr to readme
2018-02-06 10:51:42 +11:00
d5a1a7ca1c Add vue-plyr to readme 2018-01-28 23:03:05 -07:00
28 changed files with 685 additions and 658 deletions

2
demo/dist/demo.css vendored

File diff suppressed because one or more lines are too long

3
demo/dist/demo.js vendored
View File

@ -55,7 +55,8 @@ document.addEventListener('DOMContentLoaded', function () {
google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c' google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c'
}, },
ads: { ads: {
enabled: true enabled: true,
publisherId: '918848828995742'
} }
}); });

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
!function(){"use strict";var e,t,o,i,r,a;document.addEventListener("DOMContentLoaded",function(){window.shr&&window.shr.setup({count:{classname:"button__count"}});document.addEventListener("focusout",function(e){e.target.classList.remove("tab-focus")}),document.addEventListener("keydown",function(e){9===e.keyCode&&setTimeout(function(){document.activeElement.classList.add("tab-focus")},0)});var e=new Plyr("#player",{debug:!0,title:"View From A Blue Moon",iconUrl:"../dist/plyr.svg",keyboard:{global:!0},tooltips:{controls:!0},captions:{active:!0},keys:{google:"AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c"},ads:{enabled:!0}});window.player=e;var t=document.querySelectorAll("[data-source]"),o={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},i=window.location.hash.replace("#",""),r=window.history&&window.history.pushState;function a(e,t,o){e&&e.classList[o?"add":"remove"](t)}function n(r,n){if(r in o&&(n||r!==i)&&(i.length||r!==o.video)){switch(r){case o.video:e.source={type:"video",title:"View From A Blue Moon",sources:[{src:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.mp4",type:"video/mp4"}],poster:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg",tracks:[{kind:"captions",label:"English",srclang:"en",src:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt",default:!0},{kind:"captions",label:"French",srclang:"fr",src:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt"}]};break;case o.audio:e.source={type:"audio",title:"Kishi Bashi – “It All Began With A Burst”",sources:[{src:"https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3",type:"audio/mp3"},{src:"https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg",type:"audio/ogg"}]};break;case o.youtube:e.source={type:"video",title:"View From A Blue Moon",sources:[{src:"https://youtube.com/watch?v=bTqVqk7FSmY",provider:"youtube"}]};break;case o.vimeo:e.source={type:"video",sources:[{src:"https://vimeo.com/76979871",provider:"vimeo"}]}}i=r,Array.from(t).forEach(function(e){return a(e.parentElement,"active",!1)}),a(document.querySelector('[data-source="'+r+'"]'),"active",!0),Array.from(document.querySelectorAll(".plyr__cite")).forEach(function(e){e.setAttribute("hidden","")}),document.querySelector(".plyr__cite--"+r).removeAttribute("hidden")}}if(Array.from(t).forEach(function(e){e.addEventListener("click",function(){var t=e.getAttribute("data-source");n(t),r&&window.history.pushState({type:t},"","#"+t)})}),window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&n(e.state.type)}),r){var s=!i.length;s&&(i=o.video),i in o&&window.history.replaceState({type:i},"",s?"":"#"+i),i!==o.video&&n(i,!0)}}),"plyr.io"===window.location.host&&(e=window,t=document,o="script",i="ga",e.GoogleAnalyticsObject=i,e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,r=t.createElement(o),a=t.getElementsByTagName(o)[0],r.async=1,r.src="https://www.google-analytics.com/analytics.js",a.parentNode.insertBefore(r,a),window.ga("create","UA-40881672-11","auto"),window.ga("send","pageview"))}(); !function(){"use strict";var e,t,o,i,r,a;document.addEventListener("DOMContentLoaded",function(){window.shr&&window.shr.setup({count:{classname:"button__count"}});document.addEventListener("focusout",function(e){e.target.classList.remove("tab-focus")}),document.addEventListener("keydown",function(e){9===e.keyCode&&setTimeout(function(){document.activeElement.classList.add("tab-focus")},0)});var e=new Plyr("#player",{debug:!0,title:"View From A Blue Moon",iconUrl:"../dist/plyr.svg",keyboard:{global:!0},tooltips:{controls:!0},captions:{active:!0},keys:{google:"AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c"},ads:{enabled:!0,publisherId:"918848828995742"}});window.player=e;var t=document.querySelectorAll("[data-source]"),o={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},i=window.location.hash.replace("#",""),r=window.history&&window.history.pushState;function a(e,t,o){e&&e.classList[o?"add":"remove"](t)}function n(r,n){if(r in o&&(n||r!==i)&&(i.length||r!==o.video)){switch(r){case o.video:e.source={type:"video",title:"View From A Blue Moon",sources:[{src:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.mp4",type:"video/mp4"}],poster:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg",tracks:[{kind:"captions",label:"English",srclang:"en",src:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt",default:!0},{kind:"captions",label:"French",srclang:"fr",src:"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt"}]};break;case o.audio:e.source={type:"audio",title:"Kishi Bashi – “It All Began With A Burst”",sources:[{src:"https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3",type:"audio/mp3"},{src:"https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg",type:"audio/ogg"}]};break;case o.youtube:e.source={type:"video",title:"View From A Blue Moon",sources:[{src:"https://youtube.com/watch?v=bTqVqk7FSmY",provider:"youtube"}]};break;case o.vimeo:e.source={type:"video",sources:[{src:"https://vimeo.com/76979871",provider:"vimeo"}]}}i=r,Array.from(t).forEach(function(e){return a(e.parentElement,"active",!1)}),a(document.querySelector('[data-source="'+r+'"]'),"active",!0),Array.from(document.querySelectorAll(".plyr__cite")).forEach(function(e){e.setAttribute("hidden","")}),document.querySelector(".plyr__cite--"+r).removeAttribute("hidden")}}if(Array.from(t).forEach(function(e){e.addEventListener("click",function(){var t=e.getAttribute("data-source");n(t),r&&window.history.pushState({type:t},"","#"+t)})}),window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&n(e.state.type)}),r){var s=!i.length;s&&(i=o.video),i in o&&window.history.replaceState({type:i},"",s?"":"#"+i),i!==o.video&&n(i,!0)}}),"plyr.io"===window.location.host&&(e=window,t=document,o="script",i="ga",e.GoogleAnalyticsObject=i,e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,r=t.createElement(o),a=t.getElementsByTagName(o)[0],r.async=1,r.src="https://www.google-analytics.com/analytics.js",a.parentNode.insertBefore(r,a),window.ga("create","UA-40881672-11","auto"),window.ga("send","pageview"))}();
//# sourceMappingURL=demo.min.js.map //# sourceMappingURL=demo.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -53,6 +53,7 @@ document.addEventListener('DOMContentLoaded', () => {
}, },
ads: { ads: {
enabled: true, enabled: true,
publisherId: '918848828995742',
}, },
}); });

2
dist/plyr.css vendored

File diff suppressed because one or more lines are too long

153
dist/plyr.js vendored
View File

@ -77,7 +77,7 @@ var defaults = {
// Sprite (for icons) // Sprite (for icons)
loadSprite: true, loadSprite: true,
iconPrefix: 'plyr', iconPrefix: 'plyr',
iconUrl: 'https://cdn.plyr.io/3.0.0-beta.19/plyr.svg', iconUrl: 'https://cdn.plyr.io/3.0.0-beta.20/plyr.svg',
// Blank video (used to prevent errors on source change) // Blank video (used to prevent errors on source change)
blankVideo: 'https://cdn.plyr.io/static/blank.mp4', blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
@ -326,7 +326,7 @@ var defaults = {
// Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio // Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
ads: { ads: {
enabled: false, enabled: false,
publisherId: '918848828995742' publisherId: ''
} }
}; };
@ -1260,6 +1260,7 @@ var utils = {
if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) { if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) {
return 0; return 0;
} }
return (current / max * 100).toFixed(2); return (current / max * 100).toFixed(2);
}, },
@ -1511,13 +1512,9 @@ var support = {
break; break;
case 'youtube:video': case 'youtube:video':
api = true;
ui = support.rangeInput && (!browser.isIPhone || playsInline);
break;
case 'vimeo:video': case 'vimeo:video':
api = true; api = true;
ui = support.rangeInput && !browser.isIPhone; ui = support.rangeInput && (!browser.isIPhone || playsInline);
break; break;
default: default:
@ -2179,7 +2176,7 @@ var ui = {
var _this = this; var _this = this;
// Re-attach media element listeners // Re-attach media element listeners
// TODO: Use event bubbling // TODO: Use event bubbling?
this.listeners.media(); this.listeners.media();
// Don't setup interface if no support // Don't setup interface if no support
@ -2398,8 +2395,6 @@ var ui = {
// Update <progress> elements // Update <progress> elements
updateProgress: function updateProgress(event) { updateProgress: function updateProgress(event) {
var _this4 = this;
if (!this.supported.ui || !utils.is.event(event)) { if (!this.supported.ui || !utils.is.event(event)) {
return; return;
} }
@ -2423,22 +2418,7 @@ var ui = {
// Check buffer status // Check buffer status
case 'playing': case 'playing':
case 'progress': case 'progress':
value = function () { ui.setProgress.call(this, this.elements.display.buffer, this.buffered * 100);
var buffered = _this4.media.buffered;
if (buffered && buffered.length) {
// HTML5
return utils.getPercentage(buffered.end(0), _this4.duration);
} else if (utils.is.number(buffered)) {
// YouTube returns between 0 and 1
return buffered * 100;
}
return 0;
}();
ui.setProgress.call(this, this.elements.display.buffer, value);
break; break;
@ -3883,7 +3863,9 @@ var Listeners = function () {
}, { }, {
key: 'global', key: 'global',
value: function global(toggle) { value: function global() {
var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
// Keyboard shortcuts // Keyboard shortcuts
if (this.player.config.keyboard.global) { if (this.player.config.keyboard.global) {
utils.toggleListener(window, 'keydown keyup', this.handleKey, toggle, false); utils.toggleListener(window, 'keydown keyup', this.handleKey, toggle, false);
@ -4294,6 +4276,14 @@ var Listeners = function () {
}); });
}, false); }, false);
} }
// Reset on destroy
}, {
key: 'clear',
value: function clear() {
this.global(false);
}
}]); }]);
return Listeners; return Listeners;
}(); }();
@ -4565,7 +4555,7 @@ var Ads = function () {
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (!start) { if (!start) {
window.clearInterval(this.countdownTimer); clearInterval(this.countdownTimer);
this.elements.container.removeAttribute('data-badge-text'); this.elements.container.removeAttribute('data-badge-text');
return; return;
} }
@ -4576,7 +4566,7 @@ var Ads = function () {
_this5.elements.container.setAttribute('data-badge-text', label); _this5.elements.container.setAttribute('data-badge-text', label);
}; };
this.countdownTimer = window.setInterval(update, 100); this.countdownTimer = setInterval(update, 100);
} }
/** /**
@ -5351,10 +5341,10 @@ var youtube = {
utils.dispatchEvent.call(player, player.media, 'durationchange'); utils.dispatchEvent.call(player, player.media, 'durationchange');
// Reset timer // Reset timer
window.clearInterval(player.timers.buffering); clearInterval(player.timers.buffering);
// Setup buffering // Setup buffering
player.timers.buffering = window.setInterval(function () { player.timers.buffering = setInterval(function () {
// Get loaded % from YouTube // Get loaded % from YouTube
player.media.buffered = instance.getVideoLoadedFraction(); player.media.buffered = instance.getVideoLoadedFraction();
@ -5368,7 +5358,7 @@ var youtube = {
// Bail if we're at 100% // Bail if we're at 100%
if (player.media.buffered === 1) { if (player.media.buffered === 1) {
window.clearInterval(player.timers.buffering); clearInterval(player.timers.buffering);
// Trigger event // Trigger event
utils.dispatchEvent.call(player, player.media, 'canplaythrough'); utils.dispatchEvent.call(player, player.media, 'canplaythrough');
@ -5385,7 +5375,7 @@ var youtube = {
var instance = event.target; var instance = event.target;
// Reset timer // Reset timer
window.clearInterval(player.timers.playing); clearInterval(player.timers.playing);
// Handle events // Handle events
// -1 Unstarted // -1 Unstarted
@ -5425,7 +5415,7 @@ var youtube = {
utils.dispatchEvent.call(player, player.media, 'playing'); utils.dispatchEvent.call(player, player.media, 'playing');
// Poll to get playback progress // Poll to get playback progress
player.timers.playing = window.setInterval(function () { player.timers.playing = setInterval(function () {
utils.dispatchEvent.call(player, player.media, 'timeupdate'); utils.dispatchEvent.call(player, player.media, 'timeupdate');
}, 50); }, 50);
@ -6031,7 +6021,7 @@ var source = {
// ========================================================================== // ==========================================================================
// Plyr // Plyr
// plyr.js v3.0.0-beta.19 // plyr.js v3.0.0-beta.20
// https://github.com/sampotts/plyr // https://github.com/sampotts/plyr
// License: The MIT License (MIT) // License: The MIT License (MIT)
// ========================================================================== // ==========================================================================
@ -6287,7 +6277,7 @@ var Plyr = function () {
this.listeners.container(); this.listeners.container();
// Global listeners // Global listeners
this.listeners.global(true); this.listeners.global();
// Setup fullscreen // Setup fullscreen
this.fullscreen = new Fullscreen(this); this.fullscreen = new Fullscreen(this);
@ -6547,7 +6537,7 @@ var Plyr = function () {
} }
// Clear timer on every call // Clear timer on every call
window.clearTimeout(this.timers.controls); clearTimeout(this.timers.controls);
// If the mouse is not over the controls, set a timeout to hide them // If the mouse is not over the controls, set a timeout to hide them
if (show || this.paused || this.loading) { if (show || this.paused || this.loading) {
@ -6638,6 +6628,10 @@ var Plyr = function () {
var soft = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var soft = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (!this.ready) {
return;
}
var done = function done() { var done = function done() {
// Reset overflow (incase destroyed while in fullscreen) // Reset overflow (incase destroyed while in fullscreen)
document.body.style.overflow = ''; document.body.style.overflow = '';
@ -6666,12 +6660,12 @@ var Plyr = function () {
callback(); callback();
} }
} else { } else {
// Unbind listeners
_this4.listeners.clear();
// Replace the container with the original element provided // Replace the container with the original element provided
utils.replaceElement(_this4.elements.original, _this4.elements.container); utils.replaceElement(_this4.elements.original, _this4.elements.container);
// Unbind global listeners
_this4.listeners.global(false);
// Event // Event
utils.dispatchEvent.call(_this4, _this4.elements.original, 'destroyed', true); utils.dispatchEvent.call(_this4, _this4.elements.original, 'destroyed', true);
@ -6680,15 +6674,27 @@ var Plyr = function () {
callback.call(_this4.elements.original); callback.call(_this4.elements.original);
} }
// Clear for GC // Reset state
_this4.elements = null; _this4.ready = false;
// Clear for garbage collection
setTimeout(function () {
_this4.elements = null;
_this4.media = null;
}, 200);
} }
}; };
// Stop playback
this.stop();
// Type specific stuff // Type specific stuff
switch (this.provider + ':' + this.type) { switch (this.provider + ':' + this.type) {
case 'html5:video': case 'html5:video':
case 'html5:audio': case 'html5:audio':
// Clear timeout
clearTimeout(this.timers.loading);
// Restore native video controls // Restore native video controls
ui.toggleNativeControls.call(this, true); ui.toggleNativeControls.call(this, true);
@ -6699,8 +6705,8 @@ var Plyr = function () {
case 'youtube:video': case 'youtube:video':
// Clear timers // Clear timers
window.clearInterval(this.timers.buffering); clearInterval(this.timers.buffering);
window.clearInterval(this.timers.playing); clearInterval(this.timers.playing);
// Destroy YouTube API // Destroy YouTube API
if (this.embed !== null) { if (this.embed !== null) {
@ -6750,37 +6756,37 @@ var Plyr = function () {
}, { }, {
key: 'isHTML5', key: 'isHTML5',
get: function get$$1() { get: function get$$1() {
return this.provider === providers.html5; return Boolean(this.provider === providers.html5);
} }
}, { }, {
key: 'isEmbed', key: 'isEmbed',
get: function get$$1() { get: function get$$1() {
return this.isYouTube || this.isVimeo; return Boolean(this.isYouTube || this.isVimeo);
} }
}, { }, {
key: 'isYouTube', key: 'isYouTube',
get: function get$$1() { get: function get$$1() {
return this.provider === providers.youtube; return Boolean(this.provider === providers.youtube);
} }
}, { }, {
key: 'isVimeo', key: 'isVimeo',
get: function get$$1() { get: function get$$1() {
return this.provider === providers.vimeo; return Boolean(this.provider === providers.vimeo);
} }
}, { }, {
key: 'isVideo', key: 'isVideo',
get: function get$$1() { get: function get$$1() {
return this.type === types.video; return Boolean(this.type === types.video);
} }
}, { }, {
key: 'isAudio', key: 'isAudio',
get: function get$$1() { get: function get$$1() {
return this.type === types.audio; return Boolean(this.type === types.audio);
} }
}, { }, {
key: 'paused', key: 'paused',
get: function get$$1() { get: function get$$1() {
return this.media.paused; return Boolean(this.media.paused);
} }
/** /**
@ -6790,7 +6796,7 @@ var Plyr = function () {
}, { }, {
key: 'playing', key: 'playing',
get: function get$$1() { get: function get$$1() {
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));
} }
/** /**
@ -6800,7 +6806,7 @@ var Plyr = function () {
}, { }, {
key: 'ended', key: 'ended',
get: function get$$1() { get: function get$$1() {
return this.media.ended; return Boolean(this.media.ended);
} }
}, { }, {
key: 'currentTime', key: 'currentTime',
@ -6833,6 +6839,31 @@ var Plyr = function () {
return Number(this.media.currentTime); return Number(this.media.currentTime);
} }
/**
* Get buffered
*/
}, {
key: 'buffered',
get: function get$$1() {
var buffered = this.media.buffered;
// 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 status
*/ */
@ -6840,7 +6871,7 @@ var Plyr = function () {
}, { }, {
key: 'seeking', key: 'seeking',
get: function get$$1() { get: function get$$1() {
return this.media.seeking; return Boolean(this.media.seeking);
} }
/** /**
@ -6912,7 +6943,7 @@ var Plyr = function () {
*/ */
, ,
get: function get$$1() { get: function get$$1() {
return this.media.volume; return Number(this.media.volume);
} }
}, { }, {
key: 'muted', key: 'muted',
@ -6941,7 +6972,7 @@ var Plyr = function () {
*/ */
, ,
get: function get$$1() { get: function get$$1() {
return this.media.muted; return Boolean(this.media.muted);
} }
/** /**
@ -6961,12 +6992,12 @@ var Plyr = function () {
} }
// Get audio tracks // 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 * 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)
*/ */
}, { }, {
@ -7011,7 +7042,7 @@ var Plyr = function () {
*/ */
, ,
get: function get$$1() { get: function get$$1() {
return this.media.playbackRate; return Number(this.media.playbackRate);
} }
/** /**
@ -7114,7 +7145,7 @@ var Plyr = function () {
*/ */
, ,
get: function get$$1() { get: function get$$1() {
return this.media.loop; return Boolean(this.media.loop);
} }
/** /**
@ -7183,7 +7214,7 @@ var Plyr = function () {
*/ */
, ,
get: function get$$1() { get: function get$$1() {
return this.config.autoplay; return Boolean(this.config.autoplay);
} }
}, { }, {
key: 'language', key: 'language',

2
dist/plyr.js.map vendored

File diff suppressed because one or more lines are too long

2
dist/plyr.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5268,7 +5268,7 @@ var defaults = {
// Sprite (for icons) // Sprite (for icons)
loadSprite: true, loadSprite: true,
iconPrefix: 'plyr', iconPrefix: 'plyr',
iconUrl: 'https://cdn.plyr.io/3.0.0-beta.19/plyr.svg', iconUrl: 'https://cdn.plyr.io/3.0.0/plyr.svg',
// Blank video (used to prevent errors on source change) // Blank video (used to prevent errors on source change)
blankVideo: 'https://cdn.plyr.io/static/blank.mp4', blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
@ -5517,7 +5517,7 @@ var defaults = {
// Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio // Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
ads: { ads: {
enabled: false, enabled: false,
publisherId: '918848828995742' publisherId: ''
} }
}; };
@ -6451,6 +6451,7 @@ var utils = {
if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) { if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) {
return 0; return 0;
} }
return (current / max * 100).toFixed(2); return (current / max * 100).toFixed(2);
}, },
@ -6702,13 +6703,9 @@ var support = {
break; break;
case 'youtube:video': case 'youtube:video':
api = true;
ui = support.rangeInput && (!browser.isIPhone || playsInline);
break;
case 'vimeo:video': case 'vimeo:video':
api = true; api = true;
ui = support.rangeInput && !browser.isIPhone; ui = support.rangeInput && (!browser.isIPhone || playsInline);
break; break;
default: default:
@ -7370,7 +7367,7 @@ var ui = {
var _this = this; var _this = this;
// Re-attach media element listeners // Re-attach media element listeners
// TODO: Use event bubbling // TODO: Use event bubbling?
this.listeners.media(); this.listeners.media();
// Don't setup interface if no support // Don't setup interface if no support
@ -7589,8 +7586,6 @@ var ui = {
// Update <progress> elements // Update <progress> elements
updateProgress: function updateProgress(event) { updateProgress: function updateProgress(event) {
var _this4 = this;
if (!this.supported.ui || !utils.is.event(event)) { if (!this.supported.ui || !utils.is.event(event)) {
return; return;
} }
@ -7614,22 +7609,7 @@ var ui = {
// Check buffer status // Check buffer status
case 'playing': case 'playing':
case 'progress': case 'progress':
value = function () { ui.setProgress.call(this, this.elements.display.buffer, this.buffered * 100);
var buffered = _this4.media.buffered;
if (buffered && buffered.length) {
// HTML5
return utils.getPercentage(buffered.end(0), _this4.duration);
} else if (utils.is.number(buffered)) {
// YouTube returns between 0 and 1
return buffered * 100;
}
return 0;
}();
ui.setProgress.call(this, this.elements.display.buffer, value);
break; break;
@ -9074,7 +9054,9 @@ var Listeners = function () {
}, { }, {
key: 'global', key: 'global',
value: function global(toggle) { value: function global() {
var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
// Keyboard shortcuts // Keyboard shortcuts
if (this.player.config.keyboard.global) { if (this.player.config.keyboard.global) {
utils.toggleListener(window, 'keydown keyup', this.handleKey, toggle, false); utils.toggleListener(window, 'keydown keyup', this.handleKey, toggle, false);
@ -9485,6 +9467,14 @@ var Listeners = function () {
}); });
}, false); }, false);
} }
// Reset on destroy
}, {
key: 'clear',
value: function clear() {
this.global(false);
}
}]); }]);
return Listeners; return Listeners;
}(); }();
@ -9756,7 +9746,7 @@ var Ads = function () {
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (!start) { if (!start) {
window.clearInterval(this.countdownTimer); clearInterval(this.countdownTimer);
this.elements.container.removeAttribute('data-badge-text'); this.elements.container.removeAttribute('data-badge-text');
return; return;
} }
@ -9767,7 +9757,7 @@ var Ads = function () {
_this5.elements.container.setAttribute('data-badge-text', label); _this5.elements.container.setAttribute('data-badge-text', label);
}; };
this.countdownTimer = window.setInterval(update, 100); this.countdownTimer = setInterval(update, 100);
} }
/** /**
@ -10542,10 +10532,10 @@ var youtube = {
utils.dispatchEvent.call(player, player.media, 'durationchange'); utils.dispatchEvent.call(player, player.media, 'durationchange');
// Reset timer // Reset timer
window.clearInterval(player.timers.buffering); clearInterval(player.timers.buffering);
// Setup buffering // Setup buffering
player.timers.buffering = window.setInterval(function () { player.timers.buffering = setInterval(function () {
// Get loaded % from YouTube // Get loaded % from YouTube
player.media.buffered = instance.getVideoLoadedFraction(); player.media.buffered = instance.getVideoLoadedFraction();
@ -10559,7 +10549,7 @@ var youtube = {
// Bail if we're at 100% // Bail if we're at 100%
if (player.media.buffered === 1) { if (player.media.buffered === 1) {
window.clearInterval(player.timers.buffering); clearInterval(player.timers.buffering);
// Trigger event // Trigger event
utils.dispatchEvent.call(player, player.media, 'canplaythrough'); utils.dispatchEvent.call(player, player.media, 'canplaythrough');
@ -10576,7 +10566,7 @@ var youtube = {
var instance = event.target; var instance = event.target;
// Reset timer // Reset timer
window.clearInterval(player.timers.playing); clearInterval(player.timers.playing);
// Handle events // Handle events
// -1 Unstarted // -1 Unstarted
@ -10616,7 +10606,7 @@ var youtube = {
utils.dispatchEvent.call(player, player.media, 'playing'); utils.dispatchEvent.call(player, player.media, 'playing');
// Poll to get playback progress // Poll to get playback progress
player.timers.playing = window.setInterval(function () { player.timers.playing = setInterval(function () {
utils.dispatchEvent.call(player, player.media, 'timeupdate'); utils.dispatchEvent.call(player, player.media, 'timeupdate');
}, 50); }, 50);
@ -11222,7 +11212,7 @@ var source = {
// ========================================================================== // ==========================================================================
// Plyr // Plyr
// plyr.js v3.0.0-beta.19 // plyr.js v3.0.0
// https://github.com/sampotts/plyr // https://github.com/sampotts/plyr
// License: The MIT License (MIT) // License: The MIT License (MIT)
// ========================================================================== // ==========================================================================
@ -11478,7 +11468,7 @@ var Plyr$1 = function () {
this.listeners.container(); this.listeners.container();
// Global listeners // Global listeners
this.listeners.global(true); this.listeners.global();
// Setup fullscreen // Setup fullscreen
this.fullscreen = new Fullscreen(this); this.fullscreen = new Fullscreen(this);
@ -11738,7 +11728,7 @@ var Plyr$1 = function () {
} }
// Clear timer on every call // Clear timer on every call
window.clearTimeout(this.timers.controls); clearTimeout(this.timers.controls);
// If the mouse is not over the controls, set a timeout to hide them // If the mouse is not over the controls, set a timeout to hide them
if (show || this.paused || this.loading) { if (show || this.paused || this.loading) {
@ -11829,6 +11819,10 @@ var Plyr$1 = function () {
var soft = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var soft = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (!this.ready) {
return;
}
var done = function done() { var done = function done() {
// Reset overflow (incase destroyed while in fullscreen) // Reset overflow (incase destroyed while in fullscreen)
document.body.style.overflow = ''; document.body.style.overflow = '';
@ -11857,12 +11851,12 @@ var Plyr$1 = function () {
callback(); callback();
} }
} else { } else {
// Unbind listeners
_this4.listeners.clear();
// Replace the container with the original element provided // Replace the container with the original element provided
utils.replaceElement(_this4.elements.original, _this4.elements.container); utils.replaceElement(_this4.elements.original, _this4.elements.container);
// Unbind global listeners
_this4.listeners.global(false);
// Event // Event
utils.dispatchEvent.call(_this4, _this4.elements.original, 'destroyed', true); utils.dispatchEvent.call(_this4, _this4.elements.original, 'destroyed', true);
@ -11871,15 +11865,27 @@ var Plyr$1 = function () {
callback.call(_this4.elements.original); callback.call(_this4.elements.original);
} }
// Clear for GC // Reset state
_this4.elements = null; _this4.ready = false;
// Clear for garbage collection
setTimeout(function () {
_this4.elements = null;
_this4.media = null;
}, 200);
} }
}; };
// Stop playback
this.stop();
// Type specific stuff // Type specific stuff
switch (this.provider + ':' + this.type) { switch (this.provider + ':' + this.type) {
case 'html5:video': case 'html5:video':
case 'html5:audio': case 'html5:audio':
// Clear timeout
clearTimeout(this.timers.loading);
// Restore native video controls // Restore native video controls
ui.toggleNativeControls.call(this, true); ui.toggleNativeControls.call(this, true);
@ -11890,8 +11896,8 @@ var Plyr$1 = function () {
case 'youtube:video': case 'youtube:video':
// Clear timers // Clear timers
window.clearInterval(this.timers.buffering); clearInterval(this.timers.buffering);
window.clearInterval(this.timers.playing); clearInterval(this.timers.playing);
// Destroy YouTube API // Destroy YouTube API
if (this.embed !== null) { if (this.embed !== null) {
@ -11941,37 +11947,37 @@ var Plyr$1 = function () {
}, { }, {
key: 'isHTML5', key: 'isHTML5',
get: function get() { get: function get() {
return this.provider === providers.html5; return Boolean(this.provider === providers.html5);
} }
}, { }, {
key: 'isEmbed', key: 'isEmbed',
get: function get() { get: function get() {
return this.isYouTube || this.isVimeo; return Boolean(this.isYouTube || this.isVimeo);
} }
}, { }, {
key: 'isYouTube', key: 'isYouTube',
get: function get() { get: function get() {
return this.provider === providers.youtube; return Boolean(this.provider === providers.youtube);
} }
}, { }, {
key: 'isVimeo', key: 'isVimeo',
get: function get() { get: function get() {
return this.provider === providers.vimeo; return Boolean(this.provider === providers.vimeo);
} }
}, { }, {
key: 'isVideo', key: 'isVideo',
get: function get() { get: function get() {
return this.type === types.video; return Boolean(this.type === types.video);
} }
}, { }, {
key: 'isAudio', key: 'isAudio',
get: function get() { get: function get() {
return this.type === types.audio; return Boolean(this.type === types.audio);
} }
}, { }, {
key: 'paused', key: 'paused',
get: function get() { get: function get() {
return this.media.paused; return Boolean(this.media.paused);
} }
/** /**
@ -11981,7 +11987,7 @@ var Plyr$1 = function () {
}, { }, {
key: 'playing', key: 'playing',
get: function get() { get: function get() {
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));
} }
/** /**
@ -11991,7 +11997,7 @@ var Plyr$1 = function () {
}, { }, {
key: 'ended', key: 'ended',
get: function get() { get: function get() {
return this.media.ended; return Boolean(this.media.ended);
} }
}, { }, {
key: 'currentTime', key: 'currentTime',
@ -12024,6 +12030,31 @@ var Plyr$1 = function () {
return Number(this.media.currentTime); return Number(this.media.currentTime);
} }
/**
* Get buffered
*/
}, {
key: 'buffered',
get: function get() {
var buffered = this.media.buffered;
// 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 status
*/ */
@ -12031,7 +12062,7 @@ var Plyr$1 = function () {
}, { }, {
key: 'seeking', key: 'seeking',
get: function get() { get: function get() {
return this.media.seeking; return Boolean(this.media.seeking);
} }
/** /**
@ -12103,7 +12134,7 @@ var Plyr$1 = function () {
*/ */
, ,
get: function get() { get: function get() {
return this.media.volume; return Number(this.media.volume);
} }
}, { }, {
key: 'muted', key: 'muted',
@ -12132,7 +12163,7 @@ var Plyr$1 = function () {
*/ */
, ,
get: function get() { get: function get() {
return this.media.muted; return Boolean(this.media.muted);
} }
/** /**
@ -12152,12 +12183,12 @@ var Plyr$1 = function () {
} }
// Get audio tracks // 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 * 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)
*/ */
}, { }, {
@ -12202,7 +12233,7 @@ var Plyr$1 = function () {
*/ */
, ,
get: function get() { get: function get() {
return this.media.playbackRate; return Number(this.media.playbackRate);
} }
/** /**
@ -12305,7 +12336,7 @@ var Plyr$1 = function () {
*/ */
, ,
get: function get() { get: function get() {
return this.media.loop; return Boolean(this.media.loop);
} }
/** /**
@ -12374,7 +12405,7 @@ var Plyr$1 = function () {
*/ */
, ,
get: function get() { get: function get() {
return this.config.autoplay; return Boolean(this.config.autoplay);
} }
}, { }, {
key: 'language', key: 'language',
@ -12481,7 +12512,7 @@ var Plyr$1 = function () {
// ========================================================================== // ==========================================================================
// Plyr Polyfilled Build // Plyr Polyfilled Build
// plyr.js v3.0.0-beta.19 // plyr.js v3.0.0-beta.20
// https://github.com/sampotts/plyr // https://github.com/sampotts/plyr
// License: The MIT License (MIT) // License: The MIT License (MIT)
// ========================================================================== // ==========================================================================

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "plyr", "name": "plyr",
"version": "3.0.0-beta.19", "version": "3.0.0",
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player", "description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
"homepage": "https://plyr.io", "homepage": "https://plyr.io",
"main": "./dist/plyr.js", "main": "./dist/plyr.js",
@ -39,7 +39,7 @@
"rollup-plugin-commonjs": "^8.4.1", "rollup-plugin-commonjs": "^8.4.1",
"rollup-plugin-node-resolve": "^3.2.0", "rollup-plugin-node-resolve": "^3.2.0",
"run-sequence": "^2.2.1", "run-sequence": "^2.2.1",
"stylelint": "^9.1.1", "stylelint": "^9.1.3",
"stylelint-config-prettier": "^3.0.4", "stylelint-config-prettier": "^3.0.4",
"stylelint-config-recommended": "^2.1.0", "stylelint-config-recommended": "^2.1.0",
"stylelint-config-sass-guidelines": "^5.0.0", "stylelint-config-sass-guidelines": "^5.0.0",

View File

@ -1,7 +1,3 @@
---
Beware: This version is currently in beta and not production-ready
---
# Plyr # Plyr
A simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports [_modern_](#browser-support) browsers. A simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports [_modern_](#browser-support) browsers.
@ -13,13 +9,13 @@ A simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo medi
## Features ## Features
* **Accessible** - full support for VTT captions and screen readers * **Accessible** - full support for VTT captions and screen readers
* **Lightweight** - just 18KB minified and gzipped
* **[Customisable](#html)** - make the player look how you want with the markup you want * **[Customisable](#html)** - make the player look how you want with the markup you want
* **Semantic** - uses the _right_ elements. `<input type="range">` for volume and `<progress>` for progress and well, `<button>`s for buttons. There's no * **Semantic** - uses the _right_ elements. `<input type="range">` for volume and `<progress>` for progress and well, `<button>`s for buttons. There's no
`<span>` or `<a href="#">` button hacks `<span>` or `<a href="#">` button hacks
* **Responsive** - works with any screen size * **Responsive** - works with any screen size
* **HTML Video & Audio** - support for both formats * **HTML Video & Audio** - support for both formats
* **[Embedded Video](#embeds)** - support for YouTube and Vimeo video playback * **[Embedded Video](#embeds)** - support for YouTube and Vimeo video playback
* **[Monetization](#ads)** - make money from your videos
* **[Streaming](#streaming)** - support for hls.js, Shaka and dash.js streaming playback * **[Streaming](#streaming)** - support for hls.js, Shaka and dash.js streaming playback
* **[API](#api)** - toggle playback, volume, seeking, and more through a standardized API * **[API](#api)** - toggle playback, volume, seeking, and more through a standardized API
* **[Events](#events)** - no messing around with Vimeo and YouTube APIs, all events are standardized across formats * **[Events](#events)** - no messing around with Vimeo and YouTube APIs, all events are standardized across formats
@ -128,7 +124,7 @@ See [initialising](#initialising) for more information on advanced setups.
If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the JavaScript, you can use the following: If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the JavaScript, you can use the following:
```html ```html
<script src="https://cdn.plyr.io/3.0.0-beta.19/plyr.js"></script> <script src="https://cdn.plyr.io/3.0.0/plyr.js"></script>
``` ```
_Note_: Be sure to read the [polyfills](#polyfills) section below about browser compatibility _Note_: Be sure to read the [polyfills](#polyfills) section below about browser compatibility
@ -144,13 +140,23 @@ Include the `plyr.css` stylsheet into your `<head>`
If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the default CSS, you can use the following: If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the default CSS, you can use the following:
```html ```html
<link rel="stylesheet" href="https://cdn.plyr.io/3.0.0-beta.19/plyr.css"> <link rel="stylesheet" href="https://cdn.plyr.io/3.0.0/plyr.css">
``` ```
### SVG Sprite ### SVG Sprite
The SVG sprite is loaded automatically from our CDN (provided by [Fastly](https://www.fastly.com/)). To change this, see the [options](#options) below. For The SVG sprite is loaded automatically from our CDN (provided by [Fastly](https://www.fastly.com/)). To change this, see the [options](#options) below. For
reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.0.0-beta.19/plyr.svg`. reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.0.0/plyr.svg`.
## Ads
Plyr has partnered up with [ai.vi](http://vi.ai/publisher-video-monetization/?aid=plyrio) to offer monetization options for your videos. Getting setup is easy:
* [Sign up for a vi.ai account](http://vi.ai/publisher-video-monetization/?aid=plyrio)
* Grab your publisher ID from the code snippet
* Enable ads in the [config options](#options) and enter your publisher ID
Any questions regarding the ads can be sent straight to vi.ai and any issues with rendering raised through GitHub issues.
## Advanced ## Advanced
@ -284,6 +290,7 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke
| `speed` | Object | `{ selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2] }` | `selected`: The default speed for playback. `options`: Options to display in the menu. Most browsers will refuse to play slower than 0.5. | | `speed` | Object | `{ selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2] }` | `selected`: The default speed for playback. `options`: Options to display in the menu. Most browsers will refuse to play slower than 0.5. |
| `quality` | Object | `{ default: 'default', options: ['hd2160', 'hd1440', 'hd1080', 'hd720', 'large', 'medium', 'small', 'tiny', 'default'] }` | Currently only supported by YouTube. `default` is the default quality level, determined by YouTube. `options` are the options to display. | | `quality` | Object | `{ default: 'default', options: ['hd2160', 'hd1440', 'hd1080', 'hd720', 'large', 'medium', 'small', 'tiny', 'default'] }` | Currently only supported by YouTube. `default` is the default quality level, determined by YouTube. `options` are the options to display. |
| `loop` | Object | `{ active: false }` | `active`: Whether to loop the current video. If the `loop` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true This is an object to support future functionality. | | `loop` | Object | `{ active: false }` | `active`: Whether to loop the current video. If the `loop` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true This is an object to support future functionality. |
| `ads` | Object | `{ enabled: false, publisherId: '' }` | `enabled`: Whether to enable vi.ai ads. `publisherId`: Your unique vi.ai publisher ID. |
1. Vimeo only 1. Vimeo only
@ -366,6 +373,7 @@ player.fullscreen.active; // false;
| `paused` | ✓ | - | Returns a boolean indicating if the current player is paused. | | `paused` | ✓ | - | Returns a boolean indicating if the current player is paused. |
| `playing` | ✓ | - | Returns a boolean indicating if the current player is playing. | | `playing` | ✓ | - | Returns a boolean indicating if the current player is playing. |
| `ended` | ✓ | - | Returns a boolean indicating if the current player has finished playback. | | `ended` | ✓ | - | Returns a boolean indicating if the current player has finished playback. |
| `buffered` | ✓ | - | Returns a float between 0 and 1 indicating how much of the media is buffered |
| `currentTime` | ✓ | ✓ | Gets or sets the currentTime for the player. The setter accepts a float in seconds. | | `currentTime` | ✓ | ✓ | Gets or sets the currentTime for the player. The setter accepts a float in seconds. |
| `seeking` | ✓ | - | Returns a boolean indicating if the current player is seeking. | | `seeking` | ✓ | - | Returns a boolean indicating if the current player is seeking. |
| `duration` | ✓ | - | Returns the duration for the current media. | | `duration` | ✓ | - | Returns the duration for the current media. |

View File

@ -56,7 +56,7 @@ const defaults = {
// Sprite (for icons) // Sprite (for icons)
loadSprite: true, loadSprite: true,
iconPrefix: 'plyr', iconPrefix: 'plyr',
iconUrl: 'https://cdn.plyr.io/3.0.0-beta.19/plyr.svg', iconUrl: 'https://cdn.plyr.io/3.0.0/plyr.svg',
// Blank video (used to prevent errors on source change) // Blank video (used to prevent errors on source change)
blankVideo: 'https://cdn.plyr.io/static/blank.mp4', blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
@ -376,7 +376,7 @@ const defaults = {
// Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio // Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
ads: { ads: {
enabled: false, enabled: false,
publisherId: '918848828995742', publisherId: '',
}, },
}; };

View File

@ -188,7 +188,7 @@ class Listeners {
} }
// Global window & document listeners // Global window & document listeners
global(toggle) { global(toggle = true) {
// Keyboard shortcuts // Keyboard shortcuts
if (this.player.config.keyboard.global) { if (this.player.config.keyboard.global) {
utils.toggleListener(window, 'keydown keyup', this.handleKey, toggle, false); utils.toggleListener(window, 'keydown keyup', this.handleKey, toggle, false);
@ -585,6 +585,11 @@ class Listeners {
false, false,
); );
} }
// Reset on destroy
clear() {
this.global(false);
}
} }
export default Listeners; export default Listeners;

View File

@ -171,7 +171,7 @@ class Ads {
*/ */
pollCountdown(start = false) { pollCountdown(start = false) {
if (!start) { if (!start) {
window.clearInterval(this.countdownTimer); clearInterval(this.countdownTimer);
this.elements.container.removeAttribute('data-badge-text'); this.elements.container.removeAttribute('data-badge-text');
return; return;
} }
@ -182,7 +182,7 @@ class Ads {
this.elements.container.setAttribute('data-badge-text', label); this.elements.container.setAttribute('data-badge-text', label);
}; };
this.countdownTimer = window.setInterval(update, 100); this.countdownTimer = setInterval(update, 100);
} }
/** /**

View File

@ -305,10 +305,10 @@ const youtube = {
utils.dispatchEvent.call(player, player.media, 'durationchange'); utils.dispatchEvent.call(player, player.media, 'durationchange');
// Reset timer // Reset timer
window.clearInterval(player.timers.buffering); clearInterval(player.timers.buffering);
// Setup buffering // Setup buffering
player.timers.buffering = window.setInterval(() => { player.timers.buffering = setInterval(() => {
// Get loaded % from YouTube // Get loaded % from YouTube
player.media.buffered = instance.getVideoLoadedFraction(); player.media.buffered = instance.getVideoLoadedFraction();
@ -322,7 +322,7 @@ const youtube = {
// Bail if we're at 100% // Bail if we're at 100%
if (player.media.buffered === 1) { if (player.media.buffered === 1) {
window.clearInterval(player.timers.buffering); clearInterval(player.timers.buffering);
// Trigger event // Trigger event
utils.dispatchEvent.call(player, player.media, 'canplaythrough'); utils.dispatchEvent.call(player, player.media, 'canplaythrough');
@ -337,7 +337,7 @@ const youtube = {
const instance = event.target; const instance = event.target;
// Reset timer // Reset timer
window.clearInterval(player.timers.playing); clearInterval(player.timers.playing);
// Handle events // Handle events
// -1 Unstarted // -1 Unstarted
@ -377,7 +377,7 @@ const youtube = {
utils.dispatchEvent.call(player, player.media, 'playing'); utils.dispatchEvent.call(player, player.media, 'playing');
// Poll to get playback progress // Poll to get playback progress
player.timers.playing = window.setInterval(() => { player.timers.playing = setInterval(() => {
utils.dispatchEvent.call(player, player.media, 'timeupdate'); utils.dispatchEvent.call(player, player.media, 'timeupdate');
}, 50); }, 50);

View File

@ -1,6 +1,6 @@
// ========================================================================== // ==========================================================================
// Plyr // Plyr
// plyr.js v3.0.0-beta.19 // plyr.js v3.0.0
// https://github.com/sampotts/plyr // https://github.com/sampotts/plyr
// License: The MIT License (MIT) // License: The MIT License (MIT)
// ========================================================================== // ==========================================================================
@ -276,7 +276,7 @@ class Plyr {
this.listeners.container(); this.listeners.container();
// Global listeners // Global listeners
this.listeners.global(true); this.listeners.global();
// Setup fullscreen // Setup fullscreen
this.fullscreen = new Fullscreen(this); this.fullscreen = new Fullscreen(this);
@ -293,22 +293,22 @@ class Plyr {
* Types and provider helpers * Types and provider helpers
*/ */
get isHTML5() { get isHTML5() {
return this.provider === providers.html5; return Boolean(this.provider === providers.html5);
} }
get isEmbed() { get isEmbed() {
return this.isYouTube || this.isVimeo; return Boolean(this.isYouTube || this.isVimeo);
} }
get isYouTube() { get isYouTube() {
return this.provider === providers.youtube; return Boolean(this.provider === providers.youtube);
} }
get isVimeo() { get isVimeo() {
return this.provider === providers.vimeo; return Boolean(this.provider === providers.vimeo);
} }
get isVideo() { get isVideo() {
return this.type === types.video; return Boolean(this.type === types.video);
} }
get isAudio() { get isAudio() {
return this.type === types.audio; return Boolean(this.type === types.audio);
} }
/** /**
@ -339,21 +339,21 @@ class Plyr {
* Get paused state * Get paused state
*/ */
get paused() { get paused() {
return this.media.paused; return Boolean(this.media.paused);
} }
/** /**
* Get playing state * Get playing state
*/ */
get playing() { 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 state
*/ */
get ended() { get ended() {
return this.media.ended; return Boolean(this.media.ended);
} }
/** /**
@ -434,11 +434,32 @@ class Plyr {
return Number(this.media.currentTime); return Number(this.media.currentTime);
} }
/**
* 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 status
*/ */
get seeking() { get seeking() {
return this.media.seeking; return Boolean(this.media.seeking);
} }
/** /**
@ -503,7 +524,7 @@ class Plyr {
* Get the current player volume * Get the current player volume
*/ */
get volume() { get volume() {
return this.media.volume; return Number(this.media.volume);
} }
/** /**
@ -552,7 +573,7 @@ class Plyr {
* Get current muted state * Get current muted state
*/ */
get muted() { get muted() {
return this.media.muted; return Boolean(this.media.muted);
} }
/** /**
@ -569,12 +590,16 @@ class Plyr {
} }
// Get audio tracks // 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 * 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) { set speed(input) {
let speed = null; let speed = null;
@ -615,7 +640,7 @@ class Plyr {
* Get current playback speed * Get current playback speed
*/ */
get speed() { get speed() {
return this.media.playbackRate; return Number(this.media.playbackRate);
} }
/** /**
@ -715,7 +740,7 @@ class Plyr {
* Get current loop state * Get current loop state
*/ */
get loop() { get loop() {
return this.media.loop; return Boolean(this.media.loop);
} }
/** /**
@ -772,7 +797,7 @@ class Plyr {
* Get the current autoplay state * Get the current autoplay state
*/ */
get autoplay() { get autoplay() {
return this.config.autoplay; return Boolean(this.config.autoplay);
} }
/** /**
@ -951,7 +976,7 @@ class Plyr {
} }
// Clear timer on every call // Clear timer on every call
window.clearTimeout(this.timers.controls); clearTimeout(this.timers.controls);
// If the mouse is not over the controls, set a timeout to hide them // If the mouse is not over the controls, set a timeout to hide them
if (show || this.paused || this.loading) { if (show || this.paused || this.loading) {
@ -1029,6 +1054,10 @@ class Plyr {
* @param {boolean} soft - Whether it's a soft destroy (for source changes etc) * @param {boolean} soft - Whether it's a soft destroy (for source changes etc)
*/ */
destroy(callback, soft = false) { destroy(callback, soft = false) {
if (!this.ready) {
return;
}
const done = () => { const done = () => {
// Reset overflow (incase destroyed while in fullscreen) // Reset overflow (incase destroyed while in fullscreen)
document.body.style.overflow = ''; document.body.style.overflow = '';
@ -1057,12 +1086,12 @@ class Plyr {
callback(); callback();
} }
} else { } else {
// Unbind listeners
this.listeners.clear();
// Replace the container with the original element provided // Replace the container with the original element provided
utils.replaceElement(this.elements.original, this.elements.container); utils.replaceElement(this.elements.original, this.elements.container);
// Unbind global listeners
this.listeners.global(false);
// Event // Event
utils.dispatchEvent.call(this, this.elements.original, 'destroyed', true); utils.dispatchEvent.call(this, this.elements.original, 'destroyed', true);
@ -1071,15 +1100,27 @@ class Plyr {
callback.call(this.elements.original); callback.call(this.elements.original);
} }
// Clear for GC // Reset state
this.elements = null; this.ready = false;
// Clear for garbage collection
setTimeout(() => {
this.elements = null;
this.media = null;
}, 200);
} }
}; };
// Stop playback
this.stop();
// Type specific stuff // Type specific stuff
switch (`${this.provider}:${this.type}`) { switch (`${this.provider}:${this.type}`) {
case 'html5:video': case 'html5:video':
case 'html5:audio': case 'html5:audio':
// Clear timeout
clearTimeout(this.timers.loading);
// Restore native video controls // Restore native video controls
ui.toggleNativeControls.call(this, true); ui.toggleNativeControls.call(this, true);
@ -1090,8 +1131,8 @@ class Plyr {
case 'youtube:video': case 'youtube:video':
// Clear timers // Clear timers
window.clearInterval(this.timers.buffering); clearInterval(this.timers.buffering);
window.clearInterval(this.timers.playing); clearInterval(this.timers.playing);
// Destroy YouTube API // Destroy YouTube API
if (this.embed !== null) { if (this.embed !== null) {

View File

@ -1,6 +1,6 @@
// ========================================================================== // ==========================================================================
// Plyr Polyfilled Build // Plyr Polyfilled Build
// plyr.js v3.0.0-beta.19 // plyr.js v3.0.0
// https://github.com/sampotts/plyr // https://github.com/sampotts/plyr
// License: The MIT License (MIT) // License: The MIT License (MIT)
// ========================================================================== // ==========================================================================

View File

@ -30,13 +30,9 @@ const support = {
break; break;
case 'youtube:video': case 'youtube:video':
api = true;
ui = support.rangeInput && (!browser.isIPhone || playsInline);
break;
case 'vimeo:video': case 'vimeo:video':
api = true; api = true;
ui = support.rangeInput && !browser.isIPhone; ui = support.rangeInput && (!browser.isIPhone || playsInline);
break; break;
default: default:

View File

@ -5,7 +5,6 @@
import utils from './utils'; import utils from './utils';
import captions from './captions'; import captions from './captions';
import controls from './controls'; import controls from './controls';
import listeners from './listeners';
const ui = { const ui = {
addStyleHook() { addStyleHook() {
@ -25,7 +24,7 @@ const ui = {
// Setup the UI // Setup the UI
build() { build() {
// Re-attach media element listeners // Re-attach media element listeners
// TODO: Use event bubbling // TODO: Use event bubbling?
this.listeners.media(); this.listeners.media();
// Don't setup interface if no support // Don't setup interface if no support
@ -256,21 +255,7 @@ const ui = {
// Check buffer status // Check buffer status
case 'playing': case 'playing':
case 'progress': case 'progress':
value = (() => { ui.setProgress.call(this, this.elements.display.buffer, this.buffered * 100);
const { buffered } = this.media;
if (buffered && buffered.length) {
// HTML5
return utils.getPercentage(buffered.end(0), this.duration);
} else if (utils.is.number(buffered)) {
// YouTube returns between 0 and 1
return buffered * 100;
}
return 0;
})();
ui.setProgress.call(this, this.elements.display.buffer, value);
break; break;

View File

@ -671,6 +671,7 @@ const utils = {
if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) { if (current === 0 || max === 0 || Number.isNaN(current) || Number.isNaN(max)) {
return 0; return 0;
} }
return (current / max * 100).toFixed(2); return (current / max * 100).toFixed(2);
}, },

View File

@ -3,9 +3,11 @@
// ========================================================================== // ==========================================================================
.plyr__ads { .plyr__ads {
border-radius: inherit;
bottom: 0; bottom: 0;
cursor: pointer; cursor: pointer;
left: 0; left: 0;
overflow: hidden;
position: absolute; position: absolute;
right: 0; right: 0;
top: 0; top: 0;

831
yarn.lock

File diff suppressed because it is too large Load Diff