From aac0a5a3a920a7458e814447933662d4932c803c Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 21 Aug 2016 10:30:11 +1000 Subject: [PATCH] Work on docs --- changelog.md | 4 +- dist/plyr.js | 4 +- readme.md | 407 ++++++++++++++++++++++++++++++------------------- src/js/plyr.js | 57 +++++-- 4 files changed, 300 insertions(+), 172 deletions(-) diff --git a/changelog.md b/changelog.md index 68276840..831045f7 100644 --- a/changelog.md +++ b/changelog.md @@ -20,12 +20,14 @@ And some other changes and bug fixes: - `on()` to provide an easy way to listen to events - `stop()` to, you guessed it, stop the player - `destroy()` now works correctly for YouTube and Vimeo (fixes #272) -- New `destoryed` event when original element is restored (original element passed as event target) +- New `destroyed` event when original element is restored (original element passed as event target) - Default volume is now 10 (max) rather than 5 - Sprite is only loaded once (fixes #259) - Fixes for Vimeo post message bugs on source change or destroy (fixes #318) - Save caption state in storage (fixes #311) - Added keyboard shortcuts to the current focused player (with option to disable) (fixes #309) +- Fix for captions bug (fixes #332) +- Change to AMD (fixes #298) ## v1.8.12 - Vimeo keyboard focus fix (Fixes #317) diff --git a/dist/plyr.js b/dist/plyr.js index 1ebf35ac..af15abec 100644 --- a/dist/plyr.js +++ b/dist/plyr.js @@ -1,2 +1,2 @@ -!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=t(e,document):"function"==typeof define&&define.amd?define(null,function(){t(e,document)}):e.plyr=t(e,document)}("undefined"!=typeof window?window:this,function(e,t){"use strict";function n(){var e,n,r,s=navigator.userAgent,o=navigator.appName,a=""+parseFloat(navigator.appVersion),i=parseInt(navigator.appVersion,10),l=!1,u=!1,c=!1,p=!1;return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(l=!0,o="IE",a="11"):-1!==(n=s.indexOf("MSIE"))?(l=!0,o="IE",a=s.substring(n+5)):-1!==(n=s.indexOf("Chrome"))?(c=!0,o="Chrome",a=s.substring(n+7)):-1!==(n=s.indexOf("Safari"))?(p=!0,o="Safari",a=s.substring(n+7),-1!==(n=s.indexOf("Version"))&&(a=s.substring(n+8))):-1!==(n=s.indexOf("Firefox"))?(u=!0,o="Firefox",a=s.substring(n+8)):(e=s.lastIndexOf(" ")+1)<(n=s.lastIndexOf("/"))&&(o=s.substring(e,n),a=s.substring(n+1),o.toLowerCase()===o.toUpperCase()&&(o=navigator.appName)),-1!==(r=a.indexOf(";"))&&(a=a.substring(0,r)),-1!==(r=a.indexOf(" "))&&(a=a.substring(0,r)),i=parseInt(""+a,10),isNaN(i)&&(a=""+parseFloat(navigator.appVersion),i=parseInt(navigator.appVersion,10)),{name:o,version:i,isIE:l,isFirefox:u,isChrome:c,isSafari:p,isIos:/(iPad|iPhone|iPod)/g.test(navigator.platform),isTouch:"ontouchstart"in t.documentElement}}function r(e,t){var n=e.media;if("video"===e.type)switch(t){case"video/webm":return!(!n.canPlayType||!n.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/,""));case"video/mp4":return!(!n.canPlayType||!n.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/,""));case"video/ogg":return!(!n.canPlayType||!n.canPlayType('video/ogg; codecs="theora"').replace(/no/,""))}else if("audio"===e.type)switch(t){case"audio/mpeg":return!(!n.canPlayType||!n.canPlayType("audio/mpeg;").replace(/no/,""));case"audio/ogg":return!(!n.canPlayType||!n.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/,""));case"audio/wav":return!(!n.canPlayType||!n.canPlayType('audio/wav; codecs="1"').replace(/no/,""))}return!1}function s(e){if(!t.querySelectorAll('script[src="'+e+'"]').length){var n=t.createElement("script");n.src=e;var r=t.getElementsByTagName("script")[0];r.parentNode.insertBefore(n,r)}}function o(e,t){return Array.prototype.indexOf&&-1!==e.indexOf(t)}function a(e,t,n){return e.replace(new RegExp(t.replace(/([.*+?\^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),n)}function i(e,t){e.length||(e=[e]);for(var n=e.length-1;n>=0;n--){var r=n>0?t.cloneNode(!0):t,s=e[n],o=s.parentNode,a=s.nextSibling;return r.appendChild(s),a?o.insertBefore(r,a):o.appendChild(r),r}}function l(e){e&&e.parentNode.removeChild(e)}function u(e,t){e.insertBefore(t,e.firstChild)}function c(e,t){for(var n in t)e.setAttribute(n,P["boolean"](t[n])&&t[n]?"":t[n])}function p(e,n,r){var s=t.createElement(e);c(s,r),u(n,s)}function d(e){return e.replace(".","")}function m(e,t,n){if(e)if(e.classList)e.classList[n?"add":"remove"](t);else{var r=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=r+(n?" "+t:"")}}function f(e,t){return e?e.classList?e.classList.contains(t):new RegExp("(\\s|^)"+t+"(\\s|$)").test(e.className):!1}function y(e,n){var r=Element.prototype,s=r.matches||r.webkitMatchesSelector||r.mozMatchesSelector||r.msMatchesSelector||function(e){return-1!==[].indexOf.call(t.querySelectorAll(e),this)};return s.call(e,n)}function b(e,t,n,r,s){g(e,t,function(t){n&&n.apply(e,[t]),r.apply(e,[t])},s)}function v(e,t,n,r,s){var o=t.split(" ");if(P["boolean"](s)||(s=!1),e instanceof NodeList)for(var a=0;ar;r++){var s=e[r];for(var o in s)s[o]&&s[o].constructor&&s[o].constructor===Object?(t[o]=t[o]||{},T(t[o],s[o])):t[o]=s[o]}return t}}function x(){var e={supportsFullScreen:!1,isFullScreen:function(){return!1},requestFullScreen:function(){},cancelFullScreen:function(){},fullScreenEventName:"",element:null,prefix:""},n="webkit moz o ms khtml".split(" ");if(P.undefined(t.cancelFullScreen))for(var r=0,s=n.length;s>r;r++){if(e.prefix=n[r],!P.undefined(t[e.prefix+"CancelFullScreen"])){e.supportsFullScreen=!0;break}if(!P.undefined(t.msExitFullscreen)&&t.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}else e.supportsFullScreen=!0;return e.supportsFullScreen&&(e.fullScreenEventName="ms"===e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(e){switch(P.undefined(e)&&(e=t.body),this.prefix){case"":return t.fullscreenElement===e;case"moz":return t.mozFullScreenElement===e;default:return t[this.prefix+"FullscreenElement"]===e}},e.requestFullScreen=function(e){return P.undefined(e)&&(e=t.body),""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"===this.prefix?"RequestFullscreen":"RequestFullScreen")]()},e.cancelFullScreen=function(){return""===this.prefix?t.cancelFullScreen():t[this.prefix+("ms"===this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?t.fullscreenElement:t[this.prefix+"FullscreenElement"]}),e}function S(y,v){function S(t,n){v.debug&&e.console&&(n=Array.prototype.slice.call(n),P.string(v.logPrefix)&&v.logPrefix.length&&n.unshift(v.logPrefix),console[t].apply(console,n))}function C(){return{url:v.iconUrl,absolute:0===v.iconUrl.indexOf("http")||Re.browser.isIE}}function F(){var e=[],t=C(),n=(t.absolute?"":t.url)+"#"+v.iconPrefix;return o(v.controls,"play-large")&&e.push('"),e.push('
'),o(v.controls,"restart")&&e.push('"),o(v.controls,"rewind")&&e.push('"),o(v.controls,"play")&&e.push('",'"),o(v.controls,"fast-forward")&&e.push('"),o(v.controls,"progress")&&(e.push('','','','','',"0% "+v.i18n.buffered,""),v.tooltips.seek&&e.push('00:00'),e.push("")),o(v.controls,"current-time")&&e.push('',''+v.i18n.currentTime+"",'00:00',""),o(v.controls,"duration")&&e.push('',''+v.i18n.duration+"",'00:00',""),o(v.controls,"mute")&&e.push('"),o(v.controls,"volume")&&e.push('','",'','',""),o(v.controls,"captions")&&e.push('"),o(v.controls,"fullscreen")&&e.push('"),e.push("
"),e.join("")}function L(){if(Re.supported.full&&("audio"!==Re.type||v.fullscreen.allowAudio)&&v.fullscreen.enabled){var e=A.supportsFullScreen;e||v.fullscreen.fallback&&!H()?(We((e?"Native":"Fallback")+" fullscreen enabled"),m(Re.container,v.classes.fullscreen.enabled,!0)):We("Fullscreen not supported and fallback disabled"),Re.buttons&&Re.buttons.fullscreen&&k(Re.buttons.fullscreen,!1),W()}}function O(){if("video"===Re.type){D(v.selectors.captions)||Re.videoContainer.insertAdjacentHTML("afterbegin",'
'),Re.usingTextTracks=!1,Re.media.textTracks&&(Re.usingTextTracks=!0);for(var e,t="",n=Re.media.childNodes,r=0;r=10||Re.browser.isFirefox&&Re.browser.version>=31)&&(We("Detected browser with known TextTrack issues - using manual fallback"),Re.usingTextTracks=!1),Re.usingTextTracks){We("TextTracks supported");for(var a=0;a ");for(var r=0;rRe.captions.length-1){Re.subcount=Re.captions.length-1;break}Re.media.currentTime.toFixed(1)>=n(Re.captions[Re.subcount][0])&&Re.media.currentTime.toFixed(1)<=r(Re.captions[Re.subcount][0])?(Re.currentCaption=Re.captions[Re.subcount][1],j(Re.currentCaption)):j()}}function q(){if(Re.buttons.captions){m(Re.container,v.classes.captions.enabled,!0);var e=Re.storage.captionsEnabled;P["boolean"](e)||(e=v.captions.defaultActive),e&&(m(Re.container,v.classes.captions.active,!0),k(Re.buttons.captions,!0))}}function R(e){return Re.container.querySelectorAll(e)}function D(e){return R(e)[0]}function H(){try{return e.self!==e.top}catch(t){return!0}}function W(){function e(e){9===e.which&&Re.isFullscreen&&(e.target!==r||e.shiftKey?e.target===n&&e.shiftKey&&(e.preventDefault(),r.focus()):(e.preventDefault(),n.focus()))}var t=R("input:not([disabled]), button:not([disabled])"),n=t[0],r=t[t.length-1];g(Re.container,"keydown",e)}function Y(e,t){if(P.string(t))p(e,Re.media,{src:t});else if(t.constructor===Array)for(var n=t.length-1;n>=0;n--)p(e,Re.media,t[n])}function B(){if(v.loadSprite){var e=C();e.absolute?(We("AJAX loading absolute SVG sprite"+(Re.browser.isIE?" (due to IE)":"")),_(e.url,"sprite-plyr")):We("Sprite will be used as external resource directly")}var n=v.html;We("Injecting custom controls"),n||(n=F()),n=a(n,"{seektime}",v.seekTime),n=a(n,"{id}",Math.floor(1e4*Math.random()));var r;if(P.string(v.selectors.controls.container)&&(r=t.querySelector(v.selectors.controls.container)),P.htmlElement(r)||(r=Re.container),r.insertAdjacentHTML("beforeend",n),v.tooltips.controls)for(var s=R([v.selectors.controls.wrapper," ",v.selectors.labels," .",v.classes.hidden].join("")),o=s.length-1;o>=0;o--){var i=s[o];m(i,v.classes.hidden,!1),m(i,v.classes.tooltip,!0)}}function X(){try{return Re.controls=D(v.selectors.controls.wrapper),Re.buttons={},Re.buttons.seek=D(v.selectors.buttons.seek),Re.buttons.play=R(v.selectors.buttons.play),Re.buttons.pause=D(v.selectors.buttons.pause),Re.buttons.restart=D(v.selectors.buttons.restart),Re.buttons.rewind=D(v.selectors.buttons.rewind),Re.buttons.forward=D(v.selectors.buttons.forward),Re.buttons.fullscreen=D(v.selectors.buttons.fullscreen),Re.buttons.mute=D(v.selectors.buttons.mute),Re.buttons.captions=D(v.selectors.buttons.captions),Re.progress={},Re.progress.container=D(v.selectors.progress.container),Re.progress.buffer={},Re.progress.buffer.bar=D(v.selectors.progress.buffer),Re.progress.buffer.text=Re.progress.buffer.bar&&Re.progress.buffer.bar.getElementsByTagName("span")[0],Re.progress.played=D(v.selectors.progress.played),Re.progress.tooltip=Re.progress.container&&Re.progress.container.querySelector("."+v.classes.tooltip),Re.volume={},Re.volume.input=D(v.selectors.volume.input),Re.volume.display=D(v.selectors.volume.display),Re.duration=D(v.selectors.duration),Re.currentTime=D(v.selectors.currentTime),Re.seekTime=R(v.selectors.seekTime),!0}catch(e){return Ye("It looks like there is a problem with your controls HTML"),J(!0),!1}}function U(){m(Re.container,v.selectors.container.replace(".",""),Re.supported.full)}function J(e){e&&o(v.types.html5,Re.type)?Re.media.setAttribute("controls",""):Re.media.removeAttribute("controls")}function z(e){var t=v.i18n.play;if(P.string(v.title)&&v.title.length&&(t+=", "+v.title,Re.container.setAttribute("aria-label",v.title)),Re.supported.full&&Re.buttons.play)for(var n=Re.buttons.play.length-1;n>=0;n--)Re.buttons.play[n].setAttribute("aria-label",t);P.htmlElement(e)&&e.setAttribute("title",v.i18n.frameTitle.replace("{title}",v.title))}function $(){var t=null;Re.storage={},M.supported&&v.storage.enabled&&(e.localStorage.removeItem("plyr-volume"),t=e.localStorage.getItem(v.storage.key),t&&(/^\d+(\.\d+)?$/.test(t)?G({volume:parseFloat(t)}):Re.storage=JSON.parse(t)))}function G(t){M.supported&&v.storage.enabled&&(T(Re.storage,t),e.localStorage.setItem(v.storage.key,JSON.stringify(Re.storage)))}function K(){if(!Re.media)return void Ye("No media element found!");if(Re.supported.full&&(m(Re.container,v.classes.type.replace("{0}",Re.type),!0),o(v.types.embed,Re.type)&&m(Re.container,v.classes.type.replace("{0}","video"),!0),m(Re.container,v.classes.stopped,v.autoplay),m(Re.ontainer,v.classes.isIos,Re.browser.isIos),m(Re.container,v.classes.isTouch,Re.browser.isTouch),"video"===Re.type)){var e=t.createElement("div");e.setAttribute("class",v.classes.videoWrapper),i(Re.media,e),Re.videoContainer=e}o(v.types.embed,Re.type)&&Q()}function Q(){for(var n=t.createElement("div"),r=Re.embedId,o=Re.type+"-"+Math.floor(1e4*Math.random()),a=R('[id^="'+Re.type+'-"]'),i=a.length-1;i>=0;i--)l(a[i]);if(m(Re.media,v.classes.videoWrapper,!0),m(Re.media,v.classes.embedWrapper,!0),"youtube"===Re.type)Re.media.appendChild(n),n.setAttribute("id",o),P.object(e.YT)?ee(r,n):(s(v.urls.youtube.api),e.onYouTubeReadyCallbacks=e.onYouTubeReadyCallbacks||[],e.onYouTubeReadyCallbacks.push(function(){ee(r,n)}),e.onYouTubeIframeAPIReady=function(){e.onYouTubeReadyCallbacks.forEach(function(e){e()})});else if("vimeo"===Re.type)if(Re.supported.full?Re.media.appendChild(n):n=Re.media,n.setAttribute("id",o),P.object(e.Vimeo))te(r,n);else{s(v.urls.vimeo.api);var u=e.setInterval(function(){P.object(e.Vimeo)&&(e.clearInterval(u),te(r,n))},50)}else if("soundcloud"===Re.type){var p=t.createElement("iframe");p.loaded=!1,g(p,"load",function(){p.loaded=!0}),c(p,{src:"https://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/"+r,id:o}),n.appendChild(p),Re.media.appendChild(n),e.SC||s(v.urls.soundcloud.api);var d=e.setInterval(function(){e.SC&&p.loaded&&(e.clearInterval(d),ne.call(p))},50)}}function Z(){Re.supported.full&&(Ve(),qe()),z(D("iframe"))}function ee(t,n){Re.embed=new e.YT.Player(n.id,{videoId:t,playerVars:{autoplay:v.autoplay?1:0,controls:Re.supported.full?0:1,rel:0,showinfo:0,iv_load_policy:3,cc_load_policy:v.captions.defaultActive?1:0,cc_lang_pref:"en",wmode:"transparent",modestbranding:1,disablekb:1,origin:"*"},events:{onError:function(e){h(n,"error",!0,{code:e.data,embed:e.target})},onReady:function(t){var n=t.target;Re.media.play=function(){n.playVideo(),Re.media.paused=!1},Re.media.pause=function(){n.pauseVideo(),Re.media.paused=!0},Re.media.stop=function(){n.stopVideo(),Re.media.paused=!0},Re.media.duration=n.getDuration(),Re.media.paused=!0,Re.media.currentTime=n.getCurrentTime(),Re.media.muted=n.isMuted(),v.title=n.getVideoData().title,Re.supported.full&&Re.media.querySelector("iframe").setAttribute("tabindex","-1"),Z(),h(Re.media,"timeupdate"),e.clearInterval(De.buffering),De.buffering=e.setInterval(function(){Re.media.buffered=n.getVideoLoadedFraction(),(null===Re.media.lastBuffered||Re.media.lastBufferedt?t=0:t>r&&(t=r),Ee(t);try{Re.media.currentTime=t.toFixed(4)}catch(s){}if(o(v.types.embed,Re.type)){switch(Re.type){case"youtube":Re.embed.seekTo(t);break;case"vimeo":Re.embed.setCurrentTime(t.toFixed(0));break;case"soundcloud":Re.embed.seekTo(1e3*t)}n&&se(),h(Re.media,"timeupdate"),Re.media.seeking=!0}We("Seeking to "+Re.media.currentTime+" seconds"),V(t)}function ue(){var e=parseInt(v.duration),t=0;return null===Re.media.duration||isNaN(Re.media.duration)||(t=Re.media.duration),isNaN(e)?t:e}function ce(){m(Re.container,v.classes.playing,!Re.media.paused),m(Re.container,v.classes.stopped,Re.media.paused),Fe(Re.media.paused)}function pe(){I={x:e.pageXOffset||0,y:e.pageYOffset||0}}function de(){e.scrollTo(I.x,I.y)}function me(e){var n=A.supportsFullScreen;if(n){if(!e||e.type!==A.fullScreenEventName)return void(A.isFullScreen(Re.container)?A.cancelFullScreen():(pe(),A.requestFullScreen(Re.container)));Re.isFullscreen=A.isFullScreen(Re.container)}else Re.isFullscreen=!Re.isFullscreen,t.body.style.overflow=Re.isFullscreen?"hidden":"";m(Re.container,v.classes.fullscreen.active,Re.isFullscreen),W(Re.isFullscreen),Re.buttons&&Re.buttons.fullscreen&&k(Re.buttons.fullscreen,Re.isFullscreen),h(Re.container,Re.isFullscreen?"enterfullscreen":"exitfullscreen",!0),!Re.isFullscreen&&n&&de()}function fe(e){if(P["boolean"](e)||(e=!Re.media.muted),k(Re.buttons.mute,e),Re.media.muted=e,0===Re.media.volume&&ye(v.volume),o(v.types.embed,Re.type)){switch(Re.type){case"youtube":Re.embed[Re.media.muted?"mute":"unMute"]();break;case"vimeo":case"soundcloud":Re.embed.setVolume(Re.media.muted?0:parseFloat(v.volume/v.volumeMax))}h(Re.media,"volumechange")}}function ye(e){var t=v.volumeMax,n=v.volumeMin;if(P.undefined(e)&&(e=Re.storage.volume),(null===e||isNaN(e))&&(e=v.volume),e>t&&(e=t),n>e&&(e=n),Re.media.volume=parseFloat(e/t),Re.volume.display&&(Re.volume.display.value=e),o(v.types.embed,Re.type)){switch(Re.type){case"youtube":Re.embed.setVolume(100*Re.media.volume);break;case"vimeo":case"soundcloud":Re.embed.setVolume(Re.media.volume)}h(Re.media,"volumechange")}Re.media.muted&&e>0&&fe()}function be(e){var t=Re.media.muted?0:Re.media.volume*v.volumeMax;P.number(e)||(e=v.volumeStep),ye(t+e)}function ve(e){var t=Re.media.muted?0:Re.media.volume*v.volumeMax;P.number(e)||(e=v.volumeStep),ye(t-e)}function ge(){var e=Re.media.muted?0:Re.media.volume*v.volumeMax;Re.supported.full&&(Re.volume.input&&(Re.volume.input.value=e),Re.volume.display&&(Re.volume.display.value=e)),G({volume:e}),m(Re.container,v.classes.muted,0===e),Re.supported.full&&Re.buttons.mute&&k(Re.buttons.mute,0===e)}function he(e){Re.supported.full&&Re.buttons.captions&&(P["boolean"](e)||(e=-1===Re.container.className.indexOf(v.classes.captions.active)),Re.captionsEnabled=e,k(Re.buttons.captions,Re.captionsEnabled),m(Re.container,v.classes.captions.active,Re.captionsEnabled),h(Re.container,Re.captionsEnabled?"captionsenabled":"captionsdisabled",!0),G({captionsEnabled:Re.captionsEnabled}))}function ke(e){var t="waiting"===e.type;clearTimeout(De.loading),De.loading=setTimeout(function(){m(Re.container,v.classes.loading,t)},t?250:0)}function we(e){if(Re.supported.full){var t=Re.progress.played,n=0,r=ue();if(e)switch(e.type){case"timeupdate":case"seeking":if(Re.controls.pressed)return;n=w(Re.media.currentTime,r),"timeupdate"===e.type&&Re.buttons.seek&&(Re.buttons.seek.value=n);break;case"playing":case"progress":t=Re.progress.buffer,n=function(){var e=Re.media.buffered;return e&&e.length?w(e.end(0),r):P.number(e)?100*e:0}()}Te(t,n)}}function Te(e,t){if(Re.supported.full){if(P.undefined(t)&&(t=0),P.undefined(e)){if(!Re.progress||!Re.progress.buffer)return;e=Re.progress.buffer}P.htmlElement(e)?e.value=t:e&&(e.bar&&(e.bar.value=t),e.text&&(e.text.innerHTML=t))}}function xe(e,t){if(t){isNaN(e)&&(e=0),Re.secs=parseInt(e%60),Re.mins=parseInt(e/60%60),Re.hours=parseInt(e/60/60%60);var n=parseInt(ue()/60/60%60)>0;Re.secs=("0"+Re.secs).slice(-2),Re.mins=("0"+Re.mins).slice(-2),t.innerHTML=(n?Re.hours+":":"")+Re.mins+":"+Re.secs}}function Se(){if(Re.supported.full){var e=ue()||0;!Re.duration&&v.displayDuration&&Re.media.paused&&xe(e,Re.currentTime),Re.duration&&xe(e,Re.duration),Ce()}}function _e(e){xe(Re.media.currentTime,Re.currentTime),e&&"timeupdate"===e.type&&Re.media.seeking||we(e)}function Ee(e){P.number(e)||(e=0);var t=ue(),n=w(e,t);Re.progress&&Re.progress.played&&(Re.progress.played.value=n),Re.buttons&&Re.buttons.seek&&(Re.buttons.seek.value=n)}function Ce(e){var t=ue();if(v.tooltips.seek&&Re.progress.container&&0!==t){var n=Re.progress.container.getBoundingClientRect(),r=0,s=v.classes.tooltip+"--visible";if(e)r=100/n.width*(e.pageX-n.left);else{if(!f(Re.progress.tooltip,s))return;r=Re.progress.tooltip.style.left.replace("%","")}0>r?r=0:r>100&&(r=100),xe(t/100*r,Re.progress.tooltip),Re.progress.tooltip.style.left=r+"%",e&&o(["mouseenter","mouseleave"],e.type)&&m(Re.progress.tooltip,s,"mouseenter"===e.type)}}function Fe(t){if(v.hideControls&&"audio"!==Re.type&&f(Re.container,v.classes.ready)){var n=0,r=!1,s=t;if(P["boolean"](t)||(t&&t.type?(r="enterfullscreen"===t.type,s=o(["mousemove","touchstart","mouseenter","focus"],t.type),o(["mousemove","touchmove"],t.type)&&(n=2e3),"focus"===t.type&&(n=3e3)):s=f(Re.container,v.classes.hideControls)),e.clearTimeout(De.hover),s||Re.media.paused){if(m(Re.container,v.classes.hideControls,!1),Re.media.paused)return;Re.browser.isTouch&&(n=3e3)}s&&Re.media.paused||(De.hover=e.setTimeout(function(){(!Re.controls.pressed&&!Re.controls.hover||r)&&m(Re.container,v.classes.hideControls,!0)},n))}}function Ae(e){if(!P.undefined(e))return void Ie(e);var t;switch(Re.type){case"youtube":t=Re.embed.getVideoUrl();break;case"vimeo":Re.embed.getVideoUrl.then(function(e){t=e});break;case"soundcloud":Re.embed.getCurrentSound(function(e){t=e.permalink_url});break;default:t=Re.media.currentSrc}return t||""}function Ie(e){function n(){if(Re.embed=null,"video"===Re.type&&Re.videoContainer&&l(Re.videoContainer),l(Re.media),Re.container&&Re.container.removeAttribute("class"),"type"in e&&(Re.type=e.type,"video"===Re.type)){var n=e.sources[0];"type"in n&&o(v.types.embed,n.type)&&(Re.type=n.type)}switch(Re.supported=E(Re.type),Re.type){case"video":Re.media=t.createElement("video");break;case"audio":Re.media=t.createElement("audio");break;case"youtube":case"vimeo":case"soundcloud":Re.media=t.createElement("div"),Re.embedId=e.sources[0].src}u(Re.container,Re.media),P["boolean"](e.autoplay)&&(v.autoplay=e.autoplay),o(v.types.html5,Re.type)&&(v.crossorigin&&Re.media.setAttribute("crossorigin",""),v.autoplay&&Re.media.setAttribute("autoplay",""),"poster"in e&&Re.media.setAttribute("poster",e.poster),v.loop&&Re.media.setAttribute("loop","")),m(Re.container,v.classes.fullscreen.active,Re.isFullscreen),m(Re.container,v.classes.captions.active,Re.captionsEnabled),U(),o(v.types.html5,Re.type)&&Y("source",e.sources),K(),o(v.types.html5,Re.type)?("tracks"in e&&Y("track",e.tracks),Re.media.load(),Ve(),Se(),qe()):o(v.types.embed,Re.type)&&!Re.supported.full&&(Ve(),qe()),v.title=e.title,z()}return P.object(e)&&"sources"in e&&e.sources.length?(se(),Ee(),Te(),Le(),m(Re.container,v.classes.ready,!1),void Oe(n,!1)):void Ye("Invalid source format")}function Ne(e){"video"===Re.type&&Re.media.setAttribute("poster",e)}function Pe(){function n(){var e=oe(),t=Re.buttons[e?"play":"pause"],n=Re.buttons[e?"pause":"play"];if(n=n&&n.length>1?n[n.length-1]:n[0]){var r=f(t,v.classes.tabFocus);setTimeout(function(){n.focus(),r&&(m(t,v.classes.tabFocus,!1),m(n,v.classes.tabFocus,!0))},100)}}function r(){var e=t.activeElement;return e=e&&e!==t.body?t.querySelector(":focus"):null}function s(e){return e.keyCode?e.keyCode:e.which}function a(e){for(var t in Re.buttons){var n=Re.buttons[t];if(P.nodeList(n))for(var r=0;r0)&&(t?ve(n):be(n)),(e.deltaY>0||e.deltaX<0)&&(t?be(n):ve(n))})}function Me(){if(g(Re.media,"timeupdate seeking",_e),g(Re.media,"timeupdate",V), -g(Re.media,"durationchange loadedmetadata",Se),g(Re.media,"ended",function(){"video"===Re.type&&j(),ce(),le(0),Se(),"video"===Re.type&&v.showPosterOnEnd&&Re.media.load()}),g(Re.media,"progress playing",we),g(Re.media,"volumechange",ge),g(Re.media,"play pause",ce),g(Re.media,"waiting canplay seeked",ke),v.clickToPlay&&"audio"!==Re.type){var e=D("."+v.classes.videoWrapper);if(!e)return;e.style.cursor="pointer",g(e,"click",function(){v.hideControls&&Re.browser.isTouch&&!Re.media.paused||(Re.media.paused?re():Re.media.ended?(le(),re()):se())})}v.disableContextMenu&&g(Re.media,"contextmenu",function(e){e.preventDefault()}),g(Re.media,v.events.join(" "),function(e){h(Re.container,e.type,!0)})}function Le(){if(o(v.types.html5,Re.type)){for(var e=Re.media.querySelectorAll("source"),t=0;t=0;n--){var r=n>0?t.cloneNode(!0):t,s=e[n],a=s.parentNode,o=s.nextSibling;return r.appendChild(s),o?a.insertBefore(r,o):a.appendChild(r),r}}function l(e){e&&e.parentNode.removeChild(e)}function u(e,t){e.insertBefore(t,e.firstChild)}function c(e,t){for(var n in t)e.setAttribute(n,P["boolean"](t[n])&&t[n]?"":t[n])}function p(e,n,r){var s=t.createElement(e);c(s,r),u(n,s)}function d(e){return e.replace(".","")}function m(e,t,n){if(e)if(e.classList)e.classList[n?"add":"remove"](t);else{var r=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=r+(n?" "+t:"")}}function f(e,t){return e?e.classList?e.classList.contains(t):new RegExp("(\\s|^)"+t+"(\\s|$)").test(e.className):!1}function y(e,n){var r=Element.prototype,s=r.matches||r.webkitMatchesSelector||r.mozMatchesSelector||r.msMatchesSelector||function(e){return-1!==[].indexOf.call(t.querySelectorAll(e),this)};return s.call(e,n)}function b(e,t,n,r,s){g(e,t,function(t){n&&n.apply(e,[t]),r.apply(e,[t])},s)}function v(e,t,n,r,s){var a=t.split(" ");if(P["boolean"](s)||(s=!1),e instanceof NodeList)for(var o=0;or;r++){var s=e[r];for(var a in s)s[a]&&s[a].constructor&&s[a].constructor===Object?(t[a]=t[a]||{},T(t[a],s[a])):t[a]=s[a]}return t}}function x(){var e={supportsFullScreen:!1,isFullScreen:function(){return!1},requestFullScreen:function(){},cancelFullScreen:function(){},fullScreenEventName:"",element:null,prefix:""},n="webkit moz o ms khtml".split(" ");if(P.undefined(t.cancelFullScreen))for(var r=0,s=n.length;s>r;r++){if(e.prefix=n[r],!P.undefined(t[e.prefix+"CancelFullScreen"])){e.supportsFullScreen=!0;break}if(!P.undefined(t.msExitFullscreen)&&t.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}else e.supportsFullScreen=!0;return e.supportsFullScreen&&(e.fullScreenEventName="ms"===e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(e){switch(P.undefined(e)&&(e=t.body),this.prefix){case"":return t.fullscreenElement===e;case"moz":return t.mozFullScreenElement===e;default:return t[this.prefix+"FullscreenElement"]===e}},e.requestFullScreen=function(e){return P.undefined(e)&&(e=t.body),""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"===this.prefix?"RequestFullscreen":"RequestFullScreen")]()},e.cancelFullScreen=function(){return""===this.prefix?t.cancelFullScreen():t[this.prefix+("ms"===this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?t.fullscreenElement:t[this.prefix+"FullscreenElement"]}),e}function S(y,v){function S(e,t,n,r){h(e,t,n,T({},r,{plyr:De}))}function C(t,n){v.debug&&e.console&&(n=Array.prototype.slice.call(n),P.string(v.logPrefix)&&v.logPrefix.length&&n.unshift(v.logPrefix),console[t].apply(console,n))}function F(){return{url:v.iconUrl,absolute:0===v.iconUrl.indexOf("http")||He.browser.isIE}}function L(){var e=[],t=F(),n=(t.absolute?"":t.url)+"#"+v.iconPrefix;return a(v.controls,"play-large")&&e.push('"),e.push('
'),a(v.controls,"restart")&&e.push('"),a(v.controls,"rewind")&&e.push('"),a(v.controls,"play")&&e.push('",'"),a(v.controls,"fast-forward")&&e.push('"),a(v.controls,"progress")&&(e.push('','','','','',"0% "+v.i18n.buffered,""),v.tooltips.seek&&e.push('00:00'),e.push("")),a(v.controls,"current-time")&&e.push('',''+v.i18n.currentTime+"",'00:00',""),a(v.controls,"duration")&&e.push('',''+v.i18n.duration+"",'00:00',""),a(v.controls,"mute")&&e.push('"),a(v.controls,"volume")&&e.push('','",'','',""),a(v.controls,"captions")&&e.push('"),a(v.controls,"fullscreen")&&e.push('"),e.push("
"),e.join("")}function O(){if(He.supported.full&&("audio"!==He.type||v.fullscreen.allowAudio)&&v.fullscreen.enabled){var e=A.supportsFullScreen;e||v.fullscreen.fallback&&!W()?(Be((e?"Native":"Fallback")+" fullscreen enabled"),m(He.container,v.classes.fullscreen.enabled,!0)):Be("Fullscreen not supported and fallback disabled"),He.buttons&&He.buttons.fullscreen&&k(He.buttons.fullscreen,!1),Y()}}function j(){if("video"===He.type){H(v.selectors.captions)||He.videoContainer.insertAdjacentHTML("afterbegin",'
'),He.usingTextTracks=!1,He.media.textTracks&&(He.usingTextTracks=!0);for(var e,t="",n=He.media.childNodes,r=0;r=10||He.browser.isFirefox&&He.browser.version>=31)&&(Be("Detected browser with known TextTrack issues - using manual fallback"),He.usingTextTracks=!1),He.usingTextTracks){Be("TextTracks supported");for(var o=0;o ");for(var r=0;rHe.captions.length-1){He.subcount=He.captions.length-1;break}He.media.currentTime.toFixed(1)>=n(He.captions[He.subcount][0])&&He.media.currentTime.toFixed(1)<=r(He.captions[He.subcount][0])?(He.currentCaption=He.captions[He.subcount][1],V(He.currentCaption)):V()}}function R(){if(He.buttons.captions){m(He.container,v.classes.captions.enabled,!0);var e=He.storage.captionsEnabled;P["boolean"](e)||(e=v.captions.defaultActive),e&&(m(He.container,v.classes.captions.active,!0),k(He.buttons.captions,!0))}}function D(e){return He.container.querySelectorAll(e)}function H(e){return D(e)[0]}function W(){try{return e.self!==e.top}catch(t){return!0}}function Y(){function e(e){9===e.which&&He.isFullscreen&&(e.target!==r||e.shiftKey?e.target===n&&e.shiftKey&&(e.preventDefault(),r.focus()):(e.preventDefault(),n.focus()))}var t=D("input:not([disabled]), button:not([disabled])"),n=t[0],r=t[t.length-1];g(He.container,"keydown",e)}function B(e,t){if(P.string(t))p(e,He.media,{src:t});else if(t.constructor===Array)for(var n=t.length-1;n>=0;n--)p(e,He.media,t[n])}function X(){if(v.loadSprite){var e=F();e.absolute?(Be("AJAX loading absolute SVG sprite"+(He.browser.isIE?" (due to IE)":"")),_(e.url,"sprite-plyr")):Be("Sprite will be used as external resource directly")}var n=v.html;Be("Injecting custom controls"),n||(n=L()),n=o(n,"{seektime}",v.seekTime),n=o(n,"{id}",Math.floor(1e4*Math.random()));var r;if(P.string(v.selectors.controls.container)&&(r=t.querySelector(v.selectors.controls.container)),P.htmlElement(r)||(r=He.container),r.insertAdjacentHTML("beforeend",n),v.tooltips.controls)for(var s=D([v.selectors.controls.wrapper," ",v.selectors.labels," .",v.classes.hidden].join("")),a=s.length-1;a>=0;a--){var i=s[a];m(i,v.classes.hidden,!1),m(i,v.classes.tooltip,!0)}}function U(){try{return He.controls=H(v.selectors.controls.wrapper),He.buttons={},He.buttons.seek=H(v.selectors.buttons.seek),He.buttons.play=D(v.selectors.buttons.play),He.buttons.pause=H(v.selectors.buttons.pause),He.buttons.restart=H(v.selectors.buttons.restart),He.buttons.rewind=H(v.selectors.buttons.rewind),He.buttons.forward=H(v.selectors.buttons.forward),He.buttons.fullscreen=H(v.selectors.buttons.fullscreen),He.buttons.mute=H(v.selectors.buttons.mute),He.buttons.captions=H(v.selectors.buttons.captions),He.progress={},He.progress.container=H(v.selectors.progress.container),He.progress.buffer={},He.progress.buffer.bar=H(v.selectors.progress.buffer),He.progress.buffer.text=He.progress.buffer.bar&&He.progress.buffer.bar.getElementsByTagName("span")[0],He.progress.played=H(v.selectors.progress.played),He.progress.tooltip=He.progress.container&&He.progress.container.querySelector("."+v.classes.tooltip),He.volume={},He.volume.input=H(v.selectors.volume.input),He.volume.display=H(v.selectors.volume.display),He.duration=H(v.selectors.duration),He.currentTime=H(v.selectors.currentTime),He.seekTime=D(v.selectors.seekTime),!0}catch(e){return Xe("It looks like there is a problem with your controls HTML"),z(!0),!1}}function J(){m(He.container,v.selectors.container.replace(".",""),He.supported.full)}function z(e){e&&a(v.types.html5,He.type)?He.media.setAttribute("controls",""):He.media.removeAttribute("controls")}function $(e){var t=v.i18n.play;if(P.string(v.title)&&v.title.length&&(t+=", "+v.title,He.container.setAttribute("aria-label",v.title)),He.supported.full&&He.buttons.play)for(var n=He.buttons.play.length-1;n>=0;n--)He.buttons.play[n].setAttribute("aria-label",t);P.htmlElement(e)&&e.setAttribute("title",v.i18n.frameTitle.replace("{title}",v.title))}function G(){var t=null;He.storage={},M.supported&&v.storage.enabled&&(e.localStorage.removeItem("plyr-volume"),t=e.localStorage.getItem(v.storage.key),t&&(/^\d+(\.\d+)?$/.test(t)?K({volume:parseFloat(t)}):He.storage=JSON.parse(t)))}function K(t){M.supported&&v.storage.enabled&&(T(He.storage,t),e.localStorage.setItem(v.storage.key,JSON.stringify(He.storage)))}function Q(){if(!He.media)return void Xe("No media element found!");if(He.supported.full&&(m(He.container,v.classes.type.replace("{0}",He.type),!0),a(v.types.embed,He.type)&&m(He.container,v.classes.type.replace("{0}","video"),!0),m(He.container,v.classes.stopped,v.autoplay),m(He.ontainer,v.classes.isIos,He.browser.isIos),m(He.container,v.classes.isTouch,He.browser.isTouch),"video"===He.type)){var e=t.createElement("div");e.setAttribute("class",v.classes.videoWrapper),i(He.media,e),He.videoContainer=e}a(v.types.embed,He.type)&&Z()}function Z(){for(var n=t.createElement("div"),r=He.embedId,a=He.type+"-"+Math.floor(1e4*Math.random()),o=D('[id^="'+He.type+'-"]'),i=o.length-1;i>=0;i--)l(o[i]);if(m(He.media,v.classes.videoWrapper,!0),m(He.media,v.classes.embedWrapper,!0),"youtube"===He.type)He.media.appendChild(n),n.setAttribute("id",a),P.object(e.YT)?te(r,n):(s(v.urls.youtube.api),e.onYouTubeReadyCallbacks=e.onYouTubeReadyCallbacks||[],e.onYouTubeReadyCallbacks.push(function(){te(r,n)}),e.onYouTubeIframeAPIReady=function(){e.onYouTubeReadyCallbacks.forEach(function(e){e()})});else if("vimeo"===He.type)if(He.supported.full?He.media.appendChild(n):n=He.media,n.setAttribute("id",a),P.object(e.Vimeo))ne(r,n);else{s(v.urls.vimeo.api);var u=e.setInterval(function(){P.object(e.Vimeo)&&(e.clearInterval(u),ne(r,n))},50)}else if("soundcloud"===He.type){var p=t.createElement("iframe");p.loaded=!1,g(p,"load",function(){p.loaded=!0}),c(p,{src:"https://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/"+r,id:a}),n.appendChild(p),He.media.appendChild(n),e.SC||s(v.urls.soundcloud.api);var d=e.setInterval(function(){e.SC&&p.loaded&&(e.clearInterval(d),re.call(p))},50)}}function ee(){He.supported.full&&(qe(),Re()),$(H("iframe"))}function te(t,n){He.embed=new e.YT.Player(n.id,{videoId:t,playerVars:{autoplay:v.autoplay?1:0,controls:He.supported.full?0:1,rel:0,showinfo:0,iv_load_policy:3,cc_load_policy:v.captions.defaultActive?1:0,cc_lang_pref:"en",wmode:"transparent",modestbranding:1,disablekb:1,origin:"*"},events:{onError:function(e){S(n,"error",!0,{code:e.data,embed:e.target})},onReady:function(t){var n=t.target;He.media.play=function(){n.playVideo(),He.media.paused=!1},He.media.pause=function(){n.pauseVideo(),He.media.paused=!0},He.media.stop=function(){n.stopVideo(),He.media.paused=!0},He.media.duration=n.getDuration(),He.media.paused=!0,He.media.currentTime=n.getCurrentTime(),He.media.muted=n.isMuted(),v.title=n.getVideoData().title,He.supported.full&&He.media.querySelector("iframe").setAttribute("tabindex","-1"),ee(),S(He.media,"timeupdate"),e.clearInterval(We.buffering),We.buffering=e.setInterval(function(){He.media.buffered=n.getVideoLoadedFraction(),(null===He.media.lastBuffered||He.media.lastBufferedt?t=0:t>r&&(t=r),Ce(t);try{He.media.currentTime=t.toFixed(4)}catch(s){}if(a(v.types.embed,He.type)){switch(He.type){case"youtube":He.embed.seekTo(t);break;case"vimeo":He.embed.setCurrentTime(t.toFixed(0));break;case"soundcloud":He.embed.seekTo(1e3*t)}n&&ae(),S(He.media,"timeupdate"),He.media.seeking=!0}Be("Seeking to "+He.media.currentTime+" seconds"),q(t)}function ce(){var e=parseInt(v.duration),t=0;return null===He.media.duration||isNaN(He.media.duration)||(t=He.media.duration),isNaN(e)?t:e}function pe(){m(He.container,v.classes.playing,!He.media.paused),m(He.container,v.classes.stopped,He.media.paused),Ae(He.media.paused)}function de(){I={x:e.pageXOffset||0,y:e.pageYOffset||0}}function me(){e.scrollTo(I.x,I.y)}function fe(e){var n=A.supportsFullScreen;if(n){if(!e||e.type!==A.fullScreenEventName)return void(A.isFullScreen(He.container)?A.cancelFullScreen():(de(),A.requestFullScreen(He.container)));He.isFullscreen=A.isFullScreen(He.container)}else He.isFullscreen=!He.isFullscreen,t.body.style.overflow=He.isFullscreen?"hidden":"";m(He.container,v.classes.fullscreen.active,He.isFullscreen),Y(He.isFullscreen),He.buttons&&He.buttons.fullscreen&&k(He.buttons.fullscreen,He.isFullscreen),S(He.container,He.isFullscreen?"enterfullscreen":"exitfullscreen",!0),!He.isFullscreen&&n&&me()}function ye(e){if(P["boolean"](e)||(e=!He.media.muted),k(He.buttons.mute,e),He.media.muted=e,0===He.media.volume&&be(v.volume),a(v.types.embed,He.type)){switch(He.type){case"youtube":He.embed[He.media.muted?"mute":"unMute"]();break;case"vimeo":case"soundcloud":He.embed.setVolume(He.media.muted?0:parseFloat(v.volume/v.volumeMax))}S(He.media,"volumechange")}}function be(e){var t=v.volumeMax,n=v.volumeMin;if(P.undefined(e)&&(e=He.storage.volume),(null===e||isNaN(e))&&(e=v.volume),e>t&&(e=t),n>e&&(e=n),He.media.volume=parseFloat(e/t),He.volume.display&&(He.volume.display.value=e),a(v.types.embed,He.type)){switch(He.type){case"youtube":He.embed.setVolume(100*He.media.volume);break;case"vimeo":case"soundcloud":He.embed.setVolume(He.media.volume)}S(He.media,"volumechange")}He.media.muted&&e>0&&ye()}function ve(e){var t=He.media.muted?0:He.media.volume*v.volumeMax;P.number(e)||(e=v.volumeStep),be(t+e)}function ge(e){var t=He.media.muted?0:He.media.volume*v.volumeMax;P.number(e)||(e=v.volumeStep),be(t-e)}function he(){var e=He.media.muted?0:He.media.volume*v.volumeMax;He.supported.full&&(He.volume.input&&(He.volume.input.value=e),He.volume.display&&(He.volume.display.value=e)),K({volume:e}),m(He.container,v.classes.muted,0===e),He.supported.full&&He.buttons.mute&&k(He.buttons.mute,0===e)}function ke(e){He.supported.full&&He.buttons.captions&&(P["boolean"](e)||(e=-1===He.container.className.indexOf(v.classes.captions.active)),He.captionsEnabled=e,k(He.buttons.captions,He.captionsEnabled),m(He.container,v.classes.captions.active,He.captionsEnabled),S(He.container,He.captionsEnabled?"captionsenabled":"captionsdisabled",!0),K({captionsEnabled:He.captionsEnabled}))}function we(e){var t="waiting"===e.type;clearTimeout(We.loading),We.loading=setTimeout(function(){m(He.container,v.classes.loading,t)},t?250:0)}function Te(e){if(He.supported.full){var t=He.progress.played,n=0,r=ce();if(e)switch(e.type){case"timeupdate":case"seeking":if(He.controls.pressed)return;n=w(He.media.currentTime,r),"timeupdate"===e.type&&He.buttons.seek&&(He.buttons.seek.value=n);break;case"playing":case"progress":t=He.progress.buffer,n=function(){var e=He.media.buffered;return e&&e.length?w(e.end(0),r):P.number(e)?100*e:0}()}xe(t,n)}}function xe(e,t){if(He.supported.full){if(P.undefined(t)&&(t=0),P.undefined(e)){if(!He.progress||!He.progress.buffer)return;e=He.progress.buffer}P.htmlElement(e)?e.value=t:e&&(e.bar&&(e.bar.value=t),e.text&&(e.text.innerHTML=t))}}function Se(e,t){if(t){isNaN(e)&&(e=0),He.secs=parseInt(e%60),He.mins=parseInt(e/60%60),He.hours=parseInt(e/60/60%60);var n=parseInt(ce()/60/60%60)>0;He.secs=("0"+He.secs).slice(-2),He.mins=("0"+He.mins).slice(-2),t.innerHTML=(n?He.hours+":":"")+He.mins+":"+He.secs}}function _e(){if(He.supported.full){var e=ce()||0;!He.duration&&v.displayDuration&&He.media.paused&&Se(e,He.currentTime),He.duration&&Se(e,He.duration),Fe()}}function Ee(e){Se(He.media.currentTime,He.currentTime),e&&"timeupdate"===e.type&&He.media.seeking||Te(e)}function Ce(e){P.number(e)||(e=0);var t=ce(),n=w(e,t);He.progress&&He.progress.played&&(He.progress.played.value=n),He.buttons&&He.buttons.seek&&(He.buttons.seek.value=n)}function Fe(e){var t=ce();if(v.tooltips.seek&&He.progress.container&&0!==t){var n=He.progress.container.getBoundingClientRect(),r=0,s=v.classes.tooltip+"--visible";if(e)r=100/n.width*(e.pageX-n.left);else{if(!f(He.progress.tooltip,s))return;r=He.progress.tooltip.style.left.replace("%","")}0>r?r=0:r>100&&(r=100),Se(t/100*r,He.progress.tooltip),He.progress.tooltip.style.left=r+"%",e&&a(["mouseenter","mouseleave"],e.type)&&m(He.progress.tooltip,s,"mouseenter"===e.type)}}function Ae(t){if(v.hideControls&&"audio"!==He.type&&f(He.container,v.classes.ready)){var n=0,r=!1,s=t;if(P["boolean"](t)||(t&&t.type?(r="enterfullscreen"===t.type,s=a(["mousemove","touchstart","mouseenter","focus"],t.type),a(["mousemove","touchmove"],t.type)&&(n=2e3),"focus"===t.type&&(n=3e3)):s=f(He.container,v.classes.hideControls)),e.clearTimeout(We.hover),s||He.media.paused){if(m(He.container,v.classes.hideControls,!1),He.media.paused)return;He.browser.isTouch&&(n=3e3)}s&&He.media.paused||(We.hover=e.setTimeout(function(){(!He.controls.pressed&&!He.controls.hover||r)&&m(He.container,v.classes.hideControls,!0)},n))}}function Ie(e){if(!P.undefined(e))return void Ne(e);var t;switch(He.type){case"youtube":t=He.embed.getVideoUrl();break;case"vimeo":He.embed.getVideoUrl.then(function(e){t=e});break;case"soundcloud":He.embed.getCurrentSound(function(e){t=e.permalink_url});break;default:t=He.media.currentSrc}return t||""}function Ne(e){function n(){if(He.embed=null,"video"===He.type&&He.videoContainer&&l(He.videoContainer),l(He.media),He.container&&He.container.removeAttribute("class"),"type"in e&&(He.type=e.type,"video"===He.type)){var n=e.sources[0];"type"in n&&a(v.types.embed,n.type)&&(He.type=n.type)}switch(He.supported=E(He.type),He.type){case"video":He.media=t.createElement("video");break;case"audio":He.media=t.createElement("audio");break;case"youtube":case"vimeo":case"soundcloud":He.media=t.createElement("div"),He.embedId=e.sources[0].src}u(He.container,He.media),P["boolean"](e.autoplay)&&(v.autoplay=e.autoplay),a(v.types.html5,He.type)&&(v.crossorigin&&He.media.setAttribute("crossorigin",""),v.autoplay&&He.media.setAttribute("autoplay",""),"poster"in e&&He.media.setAttribute("poster",e.poster),v.loop&&He.media.setAttribute("loop","")),m(He.container,v.classes.fullscreen.active,He.isFullscreen),m(He.container,v.classes.captions.active,He.captionsEnabled),J(),a(v.types.html5,He.type)&&B("source",e.sources),Q(),a(v.types.html5,He.type)?("tracks"in e&&B("track",e.tracks),He.media.load(),qe(),_e(),Re()):a(v.types.embed,He.type)&&!He.supported.full&&(qe(),Re()),v.title=e.title,$()}return P.object(e)&&"sources"in e&&e.sources.length?(ae(),Ce(),xe(),Oe(),m(He.container,v.classes.ready,!1),void je(n,!1)):void Xe("Invalid source format")}function Pe(e){"video"===He.type&&He.media.setAttribute("poster",e)}function Me(){function n(){var e=oe(),t=He.buttons[e?"play":"pause"],n=He.buttons[e?"pause":"play"];if(n=n&&n.length>1?n[n.length-1]:n[0]){var r=f(t,v.classes.tabFocus);setTimeout(function(){n.focus(),r&&(m(t,v.classes.tabFocus,!1),m(n,v.classes.tabFocus,!0))},100)}}function r(){var e=t.activeElement;return e=e&&e!==t.body?t.querySelector(":focus"):null}function s(e){return e.keyCode?e.keyCode:e.which}function o(e){for(var t in He.buttons){var n=He.buttons[t];if(P.nodeList(n))for(var r=0;r0)&&(t?ge(n):ve(n)),(e.deltaY>0||e.deltaX<0)&&(t?ve(n):ge(n))})}function Le(){if(g(He.media,"timeupdate seeking",Ee),g(He.media,"timeupdate",q),g(He.media,"durationchange loadedmetadata",_e),g(He.media,"ended",function(){"video"===He.type&&V(),pe(),ue(0),_e(),"video"===He.type&&v.showPosterOnEnd&&He.media.load()}),g(He.media,"progress playing",Te),g(He.media,"volumechange",he),g(He.media,"play pause",pe),g(He.media,"waiting canplay seeked",we),v.clickToPlay&&"audio"!==He.type){var e=H("."+v.classes.videoWrapper);if(!e)return;e.style.cursor="pointer",g(e,"click",function(){v.hideControls&&He.browser.isTouch&&!He.media.paused||(He.media.paused?se():He.media.ended?(ue(),se()):ae())})}v.disableContextMenu&&g(He.media,"contextmenu",function(e){e.preventDefault()}),g(He.media,v.events.join(" "),function(e){S(He.container,e.type,!0)})}function Oe(){if(a(v.types.html5,He.type)){for(var e=He.media.querySelectorAll("source"),t=0;t` elements whereby touching the track to set the value doesn't work and sliding the thumb can be tricky. To combat this, I've created [RangeTouch](https://rangetouch.com) which I'd recommend including in your solution. It's a tiny script with a nice benefit for users on touch devices. @@ -318,6 +318,12 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke false This will restore and *reload* HTML5 video once playback is complete. Note: depending on the browser caching, this may result in the video downloading again (or parts of it). Use with caution. + + keyboardShortcuts + Boolean + true + Enable keyboard shortcuts + tooltips Object @@ -414,29 +420,36 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke ## API -#### Getting the `plyr` instance -A `plyr` object is added to any element that Plyr is initialized on. You can then control the player by accessing methods in the `plyr` object. +### Instance -There are two ways to access the instance, firstly you re-query the element container you used for setup (e.g. `.js-player`) like so: +The easiest way to access the plyr instances is to store the return value from your call to `setup()`: ```javascript -var player = document.querySelector('.js-player').plyr; +var players = plyr.setup('.js-player'); ``` -You can listen for the `setup` [event](#events) on the container, after which the `plyr` key will be available and also passed in the to your callback (in the `plyr` key of the event object). - -The other method is using the return value from the call to `setup()`. An array of instances is returned so you need to use an index: +This will return an array of all instances that were setup. Another way is to use `plyr.get()` to get all instances within a given container, for example: ```javascript -var player = plyr.setup('.js-player')[0].plyr; +var players = plyr.get('.js-player'); ``` -This will return an array of plyr instances that were setup, so you need to specify the index of the instance you want or loop through of course. This is less useful if you are setting up multiple instances. +If no argument is passed, it will find all instances in the current document. This will return an array of all instances that were found in the given selector. -Once you have your instance, you can use the API methods below on it. For example to pause it: +A final option is to access the instance through the event handlers: ```javascript -player.pause(); +instance.on('ready', function(event) { + var instance = event.detail.plyr; +}); +``` + +### Methods + +Once you have your instances, you can use the API methods below on it. For example to pause the first player: + +```javascript +players[0].pause(); ``` Here's a list of the methods supported: @@ -450,6 +463,36 @@ Here's a list of the methods supported: + + getContainer() + — + Get the players outer container element that is automatically injected. + + + getMedia() + — + Get the media element (>video<, >audio< or >div< for YouTube or Vimeo). + + + getEmbed() + — + Get the embed API to access those methods - either YouTube or Vimeo. + + + getType() + — + Get the type - 'video', 'audio', 'youtube' or 'vimeo'. + + + isReady() + — + Determine if the player is ready to accept API calls - this is because HTML5 is ready instantly but YouTube and Vimeo can take some time to load their APIs. + + + on() + String, Function + Watch for an event (first argument) and run a callback function (second argument). This saves you doing your own addEventListners. + play() — @@ -460,7 +503,12 @@ Here's a list of the methods supported: — Pauses the media - + + stop() + — + Stops the media + + restart() — Restarts playback @@ -660,172 +708,215 @@ Some more details on the object parameters ## Events -You can listen for events on the target element you setup Plyr on (see example under the table). Some events only apply to HTML5 audio and video. +You can listen for events on the target element you setup Plyr on (see example under the table). Some events only apply to HTML5 audio and video. Using your reference to the instance, you can use the `on()` API method or `addEventListener()`. Access to the API can be obtained this way through the `event.detail.plyr` property. Here's an example: + +```javascript +instance.on('ready', function(event) { + var instance = event.detail.plyr; +}); +``` + +These events also bubble up the DOM. The event target will be the container element. - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Event nameHTML5 onlyHTML5 only Description
canplaySent when enough data is available that the media can be played, at least for a couple of frames. This corresponds to the HAVE_ENOUGH_DATA readyState.
canplaythroughSent when the ready state changes to CAN_PLAY_THROUGH, indicating that the entire media can be played without interruption, assuming the download rate remains at least at the current level. Note: Manually setting the currentTime will eventually fire a canplaythrough event in firefox. Other browsers might not fire this event.
emptiedThe media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the load() method is called to reload it.
endedSent when playback completes.
errorSent when an error occurs.  The element's error attribute contains more information.
loadeddataThe first frame of the media has finished loading.
loadedmetadataThe media's metadata has finished loading; all attributes now contain as much useful information as they're going to.
loadstartSent when loading of the media begins.
pauseSent when playback is paused.
playSent when playback of the media starts after having been paused; that is, when playback is resumed after a prior pause event.
playingSent when the media begins to play (either for the first time, after having been paused, or after ending and then restarting).
progressSent periodically to inform interested parties of progress downloading the media. Information about the current amount of the media that has been downloaded is available in the media element's buffered attribute.
seekedSent when a seek operation completes.
seekingSent when a seek operation begins.
stalledSent when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
timeupdateThe time indicated by the element's currentTime attribute has changed.
volumechangeSent when the audio volume changes (both when the volume is set and when the muted attribute is changed).
waitingSent when the requested operation (such as playback) is delayed pending the completion of another operation (such as a seek).
enterfullscreenUser enters fullscreen (either the proper fullscreen or full-window fallback for older browsers)
exitfullscreenUser exits fullscreen
captionsenabledCaptions toggled on
captionsdisabledCaptions toggled off
readyTriggered when initial setup is done or a source change has occurred.
setupWhen an initial setup has completed
readyTriggered when the instance is ready for API use and external APIs are ready (YouTube and Vimeo).
canplaySent when enough data is available that the media can be played, at least for a couple of frames. This corresponds to the HAVE_ENOUGH_DATA readyState.
canplaythroughSent when the ready state changes to CAN_PLAY_THROUGH, indicating that the entire media can be played without interruption, assuming the download rate remains at least at the current level. Note: Manually setting the currentTime will eventually fire a canplaythrough event in firefox. Other browsers might not fire this event.
emptiedThe media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the load() method is called to reload it.
endedSent when playback completes.
errorSent when an error occurs.  The element's error attribute contains more information.
loadeddataThe first frame of the media has finished loading.
loadedmetadataThe media's metadata has finished loading; all attributes now contain as much useful information as they're going to.
loadstartSent when loading of the media begins.
pauseSent when playback is paused.
playSent when playback of the media starts after having been paused; that is, when playback is resumed after a prior pause event.
playingSent when the media begins to play (either for the first time, after having been paused, or after ending and then restarting).
progressSent periodically to inform interested parties of progress downloading the media. Information about the current amount of the media that has been downloaded is available in the media element's buffered attribute.
seekedSent when a seek operation completes.
seekingSent when a seek operation begins.
stalledSent when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
timeupdateThe time indicated by the element's currentTime attribute has changed.
volumechangeSent when the audio volume changes (both when the volume is set and when the muted attribute is changed).
waitingSent when the requested operation (such as playback) is delayed pending the completion of another operation (such as a seek).
enterfullscreenUser enters fullscreen (either the proper fullscreen or full-window fallback for older browsers)
exitfullscreenUser exits fullscreen
captionsenabledCaptions toggled on
captionsdisabledCaptions toggled off
destroyedWhen an instance is destroyed. The original element that replaced the container will be the event target.
Details borrowed from: [https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events) -Here's an example of binding an event listener: - -```javascript -document.querySelector('.js-plyr').addEventListener('ready', function(event) { - var player = event.target.plyr; -}); -``` - -These events also bubble up the DOM. - ## Embeds YouTube and Vimeo are currently supported and function much like a HTML5 video. Check the relevant documentation sections for any differences. Plyr references a custom version of the Vimeo Froogaloop API as Vimeo have neglected to maintain the library and there were bugs with their version. You don't need to worry about including your own versions of the Vimeo or YouTube JavaScript APIs. -The native API's can be accessed through the `embed` property of the plyr object. For example: - -```javascript -document.querySelector('.js-plyr').addEventListener('ready', function(event) { - var player = event.target.plyr; - - // YouTube - console.log(player.embed.getVideoData()); - - // Vimeo - console.log(player.embed.api('getColor')); -}); -``` +The embed third party API's can be accessed through the `getEmbed()` API method. More info on the respective API's here: -[YouTube API Reference](https://developers.google.com/youtube/js_api_reference) -[Vimeo API Reference](https://developer.vimeo.com/player/js-api#reference) + +- [YouTube API Reference](https://developers.google.com/youtube/js_api_reference) +- [Vimeo API Reference](https://developer.vimeo.com/player/js-api#reference) *Please note*: not all API methods may work 100%. Your mileage may vary. It's better to use the universal plyr API where possible. +## Shortcuts +By default, a focused player will bind the following keyboard shortcuts: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyAction
0 to 9Seek from 0 to 90% respectively
space or KToggle playback
Seek forward by the seekTime option
Increase volume
Decrease volume
MToggle mute
FToggle fullscreen
CToggle captions
+ ## Streaming Because Plyr is an extension of the standard HTML5 video and audio elements, third party streaming plugins can be used with Plyr. Massive thanks to Matias Russitto ([@russitto](https://github.com/russitto)) for working on this. Here's a few examples: diff --git a/src/js/plyr.js b/src/js/plyr.js index 31f3c5bc..9f0b4690 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -489,9 +489,9 @@ }*/ // Trigger event - function _triggerEvent(element, eventName, bubbles, properties) { + function _event(element, type, bubbles, properties) { // Bail if no element - if (!element || !eventName) { + if (!element || !type) { return; } @@ -501,7 +501,7 @@ } // Create and dispatch the event - var event = new CustomEvent(eventName, { + var event = new CustomEvent(type, { bubbles: bubbles, detail: properties }); @@ -709,12 +709,20 @@ // Player instance function Plyr(media, config) { var plyr = this, - timers = {}; + timers = {}, + api; // Set media plyr.media = media; var original = media.cloneNode(true); + // Trigger events, with plyr instance passed + function _triggerEvent(element, type, bubbles, properties) { + _event(element, type, bubbles, _extend({}, properties, { + plyr: api + })); + } + // Debugging function _console(type, args) { if (config.debug && window.console) { @@ -2906,25 +2914,52 @@ first = true, timer; + // Seek by the number keys + function seekByKey() { + // Get current duration + var duration = plyr.media.duration; + + // Bail if we have no duration set + if (!_is.number(duration)) { + return; + } + + // Divide the max duration into 10th's and times by the number value + _seek((duration / 10) * (code - 48)); + } + function handleKey() { + console.log(code); + switch(code) { + // 0-9 + case 48: + case 49: + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: if (first) { seekByKey() } break; // Space and K key case 32: - case 75: if (first) { _togglePlay(); } break; + case 75: if (first) { _togglePlay() } break; // Arrow up case 38: _increaseVolume(); break; // Arrow down case 40: _decreaseVolume(); break; // M key - case 77: if (first) { _toggleMute(); } break; + case 77: if (first) { _toggleMute() } break; // Arrow forward case 39: _forward(); break; // Arrow back case 37: _rewind(); break; // F key - case 70: if (first) { _toggleFullscreen(); } break; + case 70: if (first) { _toggleFullscreen() } break; // C key - case 67: if (first) { _toggleCaptions(); } break; + case 67: if (first) { _toggleCaptions() } break; } // Escape is handle natively when in full screen @@ -3399,7 +3434,7 @@ _displayDuration(); } - var api = { + api = { getOriginal: function() { return original; }, getContainer: function() { return plyr.container }, getEmbed: function() { return plyr.embed; }, @@ -3636,12 +3671,12 @@ var events = config.events.concat(['setup', 'ready', 'statechange', 'enterfullscreen', 'exitfullscreen', 'captionsenabled', 'captionsdisabled']); _on(instance.getContainer(), events.join(' '), function() { - console.log([config.logPrefix, 'event:', event.type].join(' ')); + console.log([config.logPrefix, 'event:', event.type].join(' '), event.detail.plyr); }); } // Callback - _triggerEvent(instance.getContainer(), 'setup', true, { + _event(instance.getContainer(), 'setup', true, { plyr: instance });