Compare commits

...

33 Commits

Author SHA1 Message Date
eee699cec6 Version bump 2016-07-10 20:59:42 +10:00
3c9e9862d8 Added getCurrentTime API method (fixes #292) 2016-07-10 20:58:19 +10:00
39dc651a9d Fix for !hideControls on touch devices (fixes #303) 2016-07-10 20:50:55 +10:00
4effda125a Merge branch 'master' of https://github.com/Selz/plyr 2016-07-10 20:45:58 +10:00
bf9de231d8 Styling minor tweaks 2016-07-10 20:45:54 +10:00
ef12332505 Update readme.md 2016-06-29 16:23:38 +10:00
1b735f1727 Update readme.md 2016-06-26 22:21:19 +10:00
7f7ecf852e Line height fix 2016-06-26 09:07:42 +10:00
931672895f Reverted font size change 2016-06-26 09:04:38 +10:00
0952bc8239 Built JS 2016-06-26 08:45:06 +10:00
7e7508ca82 Fixed overflow issues (fixes #286) 2016-06-26 08:34:36 +10:00
095d100ba4 Version bump 2016-06-25 23:47:30 +10:00
c61fad51c1 Fix for z-index on large play button 2016-06-25 23:46:37 +10:00
7b11c6803d Merge pull request #283 from arrowthemes/patch-1
Make the player button clickable on small videos
2016-06-25 17:44:07 +04:00
9b75436380 v1.8.3
- Disabled iPad support for YouTube and Vimeo due to iOS limitations with iFrame playback
- Fixed IE11 icon loading (fixes #269)
- Updated screenshot (fixes #281)
- Added WordPress plugin (fixes #239)
- Added Neos plugin
- Added HLS, Shaka and dash.js examples (see #235 for more)
- Improvements for controls hiding and showing on touch devices
2016-06-25 23:39:00 +10:00
be19b72719 Merge branch 'master' of https://github.com/Selz/plyr
# Conflicts:
#	dist/plyr.css
#	src/less/plyr.less
#	src/scss/plyr.scss
2016-06-25 22:35:04 +10:00
2fdcc18356 Hide Shadow DOM elements 2016-06-25 22:33:23 +10:00
cb591dac0c Make the player button clickable on small videos
If you set the plyr video to width of 300px, the plyr__controls overlays the play centered play button such that you can't click on the play button. Adding a z-index on the plyr .plyr__play-large fixes that.
2016-06-21 21:59:00 +03:00
4c1cdea56e Merge pull request #275 from wilsonmsalberto/master
Prevent error when verifying if play buttons exist
2016-06-13 18:49:20 +01:00
80cfabbaf9 Prevent error when verifying if play buttons exist 2016-06-13 17:01:46 +01:00
Sam
c7d28b09c0 Fixed event bubbling 2016-06-09 11:05:07 +01:00
Sam
161dd48312 Fixed log message 2016-06-09 09:57:16 +01:00
Sam
383515c1b7 Merge branch 'master' of https://github.com/Selz/plyr 2016-06-09 09:49:09 +01:00
Sam
98792168e4 Changes to setup return value, SVG bug fix (fixes #269) 2016-06-09 09:49:01 +01:00
01437a4a38 Merge pull request #271 from thegrammarnazi/patch-3
correct grammar
2016-06-09 09:46:49 +01:00
03ed86f5c2 correct grammar 2016-06-09 01:39:52 -05:00
Sam
1a745e1eaa Merge branch 'master' of https://github.com/Selz/plyr 2016-06-07 12:34:40 +01:00
Sam
70646ca907 See changelog (fixes #265, #253, #257) 2016-06-07 12:34:36 +01:00
af774b6f02 Merge pull request #260 from cytec/fix-control-icon-size
use $plyr-control-icon-size in sass file
2016-06-02 10:41:36 +01:00
7a9eac093a use $plyr-control-icon-size in sass file 2016-06-02 11:40:09 +02:00
Sam
4afd311ef6 Version bump 2016-06-02 10:19:35 +01:00
Sam
7eec6c6739 Fix for multiple sprites being requested (fixes #259) 2016-06-02 10:18:33 +01:00
Sam
521431e093 Fix for scroll direction on volume (fixes #258) 2016-06-01 09:38:29 +01:00
38 changed files with 802 additions and 624 deletions

View File

@ -10,14 +10,14 @@
"plyr.js": ["src/js/plyr.js"] "plyr.js": ["src/js/plyr.js"]
} }
}, },
"docs": { "demo": {
"less": { "less": {
"docs.css": ["docs/src/less/docs.less"] "demo.css": ["demo/src/less/demo.less"]
}, },
"js": { "js": {
"docs.js": [ "demo.js": [
"docs/src/js/lib/classlist.js", "demo/src/js/lib/classlist.js",
"docs/src/js/docs.js" "demo/src/js/main.js"
] ]
} }
} }

View File

@ -1,12 +1,60 @@
# Changelog # Changelog
# v1.6.18 ## v1.8.8
- Added getCurrentTime API method (fixes #292)
- Fix for !hideControls on touch devices (fixes #303)
## v1.8.7
- Line height fix
## v1.8.6
- Reverted font size change
## v1.8.5
- Fixed overflow issues (fixes #286)
## v1.8.4
- Fix for large play button on small videos
## v1.8.3
- Disabled iPad support for YouTube and Vimeo due to iOS limitations with iFrame playback
- Fixed IE11 icon loading (fixes #269)
- Updated screenshot (fixes #281)
- Added WordPress plugin (fixes #239)
- Added Neos plugin
- Added HLS, Shaka and dash.js examples (see #235 for more)
- Improvements for controls hiding and showing on touch devices
## v1.8.2
- Fixed event bubbling
## v1.8.1
- Fixed inaccurate log message
# v1.8.0
- ***(Important)*** `setup()` now returns the element Plyr was setup on rather than the `plyr` object. This means `var player = plyr.setup()[0];` would now be `var player = plyr.setup()[0].plyr;`. This improves support for React and other virtual dom frameworks as mentioned in #254
- Fixed using a relative URL for `iconUrl` in IE (fixes #269)
# v1.7.0
- SASS cleanup (fixes #265)
- Docs tidy up to help quick start (fixes #253)
- Fix for issues with data attribute options passing (fixes #257)
- ***(Important)*** Removed the requirement for a wrapper div to setup Plyr and removed the dependency on the `plyr` classname as a JS hook. By default it will now look for `<video>`, `<audio>` and `[data-type]` elements. If you are just calling `setup()` with a `<div class="plyr">` you may want to give it a good test after upgrading. You can probably remove the wrapper div. The reason behind this is to make setup easier for newcomers and prevent the styling being used on unsupported players (because the plyr classname was used as a CSS and JS hook - which isn't ideal)
- Renamed the 'docs' folder to `demo` to avoid confusion - the readme is the docs after all
## v1.6.20
- Fix for multiple sprites being requested (fixes #259)
## v1.6.19
- Fix for scroll direction issues on volume control (fixes #258)
## v1.6.18
- Reduced rounding of seek value from 1 decimal point to 4 (fixes #242) - Reduced rounding of seek value from 1 decimal point to 4 (fixes #242)
# v1.6.17 ## v1.6.17
- Added `disableContextMenu` option to hide the right click context menu (fixes #248 and #225) - Added `disableContextMenu` option to hide the right click context menu (fixes #248 and #225)
# v1.6.16 ## v1.6.16
- Always hide standard controls (fixes #225) - Always hide standard controls (fixes #225)
- Fix for Tooltips overflowing (fixes #230) - Fix for Tooltips overflowing (fixes #230)

1
demo/dist/demo.css vendored Normal file

File diff suppressed because one or more lines are too long

1
demo/dist/demo.js vendored Normal file
View File

@ -0,0 +1 @@
"document"in self&&("classList"in document.createElement("_")?!function(){"use strict";var e=document.createElement("_");if(e.classList.add("c1","c2"),!e.classList.contains("c2")){var t=function(e){var t=DOMTokenList.prototype[e];DOMTokenList.prototype[e]=function(e){var i,o=arguments.length;for(i=0;o>i;i++)e=arguments[i],t.call(this,e)}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var i=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:i.call(this,e)}}e=null}():!function(e){"use strict";if("Element"in e){var t="classList",i="prototype",o=e.Element[i],n=Object,s=String[i].trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array[i].indexOf||function(e){for(var t=0,i=this.length;i>t;t++)if(t in this&&this[t]===e)return t;return-1},a=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},c=function(e,t){if(""===t)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(t))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(e,t)},l=function(e){for(var t=s.call(e.getAttribute("class")||""),i=t?t.split(/\s+/):[],o=0,n=i.length;n>o;o++)this.push(i[o]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},u=l[i]=[],d=function(){return new l(this)};if(a[i]=Error[i],u.item=function(e){return this[e]||null},u.contains=function(e){return e+="",-1!==c(this,e)},u.add=function(){var e,t=arguments,i=0,o=t.length,n=!1;do e=t[i]+"",-1===c(this,e)&&(this.push(e),n=!0);while(++i<o);n&&this._updateClassName()},u.remove=function(){var e,t,i=arguments,o=0,n=i.length,s=!1;do for(e=i[o]+"",t=c(this,e);-1!==t;)this.splice(t,1),s=!0,t=c(this,e);while(++o<n);s&&this._updateClassName()},u.toggle=function(e,t){e+="";var i=this.contains(e),o=i?t!==!0&&"remove":t!==!1&&"add";return o&&this[o](e),t===!0||t===!1?t:!i},u.toString=function(){return this.join(" ")},n.defineProperty){var p={get:d,enumerable:!0,configurable:!0};try{n.defineProperty(o,t,p)}catch(h){-2146823252===h.number&&(p.enumerable=!1,n.defineProperty(o,t,p))}}else n[i].__defineGetter__&&o.__defineGetter__(t,d)}}(self)),function(){function e(e,t,i){if(e)if(e.classList)e.classList[i?"add":"remove"](t);else{var o=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=o+(i?" "+t:"")}}function t(t,i){if(t in s&&(i||t!=r)&&(r.length||t!=s.video)){switch(t){case s.video:o.source({type:"video",title:"View From A Blue Moon",sources:[{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4",type:"video/mp4"},{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm",type:"video/webm"}],poster:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg",tracks:[{kind:"captions",label:"English",srclang:"en",src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt","default":!0}]});break;case s.audio:o.source({type:"audio",title:"Kishi Bashi &ndash; &ldquo;It All Began With A Burst&rdquo;",sources:[{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3",type:"audio/mp3"},{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg",type:"audio/ogg"}]});break;case s.youtube:o.source({type:"video",title:"View From A Blue Moon",sources:[{src:"bTqVqk7FSmY",type:"youtube"}]});break;case s.vimeo:o.source({type:"video",title:"View From A Blue Moon",sources:[{src:"143418951",type:"vimeo"}]})}r=t;for(var a=n.length-1;a>=0;a--)e(n[a].parentElement,"active",!1);e(document.querySelector('[data-source="'+t+'"]').parentElement,"active",!0)}}document.body.addEventListener("ready",function(e){console.log(e)});var i=plyr.setup({debug:!0,title:"Video demo",iconUrl:"../dist/plyr.svg",tooltips:{controls:!0},captions:{defaultActive:!0}});plyr.loadSprite("dist/demo.svg");for(var o=i[0].plyr,n=document.querySelectorAll("[data-source]"),s={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},r=window.location.hash.replace("#",""),a=window.history&&window.history.pushState,c=n.length-1;c>=0;c--)n[c].addEventListener("click",function(){var e=this.getAttribute("data-source");t(e),a&&history.pushState({type:e},"","#"+e)});if(window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&t(e.state.type)}),a){var l=!r.length;l&&(r=s.video),r in s&&history.replaceState({type:r},"",l?"":"#"+r),r!==s.video&&t(r,!0)}}(),document.domain.indexOf("plyr.io")>-1&&(!function(e,t,i,o,n,s,r){e.GoogleAnalyticsObject=n,e[n]=e[n]||function(){(e[n].q=e[n].q||[]).push(arguments)},e[n].l=1*new Date,s=t.createElement(i),r=t.getElementsByTagName(i)[0],s.async=1,s.src=o,r.parentNode.insertBefore(s,r)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-40881672-11","auto"),ga("send","pageview"));

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -11,7 +11,7 @@
<link rel="stylesheet" href="../dist/plyr.css"> <link rel="stylesheet" href="../dist/plyr.css">
<!-- Docs styles --> <!-- Docs styles -->
<link rel="stylesheet" href="dist/docs.css"> <link rel="stylesheet" href="dist/demo.css">
</head> </head>
<body> <body>
<header> <header>
@ -51,19 +51,17 @@
</ul> </ul>
</nav> </nav>
<section> <section>
<div class="js-media-player"> <video poster="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg" controls crossorigin>
<video poster="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg" controls crossorigin> <!-- Video files -->
<!-- Video files --> <source src="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4" type="video/mp4">
<source src="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4" type="video/mp4"> <source src="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm" type="video/webm">
<source src="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm" type="video/webm">
<!-- Text track file --> <!-- Text track file -->
<track kind="captions" label="English" srclang="en" src="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt" default> <track kind="captions" label="English" srclang="en" src="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt" default>
<!-- Fallback for browsers that don't support the <video> element --> <!-- Fallback for browsers that don't support the <video> element -->
<a href="https://cdn.selz.com/plyr/1.0/movie.mp4">Download</a> <a href="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4" download>Download</a>
</video> </video>
</div>
<ul> <ul>
<li class="plyr__cite plyr__cite--video"><small><a href="http://viewfromabluemoon.com/" target="_blank">View From A Blue Moon</a> &copy; Brainfarm</small></li> <li class="plyr__cite plyr__cite--video"><small><a href="http://viewfromabluemoon.com/" target="_blank">View From A Blue Moon</a> &copy; Brainfarm</small></li>
@ -78,10 +76,10 @@
<script src="../dist/plyr.js"></script> <script src="../dist/plyr.js"></script>
<!-- Docs script --> <!-- Docs script -->
<script src="dist/docs.js"></script> <script src="dist/demo.js"></script>
<!-- Rangetouch to fix <input type="range"> on touch devices (see https://rangetouch.com) --> <!-- Rangetouch to fix <input type="range"> on touch devices (see https://rangetouch.com) -->
<script src="https://cdn.rangetouch.com/0.0.9/rangetouch.js"></script> <script src="https://cdn.rangetouch.com/0.0.9/rangetouch.js" async></script>
<!-- Sharing libary (https://shr.one) --> <!-- Sharing libary (https://shr.one) -->
<script src="https://cdn.shr.one/0.1.9/shr.js"></script> <script src="https://cdn.shr.one/0.1.9/shr.js"></script>

185
demo/src/js/main.js Normal file
View File

@ -0,0 +1,185 @@
// ==========================================================================
// Plyr.io demo
// This code is purely for the plyr.io website
// Please see readme.md in the root or github.com/selz/plyr
// ==========================================================================
/*global plyr*/
// General functions
;(function() {
document.body.addEventListener('ready', function(event) { console.log(event); });
// Setup the player
var instances = plyr.setup({
debug: true,
title: 'Video demo',
iconUrl: '../dist/plyr.svg',
tooltips: {
controls: true
},
captions: {
defaultActive: true
}
});
plyr.loadSprite('dist/demo.svg');
// Plyr returns an array regardless
var player = instances[0].plyr;
// Setup type toggle
var buttons = document.querySelectorAll('[data-source]'),
types = {
video: 'video',
audio: 'audio',
youtube: 'youtube',
vimeo: 'vimeo'
},
currentType = window.location.hash.replace('#', ''),
historySupport = (window.history && window.history.pushState);
// Bind to each button
for (var i = buttons.length - 1; i >= 0; i--) {
buttons[i].addEventListener('click', function() {
var type = this.getAttribute('data-source');
newSource(type);
if (historySupport) {
history.pushState({ 'type': type }, '', '#' + type);
}
});
}
// List for backwards/forwards
window.addEventListener('popstate', function(event) {
if(event.state && 'type' in event.state) {
newSource(event.state.type);
}
});
// On load
if(historySupport) {
var video = !currentType.length;
// If there's no current type set, assume video
if(video) {
currentType = types.video;
}
// Replace current history state
if(currentType in types) {
history.replaceState({ 'type': currentType }, '', (video ? '' : '#' + currentType));
}
// If it's not video, load the source
if(currentType !== types.video) {
newSource(currentType, true);
}
}
// Toggle class on an element
function toggleClass(element, className, state) {
if (element) {
if (element.classList) {
element.classList[state ? 'add' : 'remove'](className);
}
else {
var name = (' ' + element.className + ' ').replace(/\s+/g, ' ').replace(' ' + className + ' ', '');
element.className = name + (state ? ' ' + className : '');
}
}
}
// Set a new source
function newSource(type, init) {
// Bail if new type isn't known, it's the current type, or current type is empty (video is default) and new type is video
if(!(type in types) || (!init && type == currentType) || (!currentType.length && type == types.video)) {
return;
}
switch(type) {
case types.video:
player.source({
type: 'video',
title: 'View From A Blue Moon',
sources: [{
src: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4',
type: 'video/mp4'
},
{
src: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm',
type: 'video/webm'
}],
poster: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg',
tracks: [{
kind: 'captions',
label: 'English',
srclang:'en',
src: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt',
default: true
}]
});
break;
case types.audio:
player.source({
type: 'audio',
title: 'Kishi Bashi &ndash; &ldquo;It All Began With A Burst&rdquo;',
sources: [{
src: 'https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3',
type: 'audio/mp3'
},
{
src: 'https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg',
type: 'audio/ogg'
}]
});
break;
case types.youtube:
player.source({
type: 'video',
title: 'View From A Blue Moon',
sources: [{
src: 'bTqVqk7FSmY',
type: 'youtube'
}]
});
break;
case types.vimeo:
player.source({
type: 'video',
title: 'View From A Blue Moon',
sources: [{
src: '143418951',
type: 'vimeo'
}]
});
break;
}
// Set the current type for next time
currentType = type;
// Remove active classes
for (var x = buttons.length - 1; x >= 0; x--) {
toggleClass(buttons[x].parentElement, 'active', false);
}
// Set active on parent
toggleClass(document.querySelector('[data-source="'+ type +'"]').parentElement, 'active', true);
}
})();
// Google analytics
// For demo site (http://[www.]plyr.io) only
if(document.domain.indexOf('plyr.io') > -1) {
(function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-40881672-11', 'auto');
ga('send', 'pageview');
}

View File

@ -21,7 +21,7 @@ video {
.plyr--audio { .plyr--audio {
max-width: @example-width-audio; max-width: @example-width-audio;
} }
.plyr--video::after { .plyr__video-wrapper::after {
content: ""; content: "";
pointer-events: none; pointer-events: none;
position: absolute; position: absolute;

View File

@ -1,5 +1,5 @@
// ========================================================================== // ==========================================================================
// HTML5 Video Player Demo Page // Plyr.io Demo Page
// ========================================================================== // ==========================================================================
// CSS Reset // CSS Reset

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 981 B

After

Width:  |  Height:  |  Size: 981 B

View File

Before

Width:  |  Height:  |  Size: 779 B

After

Width:  |  Height:  |  Size: 779 B

View File

Before

Width:  |  Height:  |  Size: 739 B

After

Width:  |  Height:  |  Size: 739 B

2
dist/plyr.css vendored

File diff suppressed because one or more lines are too long

4
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

1
docs/dist/docs.css vendored

File diff suppressed because one or more lines are too long

1
docs/dist/docs.js vendored
View File

@ -1 +0,0 @@
"document"in self&&("classList"in document.createElement("_")?!function(){"use strict";var e=document.createElement("_");if(e.classList.add("c1","c2"),!e.classList.contains("c2")){var t=function(e){var t=DOMTokenList.prototype[e];DOMTokenList.prototype[e]=function(e){var i,s=arguments.length;for(i=0;s>i;i++)e=arguments[i],t.call(this,e)}};t("add"),t("remove")}if(e.classList.toggle("c3",!1),e.classList.contains("c3")){var i=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(e,t){return 1 in arguments&&!this.contains(e)==!t?t:i.call(this,e)}}e=null}():!function(e){"use strict";if("Element"in e){var t="classList",i="prototype",s=e.Element[i],o=Object,n=String[i].trim||function(){return this.replace(/^\s+|\s+$/g,"")},r=Array[i].indexOf||function(e){for(var t=0,i=this.length;i>t;t++)if(t in this&&this[t]===e)return t;return-1},a=function(e,t){this.name=e,this.code=DOMException[e],this.message=t},c=function(e,t){if(""===t)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(t))throw new a("INVALID_CHARACTER_ERR","String contains an invalid character");return r.call(e,t)},l=function(e){for(var t=n.call(e.getAttribute("class")||""),i=t?t.split(/\s+/):[],s=0,o=i.length;o>s;s++)this.push(i[s]);this._updateClassName=function(){e.setAttribute("class",this.toString())}},u=l[i]=[],d=function(){return new l(this)};if(a[i]=Error[i],u.item=function(e){return this[e]||null},u.contains=function(e){return e+="",-1!==c(this,e)},u.add=function(){var e,t=arguments,i=0,s=t.length,o=!1;do e=t[i]+"",-1===c(this,e)&&(this.push(e),o=!0);while(++i<s);o&&this._updateClassName()},u.remove=function(){var e,t,i=arguments,s=0,o=i.length,n=!1;do for(e=i[s]+"",t=c(this,e);-1!==t;)this.splice(t,1),n=!0,t=c(this,e);while(++s<o);n&&this._updateClassName()},u.toggle=function(e,t){e+="";var i=this.contains(e),s=i?t!==!0&&"remove":t!==!1&&"add";return s&&this[s](e),t===!0||t===!1?t:!i},u.toString=function(){return this.join(" ")},o.defineProperty){var p={get:d,enumerable:!0,configurable:!0};try{o.defineProperty(s,t,p)}catch(h){-2146823252===h.number&&(p.enumerable=!1,o.defineProperty(s,t,p))}}else o[i].__defineGetter__&&s.__defineGetter__(t,d)}}(self)),plyr.setup(".js-media-player",{debug:!0,title:"Video demo",iconUrl:"../dist/plyr.svg",tooltips:{controls:!0},captions:{defaultActive:!0}}),plyr.loadSprite("dist/docs.svg"),function(){function e(e,t,i){if(e)if(e.classList)e.classList[i?"add":"remove"](t);else{var s=(" "+e.className+" ").replace(/\s+/g," ").replace(" "+t+" ","");e.className=s+(i?" "+t:"")}}function t(t,n){if(t in s&&(n||t!=o)&&(o.length||t!=s.video)){var r=document.querySelector(".js-media-player").plyr;switch(t){case s.video:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4",type:"video/mp4"},{src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm",type:"video/webm"}],poster:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg",tracks:[{kind:"captions",label:"English",srclang:"en",src:"https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt","default":!0}]});break;case s.audio:r.source({type:"audio",title:"Kishi Bashi &ndash; &ldquo;It All Began With A Burst&rdquo;",sources:[{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3",type:"audio/mp3"},{src:"https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg",type:"audio/ogg"}]});break;case s.youtube:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"bTqVqk7FSmY",type:"youtube"}]});break;case s.vimeo:r.source({type:"video",title:"View From A Blue Moon",sources:[{src:"143418951",type:"vimeo"}]})}o=t;for(var a=i.length-1;a>=0;a--)e(i[a].parentElement,"active",!1);e(document.querySelector('[data-source="'+t+'"]').parentElement,"active",!0)}}for(var i=document.querySelectorAll("[data-source]"),s={video:"video",audio:"audio",youtube:"youtube",vimeo:"vimeo"},o=window.location.hash.replace("#",""),n=window.history&&window.history.pushState,r=i.length-1;r>=0;r--)i[r].addEventListener("click",function(){var e=this.getAttribute("data-source");t(e),n&&history.pushState({type:e},"","#"+e)});if(window.addEventListener("popstate",function(e){e.state&&"type"in e.state&&t(e.state.type)}),n){var a=!o.length;a&&(o=s.video),o in s&&history.replaceState({type:o},"",a?"":"#"+o),o!==s.video&&t(o,!0)}}(),document.domain.indexOf("plyr.io")>-1&&(!function(e,t,i,s,o,n,r){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,n=t.createElement(i),r=t.getElementsByTagName(i)[0],n.async=1,n.src=s,r.parentNode.insertBefore(n,r)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),ga("create","UA-40881672-11","auto"),ga("send","pageview"));

View File

@ -1,180 +0,0 @@
// ==========================================================================
// Docs example
// ==========================================================================
/*global plyr*/
// Setup the player
plyr.setup('.js-media-player', {
debug: true,
title: 'Video demo',
iconUrl: '../dist/plyr.svg',
tooltips: {
controls: true
},
captions: {
defaultActive: true
}
});
plyr.loadSprite('dist/docs.svg');
// General functions
(function() {
var buttons = document.querySelectorAll('[data-source]'),
types = {
video: 'video',
audio: 'audio',
youtube: 'youtube',
vimeo: 'vimeo'
},
currentType = window.location.hash.replace('#', ''),
historySupport = (window.history && window.history.pushState);
// Bind to each button
for (var i = buttons.length - 1; i >= 0; i--) {
buttons[i].addEventListener('click', function() {
var type = this.getAttribute('data-source');
newSource(type);
if (historySupport) {
history.pushState({ 'type': type }, '', '#' + type);
}
});
}
// List for backwards/forwards
window.addEventListener('popstate', function(event) {
if(event.state && 'type' in event.state) {
newSource(event.state.type);
}
});
// On load
if(historySupport) {
var video = !currentType.length;
// If there's no current type set, assume video
if(video) {
currentType = types.video;
}
// Replace current history state
if(currentType in types) {
history.replaceState({ 'type': currentType }, '', (video ? '' : '#' + currentType));
}
// If it's not video, load the source
if(currentType !== types.video) {
newSource(currentType, true);
}
}
// Toggle class on an element
function toggleClass(element, className, state) {
if (element) {
if (element.classList) {
element.classList[state ? 'add' : 'remove'](className);
}
else {
var name = (' ' + element.className + ' ').replace(/\s+/g, ' ').replace(' ' + className + ' ', '');
element.className = name + (state ? ' ' + className : '');
}
}
}
// Set a new source
function newSource(type, init) {
// Bail if new type isn't known, it's the current type, or current type is empty (video is default) and new type is video
if(!(type in types) || (!init && type == currentType) || (!currentType.length && type == types.video)) {
return;
}
// Get plyr instance
var player = document.querySelector('.js-media-player').plyr;
switch(type) {
case types.video:
player.source({
type: 'video',
title: 'View From A Blue Moon',
sources: [{
src: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.mp4',
type: 'video/mp4'
},
{
src: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.webm',
type: 'video/webm'
}],
poster: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg',
tracks: [{
kind: 'captions',
label: 'English',
srclang:'en',
src: 'https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.en.vtt',
default: true
}]
});
break;
case types.audio:
player.source({
type: 'audio',
title: 'Kishi Bashi &ndash; &ldquo;It All Began With A Burst&rdquo;',
sources: [{
src: 'https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3',
type: 'audio/mp3'
},
{
src: 'https://cdn.selz.com/plyr/1.5/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg',
type: 'audio/ogg'
}]
});
break;
case types.youtube:
player.source({
type: 'video',
title: 'View From A Blue Moon',
sources: [{
src: 'bTqVqk7FSmY',
type: 'youtube'
}]
});
break;
case types.vimeo:
player.source({
type: 'video',
title: 'View From A Blue Moon',
sources: [{
src: '143418951',
type: 'vimeo'
}]
});
break;
}
// Set the current type for next time
currentType = type;
// Remove active classes
for (var x = buttons.length - 1; x >= 0; x--) {
toggleClass(buttons[x].parentElement, 'active', false);
}
// Set active on parent
toggleClass(document.querySelector('[data-source="'+ type +'"]').parentElement, 'active', true);
}
})();
// Google analytics
// For demo site (http://[www.]plyr.io) only
if(document.domain.indexOf('plyr.io') > -1) {
(function(i,s,o,g,r,a,m){i.GoogleAnalyticsObject=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-40881672-11', 'auto');
ga('send', 'pageview');
}

View File

@ -37,19 +37,19 @@ paths = {
// Output paths // Output paths
output: path.join(root, "dist/") output: path.join(root, "dist/")
}, },
docs: { demo: {
// Source paths // Source paths
src: { src: {
less: path.join(root, "docs/src/less/**/*"), less: path.join(root, "demo/src/less/**/*"),
js: path.join(root, "docs/src/js/**/*"), js: path.join(root, "demo/src/js/**/*"),
sprite: path.join(root, "docs/src/sprite/**/*") sprite: path.join(root, "demo/src/sprite/**/*")
}, },
// Output paths // Output paths
output: path.join(root, "docs/dist/"), output: path.join(root, "demo/dist/"),
// Docs // Demo
root: path.join(root, "docs/") root: path.join(root, "demo/")
}, },
upload: [path.join(root, "dist/**"), path.join(root, "docs/dist/**")] upload: [path.join(root, "dist/**"), path.join(root, "demo/dist/**")]
}, },
// Task arrays // Task arrays
@ -178,10 +178,10 @@ build.less(bundles.plyr.less, "plyr");
build.scss(bundles.plyr.scss, "plyr"); build.scss(bundles.plyr.scss, "plyr");
build.sprite("plyr"); build.sprite("plyr");
// Docs files // Demo files
build.less(bundles.docs.less, "docs"); build.less(bundles.demo.less, "demo");
build.js(bundles.docs.js, "docs"); build.js(bundles.demo.js, "demo");
build.sprite("docs"); build.sprite("demo");
// Build all JS // Build all JS
gulp.task("js", function(){ gulp.task("js", function(){
@ -200,10 +200,10 @@ gulp.task("watch", function () {
gulp.watch(paths.plyr.src.less, tasks.less); gulp.watch(paths.plyr.src.less, tasks.less);
gulp.watch(paths.plyr.src.sprite, tasks.sprite); gulp.watch(paths.plyr.src.sprite, tasks.sprite);
// Docs // Demo
gulp.watch(paths.docs.src.js, tasks.js); gulp.watch(paths.demo.src.js, tasks.js);
gulp.watch(paths.docs.src.less, tasks.less); gulp.watch(paths.demo.src.less, tasks.less);
gulp.watch(paths.docs.src.sprite, tasks.sprite); gulp.watch(paths.demo.src.sprite, tasks.sprite);
}); });
// Default gulp task // Default gulp task
@ -211,7 +211,7 @@ gulp.task("default", function(){
run(tasks.js, tasks.less, tasks.sprite, "watch"); run(tasks.js, tasks.less, tasks.sprite, "watch");
}); });
// Publish a version to CDN and docs // Publish a version to CDN and demo
// -------------------------------------------- // --------------------------------------------
// Some options // Some options
@ -225,7 +225,7 @@ options = {
"Vary": "Accept-Encoding" "Vary": "Accept-Encoding"
} }
}, },
docs: { demo: {
headers: { headers: {
"Cache-Control": "no-cache, no-store, must-revalidate, max-age=0", "Cache-Control": "no-cache, no-store, must-revalidate, max-age=0",
"Vary": "Accept-Encoding" "Vary": "Accept-Encoding"
@ -268,9 +268,9 @@ gulp.task("cdn", function () {
.pipe(s3(aws.cdn, options.cdn)); .pipe(s3(aws.cdn, options.cdn));
}); });
// Publish to Docs bucket // Publish to demo bucket
gulp.task("docs", function () { gulp.task("demo", function () {
console.log("Uploading " + version + " docs to " + aws.docs.bucket + "..."); console.log("Uploading " + version + " demo to " + aws.demo.bucket + "...");
// Replace versioned files in readme.md // Replace versioned files in readme.md
gulp.src([root + "/readme.md"]) gulp.src([root + "/readme.md"])
@ -283,19 +283,19 @@ gulp.task("docs", function () {
.pipe(replace(cdnpath, aws.cdn.bucket + "/" + version)) .pipe(replace(cdnpath, aws.cdn.bucket + "/" + version))
.pipe(gulp.dest(path.join(root, "src/js/"))); .pipe(gulp.dest(path.join(root, "src/js/")));
// Replace local file paths with remote paths in docs HTML // Replace local file paths with remote paths in demo HTML
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js" // e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
gulp.src([paths.docs.root + "*.html"]) gulp.src([paths.demo.root + "*.html"])
.pipe(replace(localPath, versionPath)) .pipe(replace(localPath, versionPath))
.pipe(s3(aws.docs, options.docs)); .pipe(s3(aws.demo, options.demo));
// Upload error.html to cdn (as well as docs site) // Upload error.html to cdn (as well as demo site)
return gulp.src([paths.docs.root + "error.html"]) return gulp.src([paths.demo.root + "error.html"])
.pipe(replace(localPath, versionPath)) .pipe(replace(localPath, versionPath))
.pipe(s3(aws.cdn, options.docs)); .pipe(s3(aws.cdn, options.demo));
}); });
// Open the docs site to check it's sweet // Open the demo site to check it's sweet
gulp.task("symlinks", function () { gulp.task("symlinks", function () {
console.log("Updating symlinks..."); console.log("Updating symlinks...");
@ -318,20 +318,20 @@ gulp.task("symlinks", function () {
})); }));
}); });
// Open the docs site to check it's sweet // Open the demo site to check it's sweet
gulp.task("open", function () { gulp.task("open", function () {
console.log("Opening " + aws.docs.bucket + "..."); console.log("Opening " + aws.demo.bucket + "...");
// A file must be specified or gulp will skip the task // A file must be specified or gulp will skip the task
// Doesn't matter which file since we set the URL above // Doesn't matter which file since we set the URL above
// Weird, I know... // Weird, I know...
return gulp.src([paths.docs.root + "index.html"]) return gulp.src([paths.demo.root + "index.html"])
.pipe(open("", { .pipe(open("", {
url: "http://" + aws.docs.bucket url: "http://" + aws.demo.bucket
})); }));
}); });
// Do everything // Do everything
gulp.task("publish", function () { gulp.task("publish", function () {
run(tasks.js, tasks.less, tasks.sprite, "cdn", "docs", "symlinks"); run(tasks.js, tasks.less, tasks.sprite, "cdn", "demo", "symlinks");
}); });

View File

@ -1,6 +1,6 @@
{ {
"name": "plyr", "name": "plyr",
"version": "1.6.18", "version": "1.8.8",
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player", "description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
"homepage": "http://plyr.io", "homepage": "http://plyr.io",
"main": "src/js/plyr.js", "main": "src/js/plyr.js",
@ -27,7 +27,11 @@
"keywords": [ "keywords": [
"HTML5 Video", "HTML5 Video",
"HTML5 Audio", "HTML5 Audio",
"Media Player" "Media Player",
"DASH",
"Shaka",
"WordPress",
"HLS"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
@ -38,7 +42,7 @@
"url": "https://github.com/selz/plyr/issues" "url": "https://github.com/selz/plyr/issues"
}, },
"directories": { "directories": {
"doc": "docs" "doc": "readme.md"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"

537
readme.md
View File

@ -3,7 +3,7 @@ A simple, accessible and customizable HTML5, YouTube and Vimeo media player.
[Checkout the demo](https://plyr.io) [Checkout the demo](https://plyr.io)
[![Image of Plyr](https://cdn.selz.com/plyr/1.5/plyr_v1.6.6.png)](https://plyr.io) [![Image of Plyr](https://cdn.selz.com/plyr/plyr_v1.8.png)](https://plyr.io)
## Why? ## Why?
We wanted a lightweight, accessible and customizable media player that supports [*modern*](#browser-support) browsers. Sure, there are many other players out there but we wanted to keep things simple, using the right elements for the job. We wanted a lightweight, accessible and customizable media player that supports [*modern*](#browser-support) browsers. Sure, there are many other players out there but we wanted to keep things simple, using the right elements for the job.
@ -22,6 +22,7 @@ We wanted a lightweight, accessible and customizable media player that supports
- **i18n support** - support for internationalization of controls - **i18n support** - support for internationalization of controls
- **No dependencies** - written in "vanilla" JavaScript, no jQuery required - **No dependencies** - written in "vanilla" JavaScript, no jQuery required
- **SASS and LESS provided** - If you like _these_ over plain CSS - **SASS and LESS provided** - If you like _these_ over plain CSS
- **[Streaming](#streaming)** - Support for hls.js, Shaka and dash.js streaming playback
Oh and yes, it works with Bootstrap. Oh and yes, it works with Bootstrap.
@ -38,22 +39,24 @@ Check out the [changelog](changelog.md) to see what's new with Plyr.
If you have any cool ideas or features, please let me know by [creating an issue](https://github.com/Selz/plyr/issues/new) or, of course, forking and sending a pull request. If you have any cool ideas or features, please let me know by [creating an issue](https://github.com/Selz/plyr/issues/new) or, of course, forking and sending a pull request.
## Implementation ## CMS plugins
Check `docs/index.html` and `docs/src/js/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.6.18/plyr.js` to `https://cdn.plyr.io/1.6.18/plyr.js` ### [WordPress](https://wordpress.org/plugins/plyr/)
Created and maintained by Ryan Anthony Drake ([@iamryandrake](https://github.com/iamryandrake))
### [Neos](https://packagist.org/packages/jonnitto/plyr)
Created and maintained by Jon Uhlmann ([@jonnitto](https://github.com/jonnitto))
## Using package managers
You can grab the source using one of the following package managers.
### npm ### npm
Using `npm`, you can grab Plyr:
``` ```
npm install plyr npm install plyr
``` ```
[https://www.npmjs.com/package/plyr](https://www.npmjs.com/package/plyr) [https://www.npmjs.com/package/plyr](https://www.npmjs.com/package/plyr)
### Bower ### Bower
If bower is your thing, you can grab Plyr using:
``` ```
bower install plyr bower install plyr
``` ```
@ -68,24 +71,78 @@ ember addon:install ember-cli-plyr
``` ```
More info is on [npm](https://www.npmjs.com/package/ember-cli-plyr) and [GitHub](https://github.com/louisrudner/ember-cli-plyr) More info is on [npm](https://www.npmjs.com/package/ember-cli-plyr) and [GitHub](https://github.com/louisrudner/ember-cli-plyr)
### CDN ## Quick setup
If you want to use our CDN, you can use the following: Here's a quick run through on getting up and running.
### HTML
Plyr extends upon the standard HTML5 markup so that's all you need for those types.
#### HTML5 Video
```html ```html
<link rel="stylesheet" href="https://cdn.plyr.io/1.6.18/plyr.css"> <video poster="/path/to/poster.jpg" controls>
<script src="https://cdn.plyr.io/1.6.18/plyr.js"></script> <source src="/path/to/video.mp4" type="video/mp4">
<source src="/path/to/video.webm" type="video/webm">
<!-- Captions are optional -->
<track kind="captions" label="English captions" src="/path/to/captions.vtt" srclang="en" default>
</video>
``` ```
The SVG sprite/defs file can be found here: `https://cdn.plyr.io/1.6.18/plyr.svg`. #### HTML5 Audio
### CSS & Styling
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.scss` file included in `/src` in your build to save a request.
```html ```html
<link rel="stylesheet" href="dist/plyr.css"> <audio controls>
<source src="/path/to/audio.mp3" type="audio/mp3">
<source src="/path/to/audio.ogg" type="audio/ogg">
</audio>
``` ```
The default setup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options. Check out the source for more on this. For YouTube and Vimeo, Plyr uses the standard YouTube API markup (an empty `<div>`):
#### YouTube embed
```html
<div data-type="youtube" data-video-id="bTqVqk7FSmY"></div>
```
#### Vimeo embed
```html
<div data-type="vimeo" data-video-id="143418951"></div>
```
### JavaScript
Include the `plyr.js` script before the closing `</body>` tag and then call `plyr.setup()`. More info on `setup()` can be found under [#initialising](initialising).
```html
<script src="path/to/plyr.js"></script>
<script>plyr.setup();</script>
```
If you want to use our CDN for the JavaScript, you can use the following:
```html
<script src="https://cdn.plyr.io/1.8.8/plyr.js"></script>
```
### CSS
Include the `plyr.css` stylsheet into your `<head>`
```html
<link rel="stylesheet" href="path/to/plyr.css">
```
If you want to use our CDN for the default CSS, you can use the following:
```html
<link rel="stylesheet" href="https://cdn.plyr.io/1.8.8/plyr.css">
```
### SVG Sprite
The SVG sprite is loaded automatically from our CDN. To change this, see the [#options](Options) below. For reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/1.8.8/plyr.svg`.
## Advanced
### LESS & SASS/SCSS
You can use `plyr.less` or `plyr.scss` file included in `/src` as part of your build and change variables to suit your design. The LESS and SASS require you to use the [autoprefixer](https://www.npmjs.com/package/gulp-autoprefixer) plugin (you should already) as all declerations use the W3C definitions - e.g. `appearance: none;` will be prefixed to `-webkit-appearance: none;` by autoprefixer.
The HTML markup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options to match any custom CSS you write. Check out the JavaScript source for more on this.
### SVG ### SVG
The icons used in the Plyr controls are loaded in an SVG sprite. The sprite is automatically loaded from our CDN by default. If you already have an icon build system in place, you can include the source plyr icons (see `/src/sprite` for source icons). The icons used in the Plyr controls are loaded in an SVG sprite. The sprite is automatically loaded from our CDN by default. If you already have an icon build system in place, you can include the source plyr icons (see `/src/sprite` for source icons).
@ -101,281 +158,226 @@ More info on SVG sprites here:
and the AJAX technique here: and the AJAX technique here:
[http://css-tricks.com/ajaxing-svg-sprite/](http://css-tricks.com/ajaxing-svg-sprite/) [http://css-tricks.com/ajaxing-svg-sprite/](http://css-tricks.com/ajaxing-svg-sprite/)
### HTML ### Cross Origin (CORS)
The only extra markup that's needed to use plyr is a `<div>` wrapper. Replace the source, poster and captions with urls for your media. You'll notice the `crossorigin` attribute on the example `<video>` elements. This is because the TextTrack captions are loaded from another domain. If your TextTrack captions are also hosted on another domain, you will need to add this attribute and make sure your host has the correct headers setup. For more info on CORS checkout the MDN docs:
```html
<div class="plyr">
<video poster="/path/to/poster.jpg" controls>
<!-- Video files -->
<source src="/path/to/video.mp4" type="video/mp4">
<source src="/path/to/video.webm" type="video/webm">
<!-- Text track file -->
<track kind="captions" label="English captions" src="/path/to/captions.vtt" srclang="en" default>
<!-- Fallback for browsers that don't support the <video> element -->
<a href="/path/to/movie.mp4">Download</a>
</video>
</div>
```
And the same for `<audio>`
```html
<div class="plyr">
<audio controls>
<!-- Audio files -->
<source src="/path/to/audio.mp3" type="audio/mp3">
<source src="/path/to/audio.ogg" type="audio/ogg">
<!-- Fallback for browsers that don't support the <audio> element -->
<a href="/path/to/audio.mp3">Download</a>
</audio>
</div>
```
For YouTube and Vimeo, Plyr uses the standard YouTube API markup (an empty `<div>`):
```html
<div class="plyr">
<div data-video-id="bTqVqk7FSmY" data-type="youtube"></div>
</div>
```
```html
<div class="plyr">
<div data-video-id="143418951" data-type="vimeo"></div>
</div>
```
#### Cross Origin (CORS)
You'll notice the `crossorigin` attribute on the example `<video>` and `<audio>` elements. This is because the media is loaded from another domain. If your media is hosted on another domain, you may need to add this attribute.
More info on CORS here:
[https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) [https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS)
### Captions ### Captions
WebVTT captions are supported. To add a caption track, check the HTML example above and look for the `<track>` element. WebVTT captions are supported. To add a caption track, check the HTML example above and look for the `<track>` element. Be sure to [validate your caption files](https://quuz.org/webvtt/).
Be sure to [validate your caption files](https://quuz.org/webvtt/)
### JavaScript ### JavaScript
#### Quick setup #### Initialising
Here's an example of a default setup: By default, Plyr looks for all `<video>`, `<audio>` and `[data-type]` elements with the document and initialises on any found. You can specify other options, including a different NodeList, HTMLElement or string selector as below:
```html
<script src="https://cdn.plyr.io/1.6.18/plyr.js"></script>
<script>plyr.setup();</script>
```
This will look for all elements with the specified container classname (default is `plyr`) and setup plyr on each element found. You can specify other options, including a different selector hook below. The container classname will be added to the specified element(s) if it is not already present (for the CSS).
You can initialize the player a few other ways:
Passing a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList): Passing a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList):
```javascript ```javascript
plyr.setup(document.querySelectorAll('.js-plyr'), options); plyr.setup(document.querySelectorAll('.js-player'), options);
``` ```
Passing a [HTMLElement](https://developer.mozilla.org/en/docs/Web/API/HTMLElement): Passing a [HTMLElement](https://developer.mozilla.org/en/docs/Web/API/HTMLElement):
```javascript ```javascript
plyr.setup(document.querySelector('.js-plyr'), options); plyr.setup(document.querySelector('.js-player'), options);
``` ```
Passing a [string selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll): Passing a [string selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll):
```javascript ```javascript
plyr.setup('.js-plyr', options); plyr.setup('.js-player', options);
``` ```
The NodeList, HTMLElement or string selector can be the target `<video>`, `<audio>` or `[data-type]` (for embeds) element or a container element. If a container has several media elements inside, each media element will be wrapped in a `<div>` and setup individually.
Passing just the options object: Passing just the options object:
```javascript ```javascript
plyr.setup(options); plyr.setup(options);
``` ```
`setup()` will return an array of all the elements Plyr was setup on. The `plyr` object can be accessed on these elements and used for the API.
#### RangeTouch #### RangeTouch
Some touch browsers (particularly Mobile Safari on iOS) seem to have issues with `<input type="range">` 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. Some touch browsers (particularly Mobile Safari on iOS) seem to have issues with `<input type="range">` 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.
#### Options #### Options
Options must be passed as an object to the `setup()` method as above or as JSON in `data-plyr` attribute on each of your target elements: Options must be passed as an object to the `setup()` method as above or as JSON in `data-plyr` attribute on each of your target elements:
```html ```html
<div class="plyr" data-plyr='{ title: "testing" }'> <video data-plyr='{ title: "testing" }'></video>
``` ```
Note the single quotes encapsulating the JSON and double quotes on the object keys. Note the single quotes encapsulating the JSON and double quotes on the object keys.
<table class="table" width="100%"> <table class="table" width="100%">
<thead> <thead>
<tr> <tr>
<th width="20%">Option</th> <th width="20%">Option</th>
<th width="15%">Type</th> <th width="15%">Type</th>
<th width="15%">Default</th> <th width="15%">Default</th>
<th width="50%">Description</th> <th width="50%">Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td><code>enabled</code></td> <td><code>enabled</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>true</code></td> <td><code>true</code></td>
<td>Completely disable Plyr. This would allow you to do a User Agent check or similar to programmatically enable or disable Plyr for a certain UA. Example below.</td> <td>Completely disable Plyr. This would allow you to do a User Agent check or similar to programmatically enable or disable Plyr for a certain UA. Example below.</td>
</tr> </tr>
<tr> <tr>
<td><code>html</code></td> <td><code>html</code></td>
<td>String</td> <td>String</td>
<td><code><a href="controls.md">See controls.md</a></code></td> <td><code><a href="controls.md">See controls.md</a></code></td>
<td>See <a href="controls.md">controls.md</a> for more info on how the html needs to be structured.</td> <td>See <a href="controls.md">controls.md</a> for more info on how the html needs to be structured.</td>
</tr> </tr>
<tr> <tr>
<td><code>controls</code></td> <td><code>controls</code></td>
<td>Array</td> <td>Array</td>
<td><code>['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'fullscreen']</code></td> <td><code>['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'fullscreen']</code></td>
<td>Toggle which control elements you would like to display when using the default controls html. If you specify a <code>html</code> option, this is redundant. The default value is to display everything.</td> <td>Toggle which control elements you would like to display when using the default controls html. If you specify a <code>html</code> option, this is redundant. The default value is to display everything.</td>
</tr> </tr>
<tr> <tr>
<td><code>i18n</code></td> <td><code>i18n</code></td>
<td>Object</td> <td>Object</td>
<td><code><a href="controls.md">See controls.md</a></code></td> <td><code><a href="controls.md">See controls.md</a></code></td>
<td>Used for internationalization (i18n) of the tooltips/labels within the buttons.</td> <td>Used for internationalization (i18n) of the tooltips/labels within the buttons.</td>
</tr> </tr>
<tr> <tr>
<td><code>loadSprite</code></td> <td><code>loadSprite</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>true</code></td> <td><code>true</code></td>
<td>Load the SVG sprite specified as the <code>iconUrl</code> option (if a URL). If <code>false</code>, it is assumed you are handling sprite loading yourself.</td> <td>Load the SVG sprite specified as the <code>iconUrl</code> option (if a URL). If <code>false</code>, it is assumed you are handling sprite loading yourself.</td>
</tr> </tr>
<tr> <tr>
<td><code>iconUrl</code></td> <td><code>iconUrl</code></td>
<td>String</td> <td>String</td>
<td><code>null</code></td> <td><code>null</code></td>
<td>Specify a URL or path to the SVG sprite. See the <a href="#svg">SVG section</a> for more info.</td> <td>Specify a URL or path to the SVG sprite. See the <a href="#svg">SVG section</a> for more info.</td>
</tr> </tr>
<tr> <tr>
<td><code>iconPrefix</code></td> <td><code>iconPrefix</code></td>
<td>String</td> <td>String</td>
<td><code>plyr</code></td> <td><code>plyr</code></td>
<td>Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG sprite but with the default controls. Most people can ignore this option.</td> <td>Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG sprite but with the default controls. Most people can ignore this option.</td>
</tr> </tr>
<tr> <tr>
<td><code>debug</code></td> <td><code>debug</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>false</code></td> <td><code>false</code></td>
<td>Display debugging information on what Plyr is doing.</td> <td>Display debugging information on what Plyr is doing.</td>
</tr> </tr>
<tr> <tr>
<td><code>autoplay</code></td> <td><code>autoplay</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>false</code></td> <td><code>false</code></td>
<td>Autoplay the media on load. This is generally advised against on UX grounds. It is also disabled on iOS (an Apple limitation).</td> <td>Autoplay the media on load. This is generally advised against on UX grounds. It is also disabled on iOS (an Apple limitation).</td>
</tr> </tr>
<tr> <tr>
<td><code>seekTime</code></td> <td><code>seekTime</code></td>
<td>Number</td> <td>Number</td>
<td><code>10</code></td> <td><code>10</code></td>
<td>The time, in seconds, to seek when a user hits fast forward or rewind.</td> <td>The time, in seconds, to seek when a user hits fast forward or rewind.</td>
</tr> </tr>
<tr> <tr>
<td><code>volume</code></td> <td><code>volume</code></td>
<td>Number</td> <td>Number</td>
<td><code>5</code></td> <td><code>5</code></td>
<td>A number, between 1 and 10, representing the initial volume of the player.</td> <td>A number, between 1 and 10, representing the initial volume of the player.</td>
</tr> </tr>
<tr> <tr>
<td><code>clickToPlay</code></td> <td><code>clickToPlay</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>true</code></td> <td><code>true</code></td>
<td>Click (or tap) of the video container will toggle pause/play.</td> <td>Click (or tap) of the video container will toggle pause/play.</td>
</tr> </tr>
<tr> <tr>
<td><code>disableContextMenu</code></td> <td><code>disableContextMenu</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>true</code></td> <td><code>true</code></td>
<td>Disable right click menu on video to <em>help</em> as very primitive obfuscation to prevent downloads of content.</td> <td>Disable right click menu on video to <em>help</em> as very primitive obfuscation to prevent downloads of content.</td>
</tr> </tr>
<tr> <tr>
<td><code>hideControls</code></td> <td><code>hideControls</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>true</code></td> <td><code>true</code></td>
<td>Hide video controls automatically after 2s of no mouse or focus movement, on control element blur (tab out), on playback start or entering fullscreen. As soon as the mouse is moved, a control element is focused or playback is paused, the controls reappear instantly.</td> <td>Hide video controls automatically after 2s of no mouse or focus movement, on control element blur (tab out), on playback start or entering fullscreen. As soon as the mouse is moved, a control element is focused or playback is paused, the controls reappear instantly.</td>
</tr> </tr>
<tr> <tr>
<td><code>showPosterOnEnd</code></td> <td><code>showPosterOnEnd</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>false</code></td> <td><code>false</code></td>
<td>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.</td> <td>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.</td>
</tr> </tr>
<tr> <tr>
<td><code>tooltips</code></td> <td><code>tooltips</code></td>
<td>Object</td> <td>Object</td>
<td><code>{ controls: false, seek: true }</code></td> <td><code>{ controls: false, seek: true }</code></td>
<td> <td>
<strong>controls</strong>: Display control labels as tooltips on :hover &amp; :focus (by default, the labels are screen reader only). <strong>controls</strong>: Display control labels as tooltips on :hover &amp; :focus (by default, the labels are screen reader only).
<br><br> <br><br>
<strong>seek</strong>: Display a seek tooltip to indicate on click where the media would seek to. <strong>seek</strong>: Display a seek tooltip to indicate on click where the media would seek to.
</td> </td>
</tr> </tr>
<tr> <tr>
<td><code>duration</code></td> <td><code>duration</code></td>
<td>Number</td> <td>Number</td>
<td><code>null</code></td> <td><code>null</code></td>
<td>Specify a custom duration.</td> <td>Specify a custom duration.</td>
</tr> </tr>
<tr> <tr>
<td><code>displayDuration</code></td> <td><code>displayDuration</code></td>
<td>Boolean</td> <td>Boolean</td>
<td><code>true</code></td> <td><code>true</code></td>
<td>Displays the duration of the media on the "metadataloaded" event (on startup) in the current time display. This will only work if the `preload` attribute is not set to `none` (or is not set at all) and you choose not to display the duration (see <code>controls</code> option).</td> <td>Displays the duration of the media on the "metadataloaded" event (on startup) in the current time display. This will only work if the `preload` attribute is not set to `none` (or is not set at all) and you choose not to display the duration (see <code>controls</code> option).</td>
</tr> </tr>
<tr> <tr>
<td><code>selectors</code></td> <td><code>selectors</code></td>
<td>Object</td> <td>Object</td>
<td>&mdash;</td> <td>&mdash;</td>
<td>See <code>plyr.js</code> in <code>/src</code> for more info. You probably don't need to change any of these.</td> <td>See <code>plyr.js</code> in <code>/src</code> for more info. You probably don't need to change any of these.</td>
</tr> </tr>
<tr> <tr>
<td><code>listeners</code></td> <td><code>listeners</code></td>
<td>Object</td> <td>Object</td>
<td>&mdash;</td> <td>&mdash;</td>
<td>Allows early binding of event listeners to the controls. See <code>controls</code> above for list of controls and see <code>plyr.js</code> in <code>/src</code> for more info.</td> <td>Allows early binding of event listeners to the controls. See <code>controls</code> above for list of controls and see <code>plyr.js</code> in <code>/src</code> for more info.</td>
</tr> </tr>
<tr> <tr>
<td><code>classes</code></td> <td><code>classes</code></td>
<td>Object</td> <td>Object</td>
<td>&mdash;</td> <td>&mdash;</td>
<td>Similar to above, these are the classes added to the player when state changes occur.</td> <td>Similar to above, these are the classes added to the player when state changes occur.</td>
</tr> </tr>
<tr> <tr>
<td><code>captions</code></td> <td><code>captions</code></td>
<td>Object</td> <td>Object</td>
<td>&mdash;</td> <td>&mdash;</td>
<td>One property <code>defaultActive</code> which toggles if captions should be on by default. The default value is <code>false</code>.</td> <td>One property <code>defaultActive</code> which toggles if captions should be on by default. The default value is <code>false</code>.</td>
</tr> </tr>
<tr> <tr>
<td><code>fullscreen</code></td> <td><code>fullscreen</code></td>
<td>Object</td> <td>Object</td>
<td>&mdash;</td> <td>&mdash;</td>
<td>See <a href="#fullscreen-options">below</a></td> <td>See <a href="#fullscreen-options">below</a></td>
</tr> </tr>
<tr> <tr>
<td><code>storage</code></td> <td><code>storage</code></td>
<td>Object</td> <td>Object</td>
<td>&mdash;</td> <td>&mdash;</td>
<td>Two properties; <code>enabled</code> which toggles if local storage should be enabled (if the browser supports it). The default value is `true`. This enables storing user settings, currently it only stores volume but more will be added later. The second property <code>key</code> is the key used for the local storage. The default is <code>plyr_volume</code> until more settings are stored.</td> <td>Two properties; <code>enabled</code> which toggles if local storage should be enabled (if the browser supports it). The default value is `true`. This enables storing user settings, currently it only stores volume but more will be added later. The second property <code>key</code> is the key used for the local storage. The default is <code>plyr_volume</code> until more settings are stored.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
#### Fullscreen options #### Fullscreen options
<table class="table" width="100%" id="fullscreen-options"> <table class="table" width="100%" id="fullscreen-options">
<thead> <thead>
<tr> <tr>
<th width="20%">Option</th> <th width="20%">Option</th>
<th width="15%">Type</th> <th width="15%">Type</th>
<th width="15%">Default</th> <th width="15%">Default</th>
<th width="50%">Description</th> <th width="50%">Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
@ -401,22 +403,24 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke
## API ## API
#### Fetching the plyr instance #### 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. 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.
There are two ways to access the instance, firstly you re-query the element container you used for setup (e.g. `.js-plyr`) like so: 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:
```javascript ```javascript
var player = document.querySelector('.js-plyr').plyr; var player = document.querySelector('.js-player').plyr;
``` ```
Or you can use the returned object from your call to the setup method: 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:
```javascript ```javascript
var player = plyr.setup('.js-plyr')[0]; var player = plyr.setup('.js-player')[0].plyr;
``` ```
This will return an array of plyr instances setup, so you need to specify the index of the instance you want. This is less useful if you are setting up multiple instances. You can listen for the `setup` [event](#events) documented below which will return each instance one by one, as they are setup (in the `plyr` key of the event object). 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.
Once you have your instance, you can use the API methods below on it. For example to pause it: Once you have your instance, you can use the API methods below on it. For example to pause it:
@ -531,11 +535,15 @@ Here's a list of the methods supported:
<td>&mdash;</td> <td>&mdash;</td>
<td>Reverses the effects of the <code>destroy()</code> method, restoring the UI and listeners.</td> <td>Reverses the effects of the <code>destroy()</code> method, restoring the UI and listeners.</td>
</tr> </tr>
<tr>
<td><code>getCurrentTime()</code></td>
<td>&mdash;</td>
<td>Will return a float with the current time in seconds.</td>
</tr>
</tbody> </tbody>
</table> </table>
#### .source() method #### .source() method
This allows changing the plyr source and type on the fly. This allows changing the plyr source and type on the fly.
Video example: Video example:
@ -645,9 +653,7 @@ Some more details on the object parameters
</tbody> </tbody>
</table> </table>
## Events ## 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.
<table class="table" width="100%"> <table class="table" width="100%">
@ -787,8 +793,9 @@ document.querySelector('.js-plyr').addEventListener('ready', function(event) {
}); });
``` ```
## Embeds 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. 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. 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.
@ -813,9 +820,15 @@ More info on the respective API's here:
*Please note*: not all API methods may work 100%. Your mileage may vary. It's better to use the universal plyr API where possible. *Please note*: not all API methods may work 100%. Your mileage may vary. It's better to use the universal plyr API where possible.
## Fullscreen ## 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:
Fullscreen in Plyr is supported for all browsers that [currently support it](http://caniuse.com/#feat=fullscreen). If you're using the default CSS, you can also use a "full browser" mode which will use the full browser window by adding the `plyr-fullscreen` class to your container. - Using [hls.js](https://github.com/dailymotion/hls.js) - [Demo](http://codepen.io/sampotts/pen/JKEMqB)
- Using [Shaka](https://github.com/google/shaka-player) - [Demo](http://codepen.io/sampotts/pen/zBNpVR)
- Using [dash.js](https://github.com/Dash-Industry-Forum/dash.js) - [Demo](http://codepen.io/sampotts/pen/BzpJXN)
## Fullscreen
Fullscreen in Plyr is supported by all browsers that [currently support it](http://caniuse.com/#feat=fullscreen). If you're using the default CSS, you can also use a "full browser" mode which will use the full browser window by adding the `plyr-fullscreen` class to your container.
## Browser support ## Browser support

View File

@ -1,6 +1,6 @@
// ========================================================================== // ==========================================================================
// Plyr // Plyr
// plyr.js v1.6.18 // plyr.js v1.8.8
// https://github.com/selz/plyr // https://github.com/selz/plyr
// License: The MIT License (MIT) // License: The MIT License (MIT)
// ========================================================================== // ==========================================================================
@ -44,7 +44,7 @@
displayDuration: true, displayDuration: true,
loadSprite: true, loadSprite: true,
iconPrefix: 'plyr', iconPrefix: 'plyr',
iconUrl: 'https://cdn.plyr.io/1.6.18/plyr.svg', iconUrl: 'https://cdn.plyr.io/1.8.8/plyr.svg',
clickToPlay: true, clickToPlay: true,
hideControls: true, hideControls: true,
showPosterOnEnd: false, showPosterOnEnd: false,
@ -54,6 +54,8 @@
seek: true seek: true
}, },
selectors: { selectors: {
html5: 'video, audio',
embed: '[data-type]',
container: '.plyr', container: '.plyr',
controls: { controls: {
container: null, container: null,
@ -173,51 +175,61 @@
// Credits: http://paypal.github.io/accessible-html5-video-player/ // Credits: http://paypal.github.io/accessible-html5-video-player/
// Unfortunately, due to mixed support, UA sniffing is required // Unfortunately, due to mixed support, UA sniffing is required
function _browserSniff() { function _browserSniff() {
var nAgt = navigator.userAgent, var ua = navigator.userAgent,
name = navigator.appName, name = navigator.appName,
fullVersion = '' + parseFloat(navigator.appVersion), fullVersion = '' + parseFloat(navigator.appVersion),
majorVersion = parseInt(navigator.appVersion, 10), majorVersion = parseInt(navigator.appVersion, 10),
nameOffset, nameOffset,
verOffset, verOffset,
ix; ix,
isIE = false,
isFirefox = false,
isChrome = false,
isSafari = false;
// MSIE 11 // MSIE 11
if ((navigator.appVersion.indexOf('Windows NT') !== -1) && (navigator.appVersion.indexOf('rv:11') !== -1)) { if ((navigator.appVersion.indexOf('Windows NT') !== -1) && (navigator.appVersion.indexOf('rv:11') !== -1)) {
isIE = true;
name = 'IE'; name = 'IE';
fullVersion = '11;'; fullVersion = '11';
} }
// MSIE // MSIE
else if ((verOffset=nAgt.indexOf('MSIE')) !== -1) { else if ((verOffset = ua.indexOf('MSIE')) !== -1) {
isIE = true;
name = 'IE'; name = 'IE';
fullVersion = nAgt.substring(verOffset + 5); fullVersion = ua.substring(verOffset + 5);
} }
// Chrome // Chrome
else if ((verOffset=nAgt.indexOf('Chrome')) !== -1) { else if ((verOffset = ua.indexOf('Chrome')) !== -1) {
isChrome = true;
name = 'Chrome'; name = 'Chrome';
fullVersion = nAgt.substring(verOffset + 7); fullVersion = ua.substring(verOffset + 7);
} }
// Safari // Safari
else if ((verOffset=nAgt.indexOf('Safari')) !== -1) { else if ((verOffset = ua.indexOf('Safari')) !== -1) {
isSafari = true;
name = 'Safari'; name = 'Safari';
fullVersion = nAgt.substring(verOffset + 7); fullVersion = ua.substring(verOffset + 7);
if ((verOffset = nAgt.indexOf('Version')) !== -1) { if ((verOffset = ua.indexOf('Version')) !== -1) {
fullVersion = nAgt.substring(verOffset + 8); fullVersion = ua.substring(verOffset + 8);
} }
} }
// Firefox // Firefox
else if ((verOffset=nAgt.indexOf('Firefox')) !== -1) { else if ((verOffset = ua.indexOf('Firefox')) !== -1) {
isFirefox = true;
name = 'Firefox'; name = 'Firefox';
fullVersion = nAgt.substring(verOffset + 8); fullVersion = ua.substring(verOffset + 8);
} }
// In most other browsers, 'name/version' is at the end of userAgent // In most other browsers, 'name/version' is at the end of userAgent
else if ((nameOffset=nAgt.lastIndexOf(' ') + 1) < (verOffset=nAgt.lastIndexOf('/'))) { else if ((nameOffset = ua.lastIndexOf(' ') + 1) < (verOffset = ua.lastIndexOf('/'))) {
name = nAgt.substring(nameOffset,verOffset); name = ua.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset + 1); fullVersion = ua.substring(verOffset + 1);
if (name.toLowerCase() == name.toUpperCase()) { if (name.toLowerCase() == name.toUpperCase()) {
name = navigator.appName; name = navigator.appName;
} }
} }
// Trim the fullVersion string at semicolon/space if present // Trim the fullVersion string at semicolon/space if present
if ((ix = fullVersion.indexOf(';')) !== -1) { if ((ix = fullVersion.indexOf(';')) !== -1) {
fullVersion = fullVersion.substring(0, ix); fullVersion = fullVersion.substring(0, ix);
@ -225,6 +237,7 @@
if ((ix = fullVersion.indexOf(' ')) !== -1) { if ((ix = fullVersion.indexOf(' ')) !== -1) {
fullVersion = fullVersion.substring(0, ix); fullVersion = fullVersion.substring(0, ix);
} }
// Get major version // Get major version
majorVersion = parseInt('' + fullVersion, 10); majorVersion = parseInt('' + fullVersion, 10);
if (isNaN(majorVersion)) { if (isNaN(majorVersion)) {
@ -236,8 +249,12 @@
return { return {
name: name, name: name,
version: majorVersion, version: majorVersion,
ios: /(iPad|iPhone|iPod)/g.test(navigator.platform), isIE: isIE,
touch: 'ontouchstart' in document.documentElement isFirefox: isFirefox,
isChrome: isChrome,
isSafari: isSafari,
isIos: /(iPad|iPhone|iPod)/g.test(navigator.platform),
isTouch: 'ontouchstart' in document.documentElement
}; };
} }
@ -323,6 +340,8 @@
else { else {
parent.appendChild(child); parent.appendChild(child);
} }
return child;
} }
} }
@ -404,6 +423,17 @@
return false; return false;
} }
// Element matches selector
function _matches(element, selector) {
var p = Element.prototype;
var f = p.matches || p.webkitMatchesSelector || p.mozMatchesSelector || p.msMatchesSelector || function(s) {
return [].indexOf.call(document.querySelectorAll(s), this) !== -1;
};
return f.call(element, selector);
}
// Bind event // Bind event
function _on(element, events, callback, useCapture) { function _on(element, events, callback, useCapture) {
if (element) { if (element) {
@ -654,9 +684,14 @@
_log(config); _log(config);
// Debugging // Debugging
function _log(text, warn) { function _log() {
if (config.debug && window.console) { if (config.debug && window.console) {
console[(warn ? 'warn' : 'log')](text); console.log.apply(console, arguments);
}
}
function _warn() {
if (config.debug && window.console) {
console.warn.apply(console, arguments);
} }
} }
@ -664,7 +699,7 @@
function _getIconUrl() { function _getIconUrl() {
return { return {
url: config.iconUrl, url: config.iconUrl,
external: (config.iconUrl.indexOf("http") === 0) absolute: (config.iconUrl.indexOf("http") === 0) || plyr.browser.isIE
}; };
} }
@ -673,7 +708,7 @@
// Create html array // Create html array
var html = [], var html = [],
iconUrl = _getIconUrl(), iconUrl = _getIconUrl(),
iconPath = (!iconUrl.external ? iconUrl.url : '') + '#' + config.iconPrefix; iconPath = (!iconUrl.absolute ? iconUrl.url : '') + '#' + config.iconPrefix;
// Larger overlaid play button // Larger overlaid play button
if (_inArray(config.controls, 'play-large')) { if (_inArray(config.controls, 'play-large')) {
@ -909,8 +944,8 @@
// Disable unsupported browsers than report false positive // Disable unsupported browsers than report false positive
// Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1033144 // Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1033144
if ((plyr.browser.name === 'IE' && plyr.browser.version >= 10) || if ((plyr.browser.isIE && plyr.browser.version >= 10) ||
(plyr.browser.name === 'Firefox' && plyr.browser.version >= 31)) { (plyr.browser.isFirefox && plyr.browser.version >= 31)) {
// Debugging // Debugging
_log('Detected browser with known TextTrack issues - using manual fallback'); _log('Detected browser with known TextTrack issues - using manual fallback');
@ -983,7 +1018,7 @@
_log('Successfully loaded the caption file via AJAX'); _log('Successfully loaded the caption file via AJAX');
} }
else { else {
_log('There was a problem loading the caption file via AJAX', true); _warn('There was a problem loading the caption file via AJAX');
} }
} }
}; };
@ -1179,12 +1214,12 @@
var iconUrl = _getIconUrl(); var iconUrl = _getIconUrl();
// Only load external sprite using AJAX // Only load external sprite using AJAX
if (iconUrl.external) { if (iconUrl.absolute) {
_log('Loading external SVG sprite'); _log('AJAX loading absolute SVG sprite' + (plyr.browser.isIE ? ' (due to IE)' : ''));
loadSprite(iconUrl.url); loadSprite(iconUrl.url, "sprite-plyr");
} }
else { else {
_log('Sprite will be used inline'); _log('Sprite will be used as external resource directly');
} }
} }
@ -1285,7 +1320,7 @@
return true; return true;
} }
catch(e) { catch(e) {
_log('It looks like there is a problem with your controls html', true); _warn('It looks like there is a problem with your controls HTML');
// Restore native video controls // Restore native video controls
_toggleNativeControls(true); _toggleNativeControls(true);
@ -1301,7 +1336,7 @@
// Toggle native controls // Toggle native controls
function _toggleNativeControls(toggle) { function _toggleNativeControls(toggle) {
if (toggle) { if (toggle && _inArray(config.types.html5, plyr.type)) {
plyr.media.setAttribute('controls', ''); plyr.media.setAttribute('controls', '');
} }
else { else {
@ -1337,8 +1372,8 @@
function _setupMedia() { function _setupMedia() {
// If there's no media, bail // If there's no media, bail
if (!plyr.media) { if (!plyr.media) {
_log('No audio or video element found', true); _warn('No media element found!');
return false; return;
} }
if (plyr.supported.full) { if (plyr.supported.full) {
@ -1355,10 +1390,10 @@
_toggleClass(plyr.container, config.classes.stopped, config.autoplay); _toggleClass(plyr.container, config.classes.stopped, config.autoplay);
// Add iOS class // Add iOS class
_toggleClass(plyr.container, config.classes.isIos, plyr.browser.ios); _toggleClass(plyr.container, config.classes.isIos, plyr.browser.isIos);
// Add touch class // Add touch class
_toggleClass(plyr.container, config.classes.isTouch, plyr.browser.touch); _toggleClass(plyr.container, config.classes.isTouch, plyr.browser.isTouch);
// Inject the player wrapper // Inject the player wrapper
if (plyr.type === 'video') { if (plyr.type === 'video') {
@ -1439,8 +1474,6 @@
_setAttributes(vimeo, { _setAttributes(vimeo, {
'src': 'https://player.vimeo.com/video/' + mediaId + '?player_id=' + id + '&api=1&badge=0&byline=0&portrait=0&title=0', 'src': 'https://player.vimeo.com/video/' + mediaId + '?player_id=' + id + '&api=1&badge=0&byline=0&portrait=0&title=0',
'id': id, 'id': id,
'webkitallowfullscreen': '',
'mozallowfullscreen': '',
'allowfullscreen': '', 'allowfullscreen': '',
'frameborder': 0 'frameborder': 0
}); });
@ -1504,8 +1537,10 @@
// Store reference to API // Store reference to API
plyr.container.plyr.embed = plyr.embed; plyr.container.plyr.embed = plyr.embed;
// Setup the UI // Setup the UI if full support
_setupInterface(); if (plyr.supported.full) {
_setupInterface();
}
// Set title // Set title
_setTitle(_getElement('iframe')); _setTitle(_getElement('iframe'));
@ -1870,7 +1905,7 @@
targetTime = input; targetTime = input;
} }
// Event // Event
else if (typeof input === 'object' && (input.type === 'input' || input.type === 'change')) { else if (input.type && _inArray(['input', 'change'], input.type)) {
// It's the seek slider // It's the seek slider
// Seek to the selected time // Seek to the selected time
targetTime = ((input.target.value / input.target.max) * duration); targetTime = ((input.target.value / input.target.max) * duration);
@ -2028,7 +2063,7 @@
_toggleState(plyr.buttons.fullscreen, plyr.isFullscreen); _toggleState(plyr.buttons.fullscreen, plyr.isFullscreen);
// Trigger an event // Trigger an event
_triggerEvent(plyr.container, plyr.isFullscreen ? 'enterfullscreen' : 'exitfullscreen'); _triggerEvent(plyr.container, plyr.isFullscreen ? 'enterfullscreen' : 'exitfullscreen', true);
// Restore scroll position // Restore scroll position
if (!plyr.isFullscreen && nativeSupport) { if (!plyr.isFullscreen && nativeSupport) {
@ -2216,7 +2251,7 @@
_toggleClass(plyr.container, config.classes.captions.active, plyr.captionsEnabled); _toggleClass(plyr.container, config.classes.captions.active, plyr.captionsEnabled);
// Trigger an event // Trigger an event
_triggerEvent(plyr.container, plyr.captionsEnabled ? 'captionsenabled' : 'captionsdisabled'); _triggerEvent(plyr.container, plyr.captionsEnabled ? 'captionsenabled' : 'captionsdisabled', true);
} }
// Check if media is loading // Check if media is loading
@ -2247,6 +2282,10 @@
// Video playing // Video playing
case 'timeupdate': case 'timeupdate':
case 'seeking': case 'seeking':
if (plyr.controls.pressed) {
return;
}
value = _getPercentage(plyr.media.currentTime, duration); value = _getPercentage(plyr.media.currentTime, duration);
// Set seek range value only if it's a 'natural' time event // Set seek range value only if it's a 'natural' time event
@ -2456,21 +2495,22 @@
if (!config.hideControls || plyr.type === 'audio') { if (!config.hideControls || plyr.type === 'audio') {
return; return;
} }
var delay = 0, var delay = 0,
isEnterFullscreen = false, isEnterFullscreen = false,
show = toggle; show = toggle;
// Default to false if no boolean // Default to false if no boolean
if (typeof toggle !== "boolean") { if (typeof toggle !== 'boolean') {
if (toggle && toggle.type) { if (toggle && toggle.type) {
// Is the enter fullscreen event // Is the enter fullscreen event
isEnterFullscreen = (toggle.type === 'enterfullscreen'); isEnterFullscreen = (toggle.type === 'enterfullscreen');
// Whether to show controls // Whether to show controls
show = _inArray(['mousemove', 'mouseenter', 'focus'], toggle.type); show = _inArray(['mousemove', 'touchstart', 'mouseenter', 'focus'], toggle.type);
// Delay hiding on mousemove events // Delay hiding on move events
if (toggle.type === 'mousemove') { if (_inArray(['mousemove', 'touchmove'], toggle.type)) {
delay = 2000; delay = 2000;
} }
@ -2480,7 +2520,7 @@
} }
} }
else { else {
show = !_hasClass(plyr.container, config.classes.hideControls); show = _hasClass(plyr.container, config.classes.hideControls);
} }
} }
@ -2497,7 +2537,7 @@
} }
// Delay for hiding on touch // Delay for hiding on touch
if (plyr.browser.touch) { if (plyr.browser.isTouch) {
delay = 3000; delay = 3000;
} }
} }
@ -2507,7 +2547,7 @@
if (!show || !plyr.media.paused) { if (!show || !plyr.media.paused) {
plyr.timers.hover = window.setTimeout(function() { plyr.timers.hover = window.setTimeout(function() {
// If the mouse is over the controls (and not entering fullscreen), bail // If the mouse is over the controls (and not entering fullscreen), bail
if (plyr.controls.active && !isEnterFullscreen) { if ((plyr.controls.pressed || plyr.controls.hover) && !isEnterFullscreen) {
return; return;
} }
@ -2555,7 +2595,7 @@
// Sources are not checked for support so be careful // Sources are not checked for support so be careful
function _updateSource(source) { function _updateSource(source) {
if (typeof source === 'undefined' || !('sources' in source) || !source.sources.length) { if (typeof source === 'undefined' || !('sources' in source) || !source.sources.length) {
_log('Invalid source format', true); _warn('Invalid source format');
return; return;
} }
@ -2683,6 +2723,10 @@
// Display duration if available // Display duration if available
_displayDuration(); _displayDuration();
} }
// If embed but not fully supported, setupInterface now
else if (_inArray(config.types.embed, plyr.type) && !plyr.supported.full) {
_setupInterface();
}
// Set aria title and iframe title // Set aria title and iframe title
config.title = source.title; config.title = source.title;
@ -2702,7 +2746,7 @@
// Listen for control events // Listen for control events
function _controlListeners() { function _controlListeners() {
// IE doesn't support input event, so we fallback to change // IE doesn't support input event, so we fallback to change
var inputEvent = (plyr.browser.name == 'IE' ? 'change' : 'input'); var inputEvent = (plyr.browser.isIE ? 'change' : 'input');
// Click play/pause helper // Click play/pause helper
function _togglePlay() { function _togglePlay() {
@ -2828,11 +2872,16 @@
// Toggle controls visibility based on mouse movement // Toggle controls visibility based on mouse movement
if (config.hideControls) { if (config.hideControls) {
// Toggle controls on mouse events and entering fullscreen // Toggle controls on mouse events and entering fullscreen
_on(plyr.container, 'mouseenter mouseleave mousemove enterfullscreen', _toggleControls); _on(plyr.container, 'mouseenter mouseleave mousemove touchstart touchend touchcancel touchmove enterfullscreen', _toggleControls);
// Watch for cursor over controls so they don't hide when trying to interact // Watch for cursor over controls so they don't hide when trying to interact
_on(plyr.controls, 'mouseenter mouseleave', function(event) { _on(plyr.controls, 'mouseenter mouseleave', function(event) {
plyr.controls.active = (event.type === 'mouseenter'); plyr.controls.hover = event.type === 'mouseenter';
});
// Watch for cursor over controls so they don't hide when trying to interact
_on(plyr.controls, 'mousedown mouseup touchstart touchend touchcancel', function(event) {
plyr.controls.pressed = _inArray(['mousedown', 'touchstart'], event.type);
}); });
// Focus in/out on controls // Focus in/out on controls
@ -2843,14 +2892,28 @@
_on(plyr.volume.input, 'wheel', function(event) { _on(plyr.volume.input, 'wheel', function(event) {
event.preventDefault(); event.preventDefault();
// Scroll down to decrease // Detect "natural" scroll - suppored on OS X Safari only
// Other browsers on OS X will be inverted until support improves
var inverted = event.webkitDirectionInvertedFromDevice;
// Scroll down (or up on natural) to decrease
if (event.deltaY < 0 || event.deltaX > 0) { if (event.deltaY < 0 || event.deltaX > 0) {
_decreaseVolume(); if (inverted) {
_decreaseVolume();
}
else {
_increaseVolume();
}
} }
// Scroll up to increase // Scroll up (or down on natural) to increase
if (event.deltaY > 0 || event.deltaX < 0) { if (event.deltaY > 0 || event.deltaX < 0) {
_increaseVolume(); if (inverted) {
_increaseVolume();
}
else {
_decreaseVolume();
}
} }
}); });
} }
@ -2916,8 +2979,8 @@
// On click play, pause ore restart // On click play, pause ore restart
_on(wrapper, 'click', function() { _on(wrapper, 'click', function() {
if (plyr.browser.touch && !plyr.media.paused) { // Touch devices will just show controls (if we're hiding controls)
_toggleControls(true); if (config.hideControls && plyr.browser.isTouch && !plyr.media.paused) {
return; return;
} }
@ -3033,7 +3096,7 @@
// Get the div placeholder for YouTube and Vimeo // Get the div placeholder for YouTube and Vimeo
if (!plyr.media) { if (!plyr.media) {
plyr.media = plyr.container.querySelectorAll('div')[0]; plyr.media = plyr.container.querySelectorAll('[data-type]')[0];
} }
// Bail if nothing to setup // Bail if nothing to setup
@ -3101,6 +3164,10 @@
_play(); _play();
} }
} }
// If embed but not fully supported, setupInterface now (to avoid flash of controls)
else if (_inArray(config.types.embed, plyr.type) && !plyr.supported.full) {
_setupInterface();
}
// Successful setup // Successful setup
plyr.init = true; plyr.init = true;
@ -3109,7 +3176,7 @@
function _setupInterface() { function _setupInterface() {
// Don't setup interface if no support // Don't setup interface if no support
if (!plyr.supported.full) { if (!plyr.supported.full) {
_log('No full support for this media type (' + plyr.type + ')', true); _warn('No full support for this media type (' + plyr.type + ')');
// Remove controls // Remove controls
_remove(_getElement(config.selectors.controls.wrapper)); _remove(_getElement(config.selectors.controls.wrapper));
@ -3167,7 +3234,7 @@
_displayDuration(); _displayDuration();
// Ready event // Ready event
_triggerEvent(plyr.container, 'ready'); _triggerEvent(plyr.container, 'ready', true);
} }
// Initialize instance // Initialize instance
@ -3197,14 +3264,20 @@
isFullscreen: function() { return plyr.isFullscreen || false; }, isFullscreen: function() { return plyr.isFullscreen || false; },
support: function(mimeType) { return _supportMime(plyr, mimeType); }, support: function(mimeType) { return _supportMime(plyr, mimeType); },
destroy: _destroy, destroy: _destroy,
restore: _init restore: _init,
getCurrentTime: function() { return plyr.media.currentTime; }
}; };
} }
// Load a sprite // Load a sprite
function loadSprite(url) { function loadSprite(url, id) {
var x = new XMLHttpRequest(); var x = new XMLHttpRequest();
// If the id is set and sprite exists, bail
if (typeof id === 'string' && document.querySelector('#' + id) !== null) {
return;
}
// Check for CORS support // Check for CORS support
if ('withCredentials' in x) { if ('withCredentials' in x) {
x.open('GET', url, true); x.open('GET', url, true);
@ -3217,6 +3290,9 @@
x.onload = function() { x.onload = function() {
var c = document.createElement('div'); var c = document.createElement('div');
c.setAttribute('hidden', ''); c.setAttribute('hidden', '');
if (typeof id === 'string') {
c.setAttribute('id', id);
}
c.innerHTML = x.responseText; c.innerHTML = x.responseText;
document.body.insertBefore(c, document.body.childNodes[0]); document.body.insertBefore(c, document.body.childNodes[0]);
} }
@ -3226,34 +3302,35 @@
// Check for support // Check for support
function supported(type) { function supported(type) {
var browser = _browserSniff(), var browser = _browserSniff(),
oldIE = (browser.name === 'IE' && browser.version <= 9), isOldIE = (browser.isIE && browser.version <= 9),
iPhone = /iPhone|iPod/i.test(navigator.userAgent), isIos = browser.isIos,
audio = !!document.createElement('audio').canPlayType, isIphone = /iPhone|iPod/i.test(navigator.userAgent),
video = !!document.createElement('video').canPlayType, audio = !!document.createElement('audio').canPlayType,
video = !!document.createElement('video').canPlayType,
basic, full; basic, full;
switch (type) { switch (type) {
case 'video': case 'video':
basic = video; basic = video;
full = (basic && (!oldIE && !iPhone)); full = (basic && (!isOldIE && !isIphone));
break; break;
case 'audio': case 'audio':
basic = audio; basic = audio;
full = (basic && !oldIE); full = (basic && !isOldIE);
break; break;
case 'vimeo': case 'vimeo':
case 'youtube': case 'youtube':
case 'soundcloud': case 'soundcloud':
basic = true; basic = true;
full = (!oldIE && !iPhone); full = (!isOldIE && !isIos);
break; break;
default: default:
basic = (audio && video); basic = (audio && video);
full = (basic && !oldIE); full = (basic && !isOldIE);
} }
return { return {
@ -3263,49 +3340,86 @@
} }
// Setup function // Setup function
function setup(elements, options) { function setup(targets, options) {
// Get the players // Get the players
var instances = []; var elements = [],
containers = [],
selector = [defaults.selectors.html5, defaults.selectors.embed].join(',');
// Select the elements // Select the elements
// Assume elements is a NodeList by default // Assume elements is a NodeList by default
if (typeof elements === 'string') { if (typeof targets === 'string') {
elements = document.querySelectorAll(elements); targets = document.querySelectorAll(targets);
} }
// Single HTMLElement passed // Single HTMLElement passed
else if (elements instanceof HTMLElement) { else if (targets instanceof HTMLElement) {
elements = [elements]; targets = [targets];
} }
// No selector passed, possibly options as first argument // No selector passed, possibly options as first argument
else if (!(elements instanceof NodeList) && typeof elements !== 'string') { else if (!(targets instanceof NodeList) && typeof targets !== 'string') {
// If options are the first argument // If options are the first argument
if (typeof options === 'undefined' && typeof elements === 'object') { if (typeof options === 'undefined' && typeof targets === 'object') {
options = elements; options = targets;
} }
// Use default selector // Use default selector
elements = document.querySelectorAll(defaults.selectors.container); targets = document.querySelectorAll(selector);
} }
// Bail if disabled or no basic support // Bail if disabled or no basic support
// You may want to disable certain UAs etc // You may want to disable certain UAs etc
if (!supported().basic || !elements.length) { if (!supported().basic || !targets.length) {
return false; return false;
} }
// Convert NodeList to array
if (targets instanceof NodeList) {
targets = Array.prototype.slice.call(targets);
}
// Check if the targets have multiple media elements
for (var i = 0; i < targets.length; i++) {
var target = targets[i];
// Get children
var children = target.querySelectorAll(selector);
// If there's more than one media element, wrap them
if (children.length > 1) {
for (var x = 0; x < children.length; x++) {
containers.push({
element: _wrap(children[x], document.createElement('div')),
original: target
});
}
}
else {
containers.push({
element: target
});
}
}
// Create a player instance for each element // Create a player instance for each element
for (var i = 0; i < elements.length; i++) { for (var key in containers) {
// Get the current element var element = containers[key].element,
var element = elements[i]; original = containers[key].original || element;
// Wrap each media element if is target is media element
// as opposed to a wrapper
if (_matches(element, selector)) {
// Wrap in a <div>
element = _wrap(element, document.createElement('div'));
}
// Setup a player instance and add to the element // Setup a player instance and add to the element
if (typeof element.plyr === 'undefined') { if (!('plyr' in element)) {
// Create instance-specific config // Create instance-specific config
var config = _extend(defaults, options, JSON.parse(element.getAttribute("data-plyr"))); var config = _extend({}, defaults, options, JSON.parse(original.getAttribute('data-plyr')));
// Bail if not enabled // Bail if not enabled
if (!config.enabled) { if (!config.enabled) {
return; return null;
} }
// Create new instance // Create new instance
@ -3315,14 +3429,16 @@
element.plyr = (Object.keys(instance).length ? instance : false); element.plyr = (Object.keys(instance).length ? instance : false);
// Callback // Callback
_triggerEvent(element, 'setup', { plyr: element.plyr }); _triggerEvent(original, 'setup', true, {
plyr: element.plyr
});
} }
// Add to return array even if it's already setup // Add to return array even if it's already setup
instances.push(element.plyr); elements.push(element);
} }
return instances; return elements;
} }
return { return {
@ -3339,7 +3455,7 @@
return false; return false;
} }
function CustomEvent (event, params) { function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined }; params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent('CustomEvent'); var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);

View File

@ -19,7 +19,7 @@
position: relative; position: relative;
max-width: 100%; max-width: 100%;
min-width: 200px; min-width: 200px;
font-family: Avenir, "Avenir Next", "Helvetica Neue", "Segoe UI", Helvetica, Arial, sans-serif; font-family: @plyr-font-family;
direction: ltr; direction: ltr;
& when (@plyr-border-box = true) { & when (@plyr-border-box = true) {
@ -178,7 +178,6 @@
padding-bottom: 56.25%; /* 16:9 */ padding-bottom: 56.25%; /* 16:9 */
height: 0; height: 0;
overflow: hidden; overflow: hidden;
border-radius: inherit;
iframe { iframe {
position: absolute; position: absolute;
@ -256,12 +255,9 @@
.plyr__controls { .plyr__controls {
display: flex; display: flex;
align-items: center; align-items: center;
line-height: 1; line-height: 1;
text-align: center; text-align: center;
transition: opacity .3s ease;
// Spacing // Spacing
> button, > button,
.plyr__progress, .plyr__progress,
@ -325,6 +321,7 @@
// Hide controls // Hide controls
.plyr--hide-controls .plyr__controls { .plyr--hide-controls .plyr__controls {
opacity: 0; opacity: 0;
pointer-events: none;
} }
// Video controls // Video controls
@ -338,6 +335,7 @@
border-bottom-left-radius: inherit; border-bottom-left-radius: inherit;
border-bottom-right-radius: inherit; border-bottom-right-radius: inherit;
color: @plyr-video-control-color; color: @plyr-video-control-color;
transition: opacity .3s ease;
button { button {
// Hover and tab focus // Hover and tab focus
@ -355,7 +353,6 @@
border-radius: inherit; border-radius: inherit;
background: @plyr-audio-controls-bg; background: @plyr-audio-controls-bg;
border: @plyr-audio-controls-border; border: @plyr-audio-controls-border;
box-shadow: @plyr-audio-controls-box-shadow;
color: @plyr-audio-control-color; color: @plyr-audio-control-color;
button { button {
@ -372,6 +369,7 @@
.plyr__play-large { .plyr__play-large {
display: none; display: none;
position: absolute; position: absolute;
z-index: 1;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
@ -379,7 +377,7 @@
background: @plyr-video-control-bg-hover; background: @plyr-video-control-bg-hover;
border: 4px solid currentColor; border: 4px solid currentColor;
border-radius: 100%; border-radius: 100%;
box-shadow: 0 1px 1px fade(@plyr-video-controls-bg, 15%); box-shadow: 0 1px 1px fade(#000, 15%);
color: @plyr-video-control-color; color: @plyr-video-control-color;
transition: all .3s ease; transition: all .3s ease;
@ -664,7 +662,6 @@
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
font-size: @plyr-font-size-small; font-size: @plyr-font-size-small;
line-height: .95;
} }
// Media duration hidden on small screens // Media duration hidden on small screens
.plyr__time + .plyr__time { .plyr__time + .plyr__time {

View File

@ -11,7 +11,8 @@
// Colors // Colors
@plyr-color-main: #3498db; @plyr-color-main: #3498db;
// Font sizes // Font
@plyr-font-family: 'San Francisco', -apple-system, BlinkMacSystemFont, '.SFNSText-Regular', Avenir, 'Avenir Next', 'Helvetica Neue', 'Segoe UI', Helvetica, Arial, sans-serif;
@plyr-font-size-small: 14px; @plyr-font-size-small: 14px;
@plyr-font-size-base: 16px; @plyr-font-size-base: 16px;
@ -32,7 +33,6 @@
@plyr-video-control-bg-hover: @plyr-color-main; @plyr-video-control-bg-hover: @plyr-color-main;
@plyr-audio-controls-bg: #fff; @plyr-audio-controls-bg: #fff;
@plyr-audio-controls-border: 1px solid #dbe3e8; @plyr-audio-controls-border: 1px solid #dbe3e8;
@plyr-audio-controls-box-shadow: 0 1px 1px fade(#000, 5%);
@plyr-audio-control-color: #565D64; @plyr-audio-control-color: #565D64;
@plyr-audio-control-color-hover: #fff; @plyr-audio-control-color-hover: #fff;
@plyr-audio-control-bg-hover: @plyr-color-main; @plyr-audio-control-bg-hover: @plyr-color-main;

View File

@ -19,7 +19,7 @@
position: relative; position: relative;
max-width: 100%; max-width: 100%;
min-width: 200px; min-width: 200px;
font-family: Avenir, "Avenir Next", "Helvetica Neue", "Segoe UI", Helvetica, Arial, sans-serif; font-family: $plyr-font-family;
direction: ltr; direction: ltr;
@if $plyr-border-box == true { @if $plyr-border-box == true {
@ -255,12 +255,9 @@
.plyr__controls { .plyr__controls {
display: flex; display: flex;
align-items: center; align-items: center;
line-height: 1; line-height: 1;
text-align: center; text-align: center;
transition: opacity .3s ease;
// Spacing // Spacing
> button, > button,
.plyr__progress, .plyr__progress,
@ -294,8 +291,8 @@
color: inherit; color: inherit;
svg { svg {
width: 18px; width: $plyr-control-icon-size;
height: 18px; height: $plyr-control-icon-size;
display: block; display: block;
fill: currentColor; fill: currentColor;
} }
@ -324,6 +321,7 @@
// Hide controls // Hide controls
.plyr--hide-controls .plyr__controls { .plyr--hide-controls .plyr__controls {
opacity: 0; opacity: 0;
pointer-events: none;
} }
// Video controls // Video controls
@ -337,6 +335,7 @@
border-bottom-left-radius: inherit; border-bottom-left-radius: inherit;
border-bottom-right-radius: inherit; border-bottom-right-radius: inherit;
color: $plyr-video-control-color; color: $plyr-video-control-color;
transition: opacity .3s ease;
button { button {
// Hover and tab focus // Hover and tab focus
@ -354,7 +353,6 @@
border-radius: inherit; border-radius: inherit;
background: $plyr-audio-controls-bg; background: $plyr-audio-controls-bg;
border: $plyr-audio-controls-border; border: $plyr-audio-controls-border;
box-shadow: $plyr-audio-controls-box-shadow;
color: $plyr-audio-control-color; color: $plyr-audio-control-color;
button { button {
@ -371,6 +369,7 @@
.plyr__play-large { .plyr__play-large {
display: none; display: none;
position: absolute; position: absolute;
z-index: 1;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
@ -378,7 +377,7 @@
background: $plyr-video-control-bg-hover; background: $plyr-video-control-bg-hover;
border: 4px solid currentColor; border: 4px solid currentColor;
border-radius: 100%; border-radius: 100%;
box-shadow: 0 1px 1px transparentize($plyr-video-controls-bg, .85); box-shadow: 0 1px 1px transparentize(#000, .85);
color: $plyr-video-control-color; color: $plyr-video-control-color;
transition: all .3s ease; transition: all .3s ease;
@ -487,7 +486,6 @@
// First tooltip // First tooltip
.plyr__controls button:first-child .plyr__tooltip { .plyr__controls button:first-child .plyr__tooltip {
$tooltip-arrow-offset: ;
left: 0; left: 0;
transform: translate(0, 10px) scale(.8); transform: translate(0, 10px) scale(.8);
transform-origin: 0 100%; transform-origin: 0 100%;
@ -663,7 +661,6 @@
display: inline-block; display: inline-block;
vertical-align: middle; vertical-align: middle;
font-size: $plyr-font-size-small; font-size: $plyr-font-size-small;
line-height: .95;
} }
// Media duration hidden on small screens // Media duration hidden on small screens
.plyr__time + .plyr__time { .plyr__time + .plyr__time {

View File

@ -13,6 +13,7 @@ $plyr-sr-only-important: true !default;
$plyr-color-main: #3498db !default; $plyr-color-main: #3498db !default;
// Font sizes // Font sizes
$plyr-font-family: 'San Francisco', -apple-system, BlinkMacSystemFont, '.SFNSText-Regular', Avenir, 'Avenir Next', 'Helvetica Neue', 'Segoe UI', Helvetica, Arial, sans-serif;
$plyr-font-size-small: 14px !default; $plyr-font-size-small: 14px !default;
$plyr-font-size-base: 16px !default; $plyr-font-size-base: 16px !default;
@ -33,7 +34,6 @@ $plyr-video-control-color-hover: #fff !default;
$plyr-video-control-bg-hover: $plyr-color-main !default; $plyr-video-control-bg-hover: $plyr-color-main !default;
$plyr-audio-controls-bg: #fff !default; $plyr-audio-controls-bg: #fff !default;
$plyr-audio-controls-border: 1px solid #dbe3e8 !default; $plyr-audio-controls-border: 1px solid #dbe3e8 !default;
$plyr-audio-controls-box-shadow: 0 1px 1px transparentize(#000, .95) !default;
$plyr-audio-control-color: #565D64 !default; $plyr-audio-control-color: #565D64 !default;
$plyr-audio-control-color-hover: #fff !default; $plyr-audio-control-color-hover: #fff !default;
$plyr-audio-control-bg-hover: $plyr-color-main; $plyr-audio-control-bg-hover: $plyr-color-main;