From 51814249afd4337c1a7d1426ea913988228a7574 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 19 May 2018 11:24:56 +1000 Subject: Reduce circular dependencies --- src/js/support.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/js/support.js') diff --git a/src/js/support.js b/src/js/support.js index 5528e898..38212d9f 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -133,6 +133,7 @@ const support = { }, }); window.addEventListener('test', null, options); + window.removeEventListener('test', null, options); } catch (e) { // Do nothing } -- cgit v1.2.3 From 392dfd024c505f5ae1bbb2f0d3e0793c251a1f35 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Wed, 13 Jun 2018 00:02:55 +1000 Subject: Utils broken down into seperate files and exports --- src/js/support.js | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'src/js/support.js') diff --git a/src/js/support.js b/src/js/support.js index 38212d9f..7eabae3c 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -2,7 +2,10 @@ // 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'; // Check for feature support const support = { @@ -15,7 +18,6 @@ const support = { check(type, provider, playsinline) { let api = false; let ui = false; - const browser = utils.getBrowser(); const canPlayInline = browser.isIPhone && playsinline && support.playsinline; switch (`${provider}:${type}`) { @@ -48,14 +50,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/ @@ -69,7 +68,7 @@ const support = { try { // Bail if no checking function - if (!this.isHTML5 || !utils.is.function(media.canPlayType)) { + if (!this.isHTML5 || !is.function(media.canPlayType)) { return false; } @@ -119,28 +118,6 @@ const support = { // 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; - })(), - // Sliders rangeInput: (() => { const range = document.createElement('input'); @@ -153,7 +130,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/ -- cgit v1.2.3 From 64bb206d85e5f7415d5ff81821e19fb107c30877 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Fri, 15 Jun 2018 14:06:28 +0200 Subject: Replace switch in support.check with simpler conditions --- src/js/support.js | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'src/js/support.js') diff --git a/src/js/support.js b/src/js/support.js index 7eabae3c..e6ce30c4 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -16,31 +16,9 @@ const support = { // Check for support // Basic functionality vs full UI check(type, provider, playsinline) { - let api = false; - let ui = false; 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, -- cgit v1.2.3 From 2a186e425bd83bddea65247d1352cc7b0114fab0 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Fri, 15 Jun 2018 15:07:37 +0200 Subject: Replace switch in support.mime with object literal and conditions, and make it return boolean --- src/js/support.js | 74 +++++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) (limited to 'src/js/support.js') diff --git a/src/js/support.js b/src/js/support.js index e6ce30c4..6395293f 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -7,6 +7,15 @@ 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 = { // Basic support @@ -41,56 +50,29 @@ 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 || !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 -- cgit v1.2.3 From fe26d383f101062745ef1397832959df8911161b Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Thu, 25 Oct 2018 09:17:15 +1100 Subject: Added support for picture-in-picture in Chrome --- src/js/support.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/js/support.js') diff --git a/src/js/support.js b/src/js/support.js index 6395293f..59f27c3b 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -36,8 +36,26 @@ const support = { }, // Picture-in-picture support - // Safari only currently - pip: (() => !browser.isIPhone && is.function(createElement('video').webkitSetPresentationMode))(), + // Safari & Chrome only currently + pip: (() => { + if (browser.isIPhone) { + return false; + } + + // Safari + // https://developer.apple.com/documentation/webkitjs/adding_picture_in_picture_to_your_safari_media_controls + if (is.function(createElement('video').webkitSetPresentationMode)) { + return true; + } + + // Chrome + // https://developers.google.com/web/updates/2018/10/watch-video-using-picture-in-picture + if (document.pictureInPictureEnabled && !createElement('video').disablePictureInPicture) { + return true; + } + + return false; + })(), // Airplay support // Safari only currently -- cgit v1.2.3 From 65eb5c1b8bd68bf2e898f7acc8703e02359377c9 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 3 Nov 2018 21:16:40 +1100 Subject: Fix support check --- src/js/support.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/js/support.js') diff --git a/src/js/support.js b/src/js/support.js index 59f27c3b..9257df13 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -70,25 +70,21 @@ const support = { // Related: http://www.leanbackplayer.com/test/h5mt.html mime(inputType) { const [mediaType] = inputType.split('/'); + let type = inputType; + + // Verify we're using HTML5 and there's no media type mismatch 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]}"`; + // Add codec if required + if (Object.keys(defaultCodecs).includes(type)) { + type += `; codecs="${defaultCodecs[inputType]}"`; } try { return Boolean(type && this.media.canPlayType(type).replace(/no/, '')); - } catch (err) { + } catch (e) { return false; } }, -- cgit v1.2.3 From a0303969c2c6875790d600444f357b12bdb09b50 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 8 Dec 2018 16:50:44 +1100 Subject: Fix for error when mime type not specified (fixes #1274) --- src/js/support.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/js/support.js') diff --git a/src/js/support.js b/src/js/support.js index 9257df13..81965867 100644 --- a/src/js/support.js +++ b/src/js/support.js @@ -68,9 +68,13 @@ 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(inputType) { - const [mediaType] = inputType.split('/'); - let type = inputType; + mime(input) { + if (is.empty(input)) { + return false; + } + + const [mediaType] = input.split('/'); + let type = input; // Verify we're using HTML5 and there's no media type mismatch if (!this.isHTML5 || mediaType !== this.type) { @@ -79,7 +83,7 @@ const support = { // Add codec if required if (Object.keys(defaultCodecs).includes(type)) { - type += `; codecs="${defaultCodecs[inputType]}"`; + type += `; codecs="${defaultCodecs[input]}"`; } try { -- cgit v1.2.3