aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/support.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-06-18 21:41:25 +1000
committerSam Potts <sam@potts.es>2018-06-18 21:41:25 +1000
commitcc3c0b54484e6f5a7b4dba8a36a44f345e462f26 (patch)
tree5fe2838546d9f981b21572dee88ee7a1c3195477 /src/js/support.js
parent4811e3333f1417bc9e14f6cc38afc789e9051c4c (diff)
parent3c9c1b4cdcd0eb9076c3f0bafbabb057ee140c42 (diff)
downloadplyr-cc3c0b54484e6f5a7b4dba8a36a44f345e462f26.tar.lz
plyr-cc3c0b54484e6f5a7b4dba8a36a44f345e462f26.tar.xz
plyr-cc3c0b54484e6f5a7b4dba8a36a44f345e462f26.zip
Merge branch 'develop'
Diffstat (limited to 'src/js/support.js')
-rw-r--r--src/js/support.js137
1 files changed, 37 insertions, 100 deletions
diff --git a/src/js/support.js b/src/js/support.js
index 38212d9f..6395293f 100644
--- a/src/js/support.js
+++ b/src/js/support.js
@@ -2,7 +2,19 @@
// Plyr support checks
// ==========================================================================
-import utils from './utils';
+import { transitionEndEvent } from './utils/animation';
+import browser from './utils/browser';
+import { createElement } from './utils/elements';
+import is from './utils/is';
+
+// Default codecs for checking mimetype support
+const defaultCodecs = {
+ 'audio/ogg': 'vorbis',
+ 'audio/wav': '1',
+ 'video/webm': 'vp8, vorbis',
+ 'video/mp4': 'avc1.42E01E, mp4a.40.2',
+ 'video/ogg': 'theora',
+};
// Check for feature support
const support = {
@@ -13,32 +25,9 @@ const support = {
// Check for support
// Basic functionality vs full UI
check(type, provider, playsinline) {
- let api = false;
- let ui = false;
- const browser = utils.getBrowser();
const canPlayInline = browser.isIPhone && playsinline && support.playsinline;
-
- switch (`${provider}:${type}`) {
- case 'html5:video':
- api = support.video;
- ui = api && support.rangeInput && (!browser.isIPhone || canPlayInline);
- break;
-
- case 'html5:audio':
- api = support.audio;
- ui = api && support.rangeInput;
- break;
-
- case 'youtube:video':
- case 'vimeo:video':
- api = true;
- ui = support.rangeInput && (!browser.isIPhone || canPlayInline);
- break;
-
- default:
- api = support.audio && support.video;
- ui = api && support.rangeInput;
- }
+ const api = support[type] || provider !== 'html5';
+ const ui = api && support.rangeInput && (type !== 'video' || !browser.isIPhone || canPlayInline);
return {
api,
@@ -48,14 +37,11 @@ const support = {
// Picture-in-picture support
// Safari only currently
- pip: (() => {
- const browser = utils.getBrowser();
- return !browser.isIPhone && utils.is.function(utils.createElement('video').webkitSetPresentationMode);
- })(),
+ pip: (() => !browser.isIPhone && is.function(createElement('video').webkitSetPresentationMode))(),
// Airplay support
// Safari only currently
- airplay: utils.is.function(window.WebKitPlaybackTargetAvailabilityEvent),
+ airplay: is.function(window.WebKitPlaybackTargetAvailabilityEvent),
// Inline playback support
// https://webkit.org/blog/6784/new-video-policies-for-ios/
@@ -64,83 +50,34 @@ const support = {
// Check for mime type support against a player instance
// Credits: http://diveintohtml5.info/everything.html
// Related: http://www.leanbackplayer.com/test/h5mt.html
- mime(type) {
- const { media } = this;
+ mime(inputType) {
+ const [mediaType] = inputType.split('/');
+ if (!this.isHTML5 || mediaType !== this.type) {
+ return false;
+ }
+
+ let type;
+ if (inputType && inputType.includes('codecs=')) {
+ // Use input directly
+ type = inputType;
+ } else if (inputType === 'audio/mpeg') {
+ // Skip codec
+ type = 'audio/mpeg;';
+ } else if (inputType in defaultCodecs) {
+ // Use codec
+ type = `${inputType}; codecs="${defaultCodecs[inputType]}"`;
+ }
try {
- // Bail if no checking function
- if (!this.isHTML5 || !utils.is.function(media.canPlayType)) {
- return false;
- }
-
- // Check directly if codecs specified
- if (type.includes('codecs=')) {
- return media.canPlayType(type).replace(/no/, '');
- }
-
- // Type specific checks
- if (this.isVideo) {
- switch (type) {
- case 'video/webm':
- return media.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/, '');
-
- case 'video/mp4':
- return media.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, '');
-
- case 'video/ogg':
- return media.canPlayType('video/ogg; codecs="theora"').replace(/no/, '');
-
- default:
- return false;
- }
- } else if (this.isAudio) {
- switch (type) {
- case 'audio/mpeg':
- return media.canPlayType('audio/mpeg;').replace(/no/, '');
-
- case 'audio/ogg':
- return media.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, '');
-
- case 'audio/wav':
- return media.canPlayType('audio/wav; codecs="1"').replace(/no/, '');
-
- default:
- return false;
- }
- }
- } catch (e) {
+ return Boolean(type && this.media.canPlayType(type).replace(/no/, ''));
+ } catch (err) {
return false;
}
-
- // If we got this far, we're stuffed
- return false;
},
// Check for textTracks support
textTracks: 'textTracks' in document.createElement('video'),
- // Check for passive event listener support
- // https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
- // https://www.youtube.com/watch?v=NPM6172J22g
- passiveListeners: (() => {
- // Test via a getter in the options object to see if the passive property is accessed
- let supported = false;
- try {
- const options = Object.defineProperty({}, 'passive', {
- get() {
- supported = true;
- return null;
- },
- });
- window.addEventListener('test', null, options);
- window.removeEventListener('test', null, options);
- } catch (e) {
- // Do nothing
- }
-
- return supported;
- })(),
-
// <input type="range"> Sliders
rangeInput: (() => {
const range = document.createElement('input');
@@ -153,7 +90,7 @@ const support = {
touch: 'ontouchstart' in document.documentElement,
// Detect transitions support
- transitions: utils.transitionEndEvent !== false,
+ transitions: transitionEndEvent !== false,
// Reduced motion iOS & MacOS setting
// https://webkit.org/blog/7551/responsive-design-for-motion/