Single instance only

This commit is contained in:
Sam Potts 2017-05-16 09:58:53 +10:00
parent fe9383bed5
commit 966c3d875d
9 changed files with 597 additions and 600 deletions

View File

@ -17,6 +17,7 @@
"js": { "js": {
"demo.js": [ "demo.js": [
"demo/src/js/lib/classlist.js", "demo/src/js/lib/classlist.js",
"demo/src/js/lib/sprite.js",
"demo/src/js/main.js" "demo/src/js/main.js"
] ]
} }

2
demo/dist/demo.js vendored

File diff suppressed because one or more lines are too long

View File

@ -51,7 +51,7 @@
</ul> </ul>
</nav> </nav>
<section> <section>
<video poster="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg" controls crossorigin playsinline> <video controls crossorigin playsinline poster="https://cdn.selz.com/plyr/1.5/View_From_A_Blue_Moon_Trailer-HD.jpg" id="player">
<!-- 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">

89
demo/src/js/lib/sprite.js Normal file
View File

@ -0,0 +1,89 @@
// ==========================================================================
// SVG sprite loading and caching
// This file should be at the top of the body to avoid a flash
// Usage: loadSprite('https://cdn.com/path/to/sprite.svg', 'sprite-id');
// The second argument is optional but prevents loading twice
// ==========================================================================
(function() {
window.loadSprite = function(url, id) {
if (typeof url !== "string") {
return;
}
var body = document.body;
var prefix = "cache-";
var hasId = typeof id === "string";
var isCached = false;
// Check for *actual* storage support
var cacheSupported = (function() {
if (!hasId) {
return false;
}
var test = '___test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
return true;
} catch (e) {
return false;
}
})();
function updateSprite(container, data) {
// Inject content
container.innerHTML = data;
// Inject the SVG to the body
body.insertBefore(container, body.childNodes[0]);
}
// Only load once
if (!hasId || document.querySelectorAll("#" + id).length === 0) {
// Create container
var container = document.createElement("div");
container.setAttribute("hidden", "");
if (hasId) {
container.setAttribute("id", id);
}
// Check in cache
if (cacheSupported) {
var cached = localStorage.getItem(prefix + id);
isCached = cached !== null;
if (isCached) {
var data = JSON.parse(cached);
updateSprite(container, data.content);
}
}
// ReSharper disable once InconsistentNaming
var xhr = new XMLHttpRequest();
// XHR for Chrome/Firefox/Opera/Safari
if ("withCredentials" in xhr) {
xhr.open("GET", url, true);
}
// Not supported
else {
return;
}
// Once loaded, inject to container and body
xhr.onload = function() {
if (cacheSupported) {
localStorage.setItem(prefix + id, JSON.stringify({
content: xhr.responseText
}));
}
updateSprite(container, xhr.responseText);
};
xhr.send();
}
}
})();

View File

