From 73de5b577342d4035f71bb595c922cc89000d7f6 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Mon, 30 Mar 2015 21:03:48 +1100 Subject: [PATCH] Added displayDuration option, small bug fix - Using the native VTT cues, sometimes cues would not disappear --- changelog.md | 3 +++ dist/plyr.js | 2 +- docs/error.html | 2 +- docs/index.html | 10 +++++----- package.json | 2 +- readme.md | 14 ++++++++++---- src/js/plyr.js | 48 +++++++++++++++++++++++++++++++++++------------- 7 files changed, 56 insertions(+), 25 deletions(-) diff --git a/changelog.md b/changelog.md index 86d9e7a7..0fd911e6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## v1.0.31 +- Display duration on metadataloaded + ## v1.0.30 - Fixed bug with media longer than 60 minutes (Fixes #69) diff --git a/dist/plyr.js b/dist/plyr.js index 2dbd7b1a..636b0c8c 100644 --- a/dist/plyr.js +++ b/dist/plyr.js @@ -1 +1 @@ -!function(e){"use strict";function t(e,t){x.debug&&window.console&&console[t?"error":"log"](e)}function n(){var e,t,n,r=navigator.userAgent,s=navigator.appName,a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10);return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(s="IE",a="11;"):-1!==(t=r.indexOf("MSIE"))?(s="IE",a=r.substring(t+5)):-1!==(t=r.indexOf("Chrome"))?(s="Chrome",a=r.substring(t+7)):-1!==(t=r.indexOf("Safari"))?(s="Safari",a=r.substring(t+7),-1!==(t=r.indexOf("Version"))&&(a=r.substring(t+8))):-1!==(t=r.indexOf("Firefox"))?(s="Firefox",a=r.substring(t+8)):(e=r.lastIndexOf(" ")+1)<(t=r.lastIndexOf("/"))&&(s=r.substring(e,t),a=r.substring(t+1),s.toLowerCase()==s.toUpperCase()&&(s=navigator.appName)),-1!==(n=a.indexOf(";"))&&(a=a.substring(0,n)),-1!==(n=a.indexOf(" "))&&(a=a.substring(0,n)),o=parseInt(""+a,10),isNaN(o)&&(a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10)),{name:s,version:o,ios:/(iPad|iPhone|iPod)/g.test(navigator.platform)}}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,t,n){return e.replace(new RegExp(t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),n)}function a(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],a=s.parentNode,o=s.nextSibling;r.appendChild(s),o?a.insertBefore(r,o):a.appendChild(r)}}function o(e){e.parentNode.removeChild(e)}function i(e,t){e.insertBefore(t,e.firstChild)}function l(e,t){for(var n in t)e.setAttribute(n,t[n])}function c(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 u(e,t,n,r){if(t=t.split(" "),e instanceof NodeList)for(var s=0;sn;n++){if(e.prefix=t[n],"undefined"!=typeof document[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}if("undefined"!=typeof document.msExitFullscreen&&document.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}return"webkit"===e.prefix&&navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)&&(e.supportsFullScreen=!1),e.supportsFullScreen&&(e.fullScreenEventName="ms"==e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(){switch(this.prefix){case"":return document.fullScreen;case"webkit":return document.webkitIsFullScreen;case"ms":return null!==document.msFullscreenElement;default:return document[this.prefix+"FullScreen"]}},e.requestFullScreen=function(e){return""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"==this.prefix?"RequestFullscreen":"RequestFullScreen")]("webkit"===this.prefix?e.ALLOW_KEYBOARD_INPUT:null)},e.cancelFullScreen=function(){return""===this.prefix?document.cancelFullScreen():document[this.prefix+("ms"==this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?document.fullscreenElement:document[this.prefix+"FullscreenElement"]}),e}function b(){var e={supported:function(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}()};return e}function h(u){function f(e){if(!tt.usingTextTracks&&"video"===tt.type&&tt.supported.full){for(tt.subcount=0,e="number"==typeof e?e:tt.media.currentTime;w(tt.captions[tt.subcount][0])tt.captions.length-1){tt.subcount=tt.captions.length-1;break}tt.media.currentTime.toFixed(1)>=h(tt.captions[tt.subcount][0])&&tt.media.currentTime.toFixed(1)<=w(tt.captions[tt.subcount][0])?(tt.currentCaption=tt.captions[tt.subcount][1],tt.captionsContainer.innerHTML=tt.currentCaption):tt.captionsContainer.innerHTML=""}}function y(){c(tt.container,x.classes.captions.enabled,!0),x.captions.defaultActive&&(c(tt.container,x.classes.captions.active,!0),tt.buttons.captions.checked=!0)}function h(e){var t=[];return t=e.split(" --> "),T(t[0])}function w(e){var t=[];return t=e.split(" --> "),T(t[1])}function T(e){if(null===e||void 0===e)return 0;var t,n=[],r=[];return n=e.split(","),r=n[0].split(":"),t=Math.floor(60*r[0]*60)+Math.floor(60*r[1])+Math.floor(r[2])}function S(e){return tt.container.querySelectorAll(e)}function F(e){return S(e)[0]}function C(){try{return window.self!==window.top}catch(e){return!0}}function E(){t("Injecting custom controls.");var e=x.html;if(e=s(e,"{seektime}",x.seekTime),e=s(e,"{id}",tt.random),tt.container.insertAdjacentHTML("beforeend",e),x.tooltips)for(var n=S(x.selectors.labels),r=n.length-1;r>=0;r--){var a=n[r];c(a,x.classes.hidden,!1),c(a,x.classes.tooltip,!0)}}function N(){try{return tt.controls=F(x.selectors.controls),tt.buttons={},tt.buttons.seek=F(x.selectors.buttons.seek),tt.buttons.play=F(x.selectors.buttons.play),tt.buttons.pause=F(x.selectors.buttons.pause),tt.buttons.restart=F(x.selectors.buttons.restart),tt.buttons.rewind=F(x.selectors.buttons.rewind),tt.buttons.forward=F(x.selectors.buttons.forward),tt.buttons.fullscreen=F(x.selectors.buttons.fullscreen),tt.buttons.mute=F(x.selectors.buttons.mute),tt.buttons.captions=F(x.selectors.buttons.captions),tt.checkboxes=S("[type='checkbox']"),tt.progress={},tt.progress.container=F(x.selectors.progress.container),tt.progress.buffer={},tt.progress.buffer.bar=F(x.selectors.progress.buffer),tt.progress.buffer.text=tt.progress.buffer.bar.getElementsByTagName("span")[0],tt.progress.played={},tt.progress.played.bar=F(x.selectors.progress.played),tt.progress.played.text=tt.progress.played.bar.getElementsByTagName("span")[0],tt.volume=F(x.selectors.buttons.volume),tt.duration=F(x.selectors.duration),tt.seekTime=S(x.selectors.seekTime),!0}catch(e){return t("It looks like there's a problem with your controls html. Bailing.",!0),!1}}function A(){var e=tt.buttons.play.innerText||"Play";"undefined"!=typeof x.title&&x.title.length&&(e+=", "+x.title),tt.buttons.play.setAttribute("aria-label",e)}function P(){if(!tt.media)return t("No audio or video element found!",!0),!1;if(tt.supported.full&&(tt.media.removeAttribute("controls"),c(tt.container,x.classes[tt.type],!0),c(tt.container,x.classes.stopped,null===tt.media.getAttribute("autoplay")),tt.browser.ios&&c(tt.container,"ios",!0),"video"===tt.type)){var e=document.createElement("div");e.setAttribute("class",x.classes.videoWrapper),a(tt.media,e),tt.videoContainer=e}null!==tt.media.getAttribute("autoplay")&&L()}function I(){if("video"===tt.type){tt.videoContainer.insertAdjacentHTML("afterbegin","
"),tt.captionsContainer=F(x.selectors.captions),tt.usingTextTracks=!1,tt.media.textTracks&&(tt.usingTextTracks=!0);for(var e,n="",r=tt.media.childNodes,s=0;s=31||"Safari"===tt.browser.name&&tt.browser.version>=7)&&(t("Detected IE 10/11 or Firefox 31+ or Safari 7+."),tt.usingTextTracks=!1),tt.usingTextTracks){t("TextTracks supported.");for(var i=0;i=7){t("Safari 7+ detected; removing track from DOM."),a=tt.media.getElementsByTagName("track");for(var d=0;dn?n=0:n>tt.media.duration&&(n=tt.media.duration);try{tt.media.currentTime=n.toFixed(1)}catch(r){}t("Seeking to "+tt.media.currentTime+" seconds"),f(n)}function R(){c(tt.container,x.classes.playing,!tt.media.paused),c(tt.container,x.classes.stopped,tt.media.paused)}function j(e){var t=k.supportsFullScreen;e&&e.type===k.fullScreenEventName?x.fullscreen.active=k.isFullScreen():t?(k.isFullScreen()?k.cancelFullScreen():k.requestFullScreen(tt.container),x.fullscreen.active=k.isFullScreen()):(x.fullscreen.active=!x.fullscreen.active,x.fullscreen.active?(p(document,"keyup",B),document.body.style.overflow="hidden"):(d(document,"keyup",B),document.body.style.overflow="")),c(tt.container,x.classes.fullscreen.active,x.fullscreen.active)}function B(e){27===(e.which||e.charCode||e.keyCode)&&x.fullscreen.active&&j()}function W(e){"undefined"==typeof e&&(e=x.storage.enabled&&b().supported?window.localStorage[x.storage.key]||x.volume:x.volume),e>10&&(e=10),tt.supported.full&&(tt.volume.value=e),tt.media.volume=parseFloat(e/10),U(),x.storage.enabled&&b().supported&&(window.localStorage.plyr_volume=e)}function _(e){"undefined"==typeof e&&(e=!tt.media.muted),tt.supported.full&&(tt.buttons.mute.checked=e),tt.media.muted=e,U()}function D(e){tt.supported.full&&("undefined"==typeof e&&(e=-1===tt.container.className.indexOf(x.classes.captions.active),tt.buttons.captions.checked=e),c(tt.container,x.classes.captions.active,e))}function U(){c(tt.container,x.classes.muted,0===tt.media.volume||tt.media.muted)}function X(e){var t="waiting"===e.type;clearTimeout(tt.loadingTimer),tt.loadingTimer=setTimeout(function(){c(tt.container,x.classes.loading,t)},t?250:0)}function J(e){var t=tt.progress.played.bar,n=tt.progress.played.text,r=0;if(e)switch(e.type){case"timeupdate":case"seeking":r=v(tt.media.currentTime,tt.media.duration),"timeupdate"==e.type&&(tt.buttons.seek.value=r);break;case"change":case"input":r=e.target.value;break;case"playing":case"progress":t=tt.progress.buffer.bar,n=tt.progress.buffer.text,r=function(){var e=tt.media.buffered;return e.length?v(e.end(0),tt.media.duration):0}()}t.value=r,n.innerHTML=r}function $(){tt.secs=parseInt(tt.media.currentTime%60),tt.mins=parseInt(tt.media.currentTime/60%60),tt.hours=parseInt(tt.media.currentTime/60/60%60),tt.secs=("0"+tt.secs).slice(-2),tt.mins=("0"+tt.mins).slice(-2),tt.duration.innerHTML=(tt.hours>0?tt.hours+":":"")+tt.mins+":"+tt.secs}function z(e){$(),J(e)}function K(){for(var e=tt.media.querySelectorAll("source"),t=e.length-1;t>=0;t--)o(e[t]);tt.media.removeAttribute("src")}function Y(e){if(e.src){var t=document.createElement("source");l(t,e),i(tt.media,t)}}function G(e){if(O(),H(),K(),"string"==typeof e)tt.media.setAttribute("src",e);else if(e.constructor===Array)for(var t in e)Y(e[t]);tt.supported.full&&(z(),R()),tt.media.load(),null!==tt.media.getAttribute("autoplay")&&L()}function Q(e){"video"===tt.type&&tt.media.setAttribute("poster",e)}function Z(){p(tt.buttons.play,"click",function(){L(),setTimeout(function(){tt.buttons.pause.focus()},100)}),p(tt.buttons.pause,"click",function(){O(),setTimeout(function(){tt.buttons.play.focus()},100)}),p(tt.buttons.restart,"click",H),p(tt.buttons.rewind,"click",q),p(tt.buttons.forward,"click",V),p(tt.volume,"change input",function(){W(this.value)}),p(tt.buttons.mute,"change",function(){_(this.checked)}),p(tt.buttons.fullscreen,"click",j),k.supportsFullScreen&&p(document,k.fullScreenEventName,j),p(tt.media,"timeupdate seeking",z),p(tt.media,"timeupdate",f),p(tt.buttons.seek,"change input",H),p(tt.buttons.captions,"change",function(){D(this.checked)}),p(tt.media,"ended",function(){"video"===tt.type&&(tt.captionsContainer.innerHTML=""),R()}),p(tt.media,"progress",J),p(tt.media,"playing",J),p(tt.media,"volumechange",U),p(tt.media,"play pause",R),p(tt.media,"waiting canplay seeked",X),p(tt.checkboxes,"keyup",m),"video"===tt.type&&x.click&&p(tt.videoContainer,"click",function(){tt.media.paused?L():tt.media.ended?(H(),L()):O()}),x.fullscreen.hideControls&&p(tt.controls,"mouseenter mouseleave",function(e){c(tt.controls,x.classes.hover,"mouseenter"===e.type)})}function et(){if(k=g(),tt.browser=n(),tt.media=tt.container.querySelectorAll("audio, video")[0],tt.type=tt.media.tagName.toLowerCase(),tt.supported=e.supported(tt.type),!tt.supported.basic)return!1;if(t(tt.browser.name+" "+tt.browser.version),P(),tt.random=Math.floor(1e4*Math.random()),tt.supported.full){if(E(),!N())return!1;A(),I(),W(),M(),Z()}return!0}var tt=this;return tt.container=u,et()?{media:tt.media,play:L,pause:O,restart:H,rewind:q,forward:V,seek:H,setVolume:W,toggleMute:_,toggleCaptions:D,source:G,poster:Q,support:function(e){return r(tt,e)}}:{}}var k,x,w={enabled:!0,debug:!1,seekTime:10,volume:5,click:!0,tooltips:!1,selectors:{container:".player",controls:".player-controls",labels:"[data-player] .sr-only, label .sr-only",buttons:{seek:"[data-player='seek']",play:"[data-player='play']",pause:"[data-player='pause']",restart:"[data-player='restart']",rewind:"[data-player='rewind']",forward:"[data-player='fast-forward']",mute:"[data-player='mute']",volume:"[data-player='volume']",captions:"[data-player='captions']",fullscreen:"[data-player='fullscreen']"},progress:{container:".player-progress",buffer:".player-progress-buffer",played:".player-progress-played"},captions:".player-captions",duration:".player-duration"},classes:{video:"player-video",videoWrapper:"player-video-wrapper",audio:"player-audio",stopped:"stopped",playing:"playing",muted:"muted",loading:"loading",tooltip:"player-tooltip",hidden:"sr-only",hover:"hover",captions:{enabled:"captions-enabled",active:"captions-active"},fullscreen:{enabled:"fullscreen-enabled",active:"fullscreen-active",hideControls:"fullscreen-hide-controls"}},captions:{defaultActive:!1},fullscreen:{enabled:!0,fallback:!0,hideControls:!0},storage:{enabled:!0,key:"plyr_volume"},html:function(){return["
","
","","","","0% played","","","0% buffered","","
","","","","","","","","Time","00:00","","","","","","","","","","","","
"].join("\n")}()};e.supported=function(e){var t,r,s=n(),a="IE"===s.name&&s.version<=9,o=/iPhone|iPod/i.test(navigator.userAgent),i=!!document.createElement("audio").canPlayType,l=!!document.createElement("video").canPlayType;switch(e){case"video":t=l,r=t&&!a&&!o;break;case"audio":t=i,r=t&&!a;break;default:t=i&&l,r=t&&!a}return{basic:t,full:r}},e.setup=function(t){if(x=y(w,t),!x.enabled||!e.supported().basic)return!1;for(var n=document.querySelectorAll(x.selectors.container),r=[],s=n.length-1;s>=0;s--){var a=n[s];if("undefined"==typeof a.plyr){var o=new h(a);a.plyr=Object.keys(o).length?o:!1}r.push(a.plyr)}return r}}(this.plyr=this.plyr||{}); \ No newline at end of file +!function(e){"use strict";function t(e,t){x.debug&&window.console&&console[t?"error":"log"](e)}function n(){var e,t,n,r=navigator.userAgent,s=navigator.appName,a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10);return-1!==navigator.appVersion.indexOf("Windows NT")&&-1!==navigator.appVersion.indexOf("rv:11")?(s="IE",a="11;"):-1!==(t=r.indexOf("MSIE"))?(s="IE",a=r.substring(t+5)):-1!==(t=r.indexOf("Chrome"))?(s="Chrome",a=r.substring(t+7)):-1!==(t=r.indexOf("Safari"))?(s="Safari",a=r.substring(t+7),-1!==(t=r.indexOf("Version"))&&(a=r.substring(t+8))):-1!==(t=r.indexOf("Firefox"))?(s="Firefox",a=r.substring(t+8)):(e=r.lastIndexOf(" ")+1)<(t=r.lastIndexOf("/"))&&(s=r.substring(e,t),a=r.substring(t+1),s.toLowerCase()==s.toUpperCase()&&(s=navigator.appName)),-1!==(n=a.indexOf(";"))&&(a=a.substring(0,n)),-1!==(n=a.indexOf(" "))&&(a=a.substring(0,n)),o=parseInt(""+a,10),isNaN(o)&&(a=""+parseFloat(navigator.appVersion),o=parseInt(navigator.appVersion,10)),{name:s,version:o,ios:/(iPad|iPhone|iPod)/g.test(navigator.platform)}}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,t,n){return e.replace(new RegExp(t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),n)}function a(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],a=s.parentNode,o=s.nextSibling;r.appendChild(s),o?a.insertBefore(r,o):a.appendChild(r)}}function o(e){e.parentNode.removeChild(e)}function i(e,t){e.insertBefore(t,e.firstChild)}function l(e,t){for(var n in t)e.setAttribute(n,t[n])}function c(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 u(e,t,n,r){if(t=t.split(" "),e instanceof NodeList)for(var s=0;sn;n++){if(e.prefix=t[n],"undefined"!=typeof document[e.prefix+"CancelFullScreen"]){e.supportsFullScreen=!0;break}if("undefined"!=typeof document.msExitFullscreen&&document.msFullscreenEnabled){e.prefix="ms",e.supportsFullScreen=!0;break}}return"webkit"===e.prefix&&navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)&&(e.supportsFullScreen=!1),e.supportsFullScreen&&(e.fullScreenEventName="ms"==e.prefix?"MSFullscreenChange":e.prefix+"fullscreenchange",e.isFullScreen=function(){switch(this.prefix){case"":return document.fullScreen;case"webkit":return document.webkitIsFullScreen;case"ms":return null!==document.msFullscreenElement;default:return document[this.prefix+"FullScreen"]}},e.requestFullScreen=function(e){return""===this.prefix?e.requestFullScreen():e[this.prefix+("ms"==this.prefix?"RequestFullscreen":"RequestFullScreen")]("webkit"===this.prefix?e.ALLOW_KEYBOARD_INPUT:null)},e.cancelFullScreen=function(){return""===this.prefix?document.cancelFullScreen():document[this.prefix+("ms"==this.prefix?"ExitFullscreen":"CancelFullScreen")]()},e.element=function(){return""===this.prefix?document.fullscreenElement:document[this.prefix+"FullscreenElement"]}),e}function b(){var e={supported:function(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}()};return e}function h(u){function f(e){if(!nt.usingTextTracks&&"video"===nt.type&&nt.supported.full){for(nt.subcount=0,e="number"==typeof e?e:nt.media.currentTime;w(nt.captions[nt.subcount][0])nt.captions.length-1){nt.subcount=nt.captions.length-1;break}nt.media.currentTime.toFixed(1)>=h(nt.captions[nt.subcount][0])&&nt.media.currentTime.toFixed(1)<=w(nt.captions[nt.subcount][0])?(nt.currentCaption=nt.captions[nt.subcount][1],nt.captionsContainer.innerHTML=nt.currentCaption):nt.captionsContainer.innerHTML=""}}function v(){c(nt.container,x.classes.captions.enabled,!0),x.captions.defaultActive&&(c(nt.container,x.classes.captions.active,!0),nt.buttons.captions.checked=!0)}function h(e){var t=[];return t=e.split(" --> "),T(t[0])}function w(e){var t=[];return t=e.split(" --> "),T(t[1])}function T(e){if(null===e||void 0===e)return 0;var t,n=[],r=[];return n=e.split(","),r=n[0].split(":"),t=Math.floor(60*r[0]*60)+Math.floor(60*r[1])+Math.floor(r[2])}function S(e){return nt.container.querySelectorAll(e)}function F(e){return S(e)[0]}function C(){try{return window.self!==window.top}catch(e){return!0}}function E(){t("Injecting custom controls.");var e=x.html;if(e=s(e,"{seektime}",x.seekTime),e=s(e,"{id}",nt.random),nt.container.insertAdjacentHTML("beforeend",e),x.tooltips)for(var n=S(x.selectors.labels),r=n.length-1;r>=0;r--){var a=n[r];c(a,x.classes.hidden,!1),c(a,x.classes.tooltip,!0)}}function A(){try{return nt.controls=F(x.selectors.controls),nt.buttons={},nt.buttons.seek=F(x.selectors.buttons.seek),nt.buttons.play=F(x.selectors.buttons.play),nt.buttons.pause=F(x.selectors.buttons.pause),nt.buttons.restart=F(x.selectors.buttons.restart),nt.buttons.rewind=F(x.selectors.buttons.rewind),nt.buttons.forward=F(x.selectors.buttons.forward),nt.buttons.fullscreen=F(x.selectors.buttons.fullscreen),nt.buttons.mute=F(x.selectors.buttons.mute),nt.buttons.captions=F(x.selectors.buttons.captions),nt.checkboxes=S("[type='checkbox']"),nt.progress={},nt.progress.container=F(x.selectors.progress.container),nt.progress.buffer={},nt.progress.buffer.bar=F(x.selectors.progress.buffer),nt.progress.buffer.text=nt.progress.buffer.bar.getElementsByTagName("span")[0],nt.progress.played={},nt.progress.played.bar=F(x.selectors.progress.played),nt.progress.played.text=nt.progress.played.bar.getElementsByTagName("span")[0],nt.volume=F(x.selectors.buttons.volume),nt.duration=F(x.selectors.duration),nt.seekTime=S(x.selectors.seekTime),!0}catch(e){return t("It looks like there's a problem with your controls html. Bailing.",!0),!1}}function N(){var e=nt.buttons.play.innerText||"Play";"undefined"!=typeof x.title&&x.title.length&&(e+=", "+x.title),nt.buttons.play.setAttribute("aria-label",e)}function P(){if(!nt.media)return t("No audio or video element found!",!0),!1;if(nt.supported.full&&(nt.media.removeAttribute("controls"),c(nt.container,x.classes[nt.type],!0),c(nt.container,x.classes.stopped,null===nt.media.getAttribute("autoplay")),nt.browser.ios&&c(nt.container,"ios",!0),"video"===nt.type)){var e=document.createElement("div");e.setAttribute("class",x.classes.videoWrapper),a(nt.media,e),nt.videoContainer=e}null!==nt.media.getAttribute("autoplay")&&L()}function I(){if("video"===nt.type){nt.videoContainer.insertAdjacentHTML("afterbegin","
"),nt.captionsContainer=F(x.selectors.captions),nt.usingTextTracks=!1,nt.media.textTracks&&(nt.usingTextTracks=!0);for(var e,n="",r=nt.media.childNodes,s=0;s=31||"Safari"===nt.browser.name&&nt.browser.version>=7)&&(t("Detected IE 10/11 or Firefox 31+ or Safari 7+."),nt.usingTextTracks=!1),nt.usingTextTracks){t("TextTracks supported.");for(var i=0;i=7){t("Safari 7+ detected; removing track from DOM."),a=nt.media.getElementsByTagName("track");for(var d=0;dn?n=0:n>nt.media.duration&&(n=nt.media.duration);try{nt.media.currentTime=n.toFixed(1)}catch(r){}t("Seeking to "+nt.media.currentTime+" seconds"),f(n)}function R(){c(nt.container,x.classes.playing,!nt.media.paused),c(nt.container,x.classes.stopped,nt.media.paused)}function j(e){var t=k.supportsFullScreen;e&&e.type===k.fullScreenEventName?x.fullscreen.active=k.isFullScreen():t?(k.isFullScreen()?k.cancelFullScreen():k.requestFullScreen(nt.container),x.fullscreen.active=k.isFullScreen()):(x.fullscreen.active=!x.fullscreen.active,x.fullscreen.active?(p(document,"keyup",B),document.body.style.overflow="hidden"):(d(document,"keyup",B),document.body.style.overflow="")),c(nt.container,x.classes.fullscreen.active,x.fullscreen.active)}function B(e){27===(e.which||e.charCode||e.keyCode)&&x.fullscreen.active&&j()}function D(e){"undefined"==typeof e&&(e=x.storage.enabled&&b().supported?window.localStorage[x.storage.key]||x.volume:x.volume),e>10&&(e=10),nt.supported.full&&(nt.volume.value=e),nt.media.volume=parseFloat(e/10),U(),x.storage.enabled&&b().supported&&(window.localStorage.plyr_volume=e)}function W(e){"undefined"==typeof e&&(e=!nt.media.muted),nt.supported.full&&(nt.buttons.mute.checked=e),nt.media.muted=e,U()}function _(e){nt.supported.full&&("undefined"==typeof e&&(e=-1===nt.container.className.indexOf(x.classes.captions.active),nt.buttons.captions.checked=e),c(nt.container,x.classes.captions.active,e))}function U(){c(nt.container,x.classes.muted,0===nt.media.volume||nt.media.muted)}function X(e){var t="waiting"===e.type;clearTimeout(nt.loadingTimer),nt.loadingTimer=setTimeout(function(){c(nt.container,x.classes.loading,t)},t?250:0)}function J(e){var t=nt.progress.played.bar,n=nt.progress.played.text,r=0;if(e)switch(e.type){case"timeupdate":case"seeking":r=y(nt.media.currentTime,nt.media.duration),"timeupdate"==e.type&&(nt.buttons.seek.value=r);break;case"change":case"input":r=e.target.value;break;case"playing":case"progress":t=nt.progress.buffer.bar,n=nt.progress.buffer.text,r=function(){var e=nt.media.buffered;return e.length?y(e.end(0),nt.media.duration):0}()}t.value=r,n.innerHTML=r}function $(e){nt.secs=parseInt(e%60),nt.mins=parseInt(e/60%60),nt.hours=parseInt(e/60/60%60);var t=parseInt(nt.media.duration/60/60%60)>0;nt.secs=("0"+nt.secs).slice(-2),nt.mins=("0"+nt.mins).slice(-2),nt.duration.innerHTML=(t?nt.hours+":":"")+nt.mins+":"+nt.secs}function z(){nt.media.paused&&$(nt.media.duration||0)}function K(e){$(nt.media.currentTime),J(e)}function Y(){for(var e=nt.media.querySelectorAll("source"),t=e.length-1;t>=0;t--)o(e[t]);nt.media.removeAttribute("src")}function G(e){if(e.src){var t=document.createElement("source");l(t,e),i(nt.media,t)}}function Q(e){if(O(),V(),Y(),"string"==typeof e)nt.media.setAttribute("src",e);else if(e.constructor===Array)for(var t in e)G(e[t]);nt.supported.full&&(K(),R()),nt.media.load(),null!==nt.media.getAttribute("autoplay")&&L()}function Z(e){"video"===nt.type&&nt.media.setAttribute("poster",e)}function et(){p(nt.buttons.play,"click",function(){L(),setTimeout(function(){nt.buttons.pause.focus()},100)}),p(nt.buttons.pause,"click",function(){O(),setTimeout(function(){nt.buttons.play.focus()},100)}),p(nt.buttons.restart,"click",V),p(nt.buttons.rewind,"click",q),p(nt.buttons.forward,"click",H),p(nt.volume,"change input",function(){D(this.value)}),p(nt.buttons.mute,"change",function(){W(this.checked)}),p(nt.buttons.fullscreen,"click",j),k.supportsFullScreen&&p(document,k.fullScreenEventName,j),p(nt.media,"timeupdate seeking",K),p(nt.media,"timeupdate",f),x.displayDuration&&p(nt.media,"loadedmetadata",z),p(nt.buttons.seek,"change input",V),p(nt.buttons.captions,"change",function(){_(this.checked)}),p(nt.media,"ended",function(){"video"===nt.type&&(nt.captionsContainer.innerHTML=""),R()}),p(nt.media,"progress",J),p(nt.media,"playing",J),p(nt.media,"volumechange",U),p(nt.media,"play pause",R),p(nt.media,"waiting canplay seeked",X),p(nt.checkboxes,"keyup",m),"video"===nt.type&&x.click&&p(nt.videoContainer,"click",function(){nt.media.paused?L():nt.media.ended?(V(),L()):O()}),x.fullscreen.hideControls&&p(nt.controls,"mouseenter mouseleave",function(e){c(nt.controls,x.classes.hover,"mouseenter"===e.type)})}function tt(){if(k=g(),nt.browser=n(),nt.media=nt.container.querySelectorAll("audio, video")[0],nt.type=nt.media.tagName.toLowerCase(),nt.supported=e.supported(nt.type),!nt.supported.basic)return!1;if(t(nt.browser.name+" "+nt.browser.version),P(),nt.random=Math.floor(1e4*Math.random()),nt.supported.full){if(E(),!A())return!1;x.displayDuration&&z(),N(),I(),D(),M(),et()}return!0}var nt=this;return nt.container=u,tt()?{media:nt.media,play:L,pause:O,restart:V,rewind:q,forward:H,seek:V,setVolume:D,toggleMute:W,toggleCaptions:_,source:Q,poster:Z,support:function(e){return r(nt,e)}}:{}}var k,x,w={enabled:!0,debug:!1,seekTime:10,volume:5,click:!0,tooltips:!1,displayDuration:!0,selectors:{container:".player",controls:".player-controls",labels:"[data-player] .sr-only, label .sr-only",buttons:{seek:"[data-player='seek']",play:"[data-player='play']",pause:"[data-player='pause']",restart:"[data-player='restart']",rewind:"[data-player='rewind']",forward:"[data-player='fast-forward']",mute:"[data-player='mute']",volume:"[data-player='volume']",captions:"[data-player='captions']",fullscreen:"[data-player='fullscreen']"},progress:{container:".player-progress",buffer:".player-progress-buffer",played:".player-progress-played"},captions:".player-captions",duration:".player-duration"},classes:{video:"player-video",videoWrapper:"player-video-wrapper",audio:"player-audio",stopped:"stopped",playing:"playing",muted:"muted",loading:"loading",tooltip:"player-tooltip",hidden:"sr-only",hover:"hover",captions:{enabled:"captions-enabled",active:"captions-active"},fullscreen:{enabled:"fullscreen-enabled",active:"fullscreen-active",hideControls:"fullscreen-hide-controls"}},captions:{defaultActive:!1},fullscreen:{enabled:!0,fallback:!0,hideControls:!0},storage:{enabled:!0,key:"plyr_volume"},html:function(){return["
","
","","","","0% played","","","0% buffered","","
","","","","","","","","Time","00:00","","","","","","","","","","","","
"].join("\n")}()};e.supported=function(e){var t,r,s=n(),a="IE"===s.name&&s.version<=9,o=/iPhone|iPod/i.test(navigator.userAgent),i=!!document.createElement("audio").canPlayType,l=!!document.createElement("video").canPlayType;switch(e){case"video":t=l,r=t&&!a&&!o;break;case"audio":t=i,r=t&&!a;break;default:t=i&&l,r=t&&!a}return{basic:t,full:r}},e.setup=function(t){if(x=v(w,t),!x.enabled||!e.supported().basic)return!1;for(var n=document.querySelectorAll(x.selectors.container),r=[],s=n.length-1;s>=0;s--){var a=n[s];if("undefined"==typeof a.plyr){var o=new h(a);a.plyr=Object.keys(o).length?o:!1}r.push(a.plyr)}return r}}(this.plyr=this.plyr||{}); \ No newline at end of file diff --git a/docs/error.html b/docs/error.html index e6631fe7..2185baf5 100644 --- a/docs/error.html +++ b/docs/error.html @@ -6,7 +6,7 @@ - +
diff --git a/docs/index.html b/docs/index.html index 4efb3899..2dcef23d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -8,10 +8,10 @@ - + - +
@@ -83,13 +83,13 @@ b.insertBefore(c, b.childNodes[0]); } } - })(document, "https://cdn.plyr.io/1.0.30/sprite.svg"); + })(document, "https://cdn.plyr.io/1.0.31/sprite.svg"); - + - + \ No newline at end of file diff --git a/package.json b/package.json index e6879167..b7cbeb53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plyr", - "version": "1.0.30", + "version": "1.0.31", "description": "A simple HTML5 media player using custom controls", "homepage": "http://plyr.io", "main": "gulpfile.js", diff --git a/readme.md b/readme.md index 5d6f5349..708dbe60 100644 --- a/readme.md +++ b/readme.md @@ -38,7 +38,7 @@ If you have any cool ideas or features, please let me know by [creating an issue Check `docs/index.html` and `docs/dist/docs.js` for an example setup. -**Heads up**, the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.0.30/plyr.js` to `https://cdn.plyr.io/1.0.30/plyr.js` +**Heads up**, the example `index.html` file needs to be served from a webserver (such as Apache, Nginx, IIS or similar) unless you change the file sources to include http or https. e.g. change `//cdn.plyr.io/1.0.31/plyr.js` to `https://cdn.plyr.io/1.0.31/plyr.js` ### Bower If bower is your thang, you can grab Plyr using: @@ -51,11 +51,11 @@ More info on setting up dependencies can be found in the [Bower Docs](http://bow If you want to use our CDN, you can use the following. HTTPS (SSL) is supported. ```html - - + + ``` -You can also access the `sprite.svg` file at `//cdn.plyr.io/1.0.30/sprite.svg`. +You can also access the `sprite.svg` file at `//cdn.plyr.io/1.0.31/sprite.svg`. ### CSS If you want to use the default css, add the `plyr.css` file from /dist into your head, or even better use `plyr.less` or `plyr.sass` file included in `/src` in your build to save a request. @@ -197,6 +197,12 @@ You can pass the following options to the setup method. Boolean false Display control labels as tooltips on :hover & :focus (by default, the labels are screen reader only). + + + displayDuration + Boolean + true + Displays the duration of the media on the "metadataloaded" event. This will only work if the `preload` attribute is not set to `none`. It is `auto` by default (if the attribute is not present). selectors diff --git a/src/js/plyr.js b/src/js/plyr.js index 9128ad99..c2b78d6b 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -1,6 +1,6 @@ // ========================================================================== // Plyr -// plyr.js v1.0.29 +// plyr.js v1.0.31 // https://github.com/selz/plyr // License: The MIT License (MIT) // ========================================================================== @@ -21,6 +21,7 @@ volume: 5, click: true, tooltips: false, + displayDuration: true, selectors: { container: ".player", controls: ".player-controls", @@ -687,7 +688,6 @@ return false; } - if(player.supported.full) { // Remove native video controls player.media.removeAttribute("controls"); @@ -800,10 +800,12 @@ if (track.kind === "captions") { _on(track, "cuechange", function() { - if (this.activeCues[0]) { - if (this.activeCues[0].hasOwnProperty("text")) { - player.captionsContainer.innerHTML = this.activeCues[0].text; - } + // Clear container + player.captionsContainer.innerHTML = ""; + + // Display a cue, if there is one + if (this.activeCues[0] && this.activeCues[0].hasOwnProperty("text")) { + player.captionsContainer.appendChild(this.activeCues[0].getCueAsHTML()); } }); } @@ -1149,24 +1151,34 @@ text.innerHTML = value; } - // Update the displayed play time - function _updateTimeDisplay() { - player.secs = parseInt(player.media.currentTime % 60); - player.mins = parseInt((player.media.currentTime / 60) % 60); - player.hours = parseInt(((player.media.currentTime / 60) / 60) % 60); + // Update the displayed time + function _updateTimeDisplay(time) { + player.secs = parseInt(time % 60); + player.mins = parseInt((time / 60) % 60); + player.hours = parseInt(((time / 60) / 60) % 60); + + // Do we need to display hours? + var displayHours = (parseInt(((player.media.duration / 60) / 60) % 60) > 0) // Ensure it"s two digits. For example, 03 rather than 3. player.secs = ("0" + player.secs).slice(-2); player.mins = ("0" + player.mins).slice(-2); // Render - player.duration.innerHTML = (player.hours > 0 ? player.hours + ":" : "") + player.mins + ":" + player.secs; + player.duration.innerHTML = (displayHours ? player.hours + ":" : "") + player.mins + ":" + player.secs; + } + + // Show the duration on metadataloaded + function _displayDuration() { + if(player.media.paused) { + _updateTimeDisplay(player.media.duration || 0); + } } // Handle time change event function _timeUpdate(event) { // Duration - _updateTimeDisplay(); + _updateTimeDisplay(player.media.currentTime); // Playing progress _updateProgress(event); @@ -1299,6 +1311,11 @@ // Update manual captions _on(player.media, "timeupdate", _seekManualCaptions); + // Display duration + if(config.displayDuration) { + _on(player.media, "loadedmetadata", _displayDuration); + } + // Seek _on(player.buttons.seek, "change input", _seek); @@ -1400,6 +1417,11 @@ return false; } + // Display duration if available + if(config.displayDuration) { + _displayDuration(); + } + // Set up aria-label for Play button with the title option _setupAria();