@ -4,16 +4,18 @@
// Please see readme.md in the root or github.com/selz/plyr // Please see readme.md in the root or github.com/selz/plyr
// ========================================================================== // ==========================================================================
/*global plyr*/ /*global Plyr*/
// General functions // General functions
(function() { (function() {
//document.body.addEventListener('ready', function(event) { console.log(event); }); document.body.addEventListener('ready', function(event) {
console.log(event);
});
// Setup the player // Setup the player
var instances = plyr.setup({ var player = new Plyr('#player', {
debug: true, debug: true,
title: 'Video demo', title: 'View From A Blue Moon',
iconUrl: '../dist/plyr.svg', iconUrl: '../dist/plyr.svg',
tooltips: { tooltips: {
controls: true controls: true
@ -35,25 +37,22 @@
'airplay' 'airplay'
] ]
}); });
plyr.loadSprite('dist/demo.svg'); window.loadSprite('dist/demo.svg', 'demo-sprite');
// Plyr returns an array regardless
var player = instances[0];
// Setup type toggle // Setup type toggle
var buttons = document.querySelectorAll('[data-source]'), var buttons = document.querySelectorAll('[data-source]');
types = { var types = {
video: 'video', video: 'video',
audio: 'audio', audio: 'audio',
youtube: 'youtube', youtube: 'youtube',
vimeo: 'vimeo' vimeo: 'vimeo'
}, };
currentType = window.location.hash.replace('#', ''), var currentType = window.location.hash.replace('#', '');
historySupport = (window.history && window.history.pushState); var historySupport = (window.history && window.history.pushState);
// Bind to each button // Bind to each button
for (var i = buttons.length - 1; i >= 0; i--) { [].forEach.call(buttons, function(button) {
buttons[i].addEventListener('click', function() { button.addEventListener('click', function() {
var type = this.getAttribute('data-source'); var type = this.getAttribute('data-source');
newSource(type); newSource(type);
@ -64,7 +63,7 @@
}, '', '#' + type); }, '', '#' + type);
} }
}); });
} });
// List for backwards/forwards // List for backwards/forwards
window.addEventListener('popstate', function(event) { window.addEventListener('popstate', function(event) {
@ -199,6 +198,6 @@ if (document.domain.indexOf('plyr.io') > -1) {
a.src = g; a.src = g;
m.parentNode.insertBefore(a, m) m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-40881672-11', 'auto'); window.ga('create', 'UA-40881672-11', 'auto');
ga('send', 'pageview'); window.ga('send', 'pageview');
} }

4
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,21 +1,26 @@
### Todo ### Todo
#### To build #### To build
[x] Get list of subtitles/captions available (HTML5) [x] Get list of subtitles/captions available (HTML5, Vimeo)
[x] Add preferred quality option into config [x] Add preferred quality option into config
[ ] Update quality options on YouTube play (can't get up front?!) [ ] Update quality options on YouTube play (can't get up front?!)
[ ] Update speed options on YouTube load [ ] Update speed options on YouTube load
[ ] Get quality options for HTML5 somehow (multi source?) [ ] Finish and test PiP (need MacOS Sierra)
[ ] Finish and test PiP (need Sierra VM) [ ] Finish and test AirPlay (need MacOS Sierra)
[ ] Finish and test AirPlay (need Sierra VM)
[ ] Download button - grab first <source> or src attribute (or maybe use currentSrc?) for HTML5 and links for embedded players
[ ] Controls hide/show events [ ] Controls hide/show events
[ ] Test custom controls still works [ ] Test custom controls still works
[ ] Tidy up small UI for iOS inline
[ ] Finish new loop setup and UI
[ ] Toggle settings menu
#### Later
[ ] Get quality options for HTML5 somehow (multi source?)
[ ] Download button - grab first <source> or src attribute (or maybe use currentSrc?) for HTML5 and links for embedded players
#### Bugs #### Bugs
[ ] Fix audio setup bug when calling `.setup()` again [ ] Fix audio setup bug when calling `.setup()` again
[ ] Fix events on unsupported devices (iOS, old IE) [ ] Fix events on unsupported devices (iOS, old IE)
[ ] Fix YouTube rights blocking (origin perhaps?) [x] Fix YouTube rights blocking (origin perhaps?)
# Notes # Notes
- No quality HTML5 support (yet) - No quality HTML5 support (yet)
@ -25,11 +30,13 @@
- No PiP or AirPlay for Vimeo/YouTube - No PiP or AirPlay for Vimeo/YouTube
- Settings won't be supported for custom controls (coming soon, need to work on templating) - Settings won't be supported for custom controls (coming soon, need to work on templating)
- Added `playsinline` support for iOS 10 - Added `playsinline` support for iOS 10
- Embed setup now accepts an <iframe> as the target element for true progressive enhancement
#### Breaking changes #### Breaking changes
- New config options for loop - New config options for loop
- Selectors changes (new `input` and `display` object) - DOCUMENT - Selectors changes (new `input` and `display` object) - DOCUMENT
- Custom HTML option now `controls` which accepts a string (HTML), a function (your own template engine) or array (use built in controls) - Custom HTML option now `controls` which accepts a string (HTML), a function (your own template engine) or array (use built in controls)
- .setup() is removed in favour of a constructor
## Added ## Added
- Seek i8n label - Seek i8n label

View File

@ -783,15 +783,10 @@ These events also bubble up the DOM. The event target will be the container elem
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr>
<td><code>setup</code></td>
<td></td>
<td>When an initial setup has completed</td>
</tr>
<tr> <tr>
<td><code>ready</code></td> <td><code>ready</code></td>
<td></td> <td></td>
<td>Triggered when the instance is ready for API use and external APIs are ready (in the case of YouTube and Vimeo).</td> <td>Triggered when the instance is ready for API calls.</td>
</tr> </tr>
<tr> <tr>
<td><code>canplay</code></td> <td><code>canplay</code></td>
@ -1057,9 +1052,6 @@ If a User Agent is disabled but supports `<video>` and `<audio>` natively, it wi
Any unsupported browsers will display links to download the media if the correct html is used. Any unsupported browsers will display links to download the media if the correct html is used.
### Checking for support
There's an API method for checking support. You can call `plyr.supported()` and optionally pass a type to it, e.g. `plyr.supported("video")`. It will return an object with two keys; `basic` meaning there's basic support for that media type (or both if no type is passed) and `full` meaning there's full support for plyr.
## Issues ## Issues
If you find anything weird with Plyr, please let us know using the GitHub issues tracker. If you find anything weird with Plyr, please let us know using the GitHub issues tracker.

File diff suppressed because it is too large Load Diff