diff --git a/.eslintrc.js b/.eslintrc.js index a0412622..ec7ddbf8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,6 +10,9 @@ module.exports = { 'rules': { 'jsdoc/check-types': 'error', 'space-infix-ops': 'error', + 'no-console': ['error', { + 'allow': ['warn', 'error'] + }], }, 'plugins': [ 'jsdoc', diff --git a/README.md b/README.md index 245cae4e..88750fd8 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ the previous snippet. A summary of all settings follows: | adLabel | string | Replaces the "Advertisement" text in the ad label. Added for multilingual UI support. | | adsRenderingSettings | object | JSON object with ads rendering settings as defined in the IMA SDK,Docs(1). | | autoPlayAdBreaks | boolean | Whether or not to automatically play VMAP or ad rules ad breaks. Defaults,to true. | -| adWillPlayMuted | boolean | Notifies the SDK whether the player intends to start ad while muted. Changing this setting will have no impact on ad playback. Defaults,to false. | +| **deprecated** adWillPlayMuted | boolean | Notifies the SDK whether the player intends to start ad while muted. Changing this setting will have no impact on ad playback. Defaults,to false. | | contribAdsSettings | object | Additional settings to be passed to the contrib-ads plugin(2), used by,this IMA plugin. | | debug | boolean | True to load the debug version of the plugin, false to load the non-debug version.,Defaults to false. | | disableFlashAds | boolean | True to disable Flash ads - Flash ads will be considered an unsupported ad type. Defaults to false. | diff --git a/examples/autoplay/ads.js b/examples/autoplay/ads.js index 84469b00..4827863f 100644 --- a/examples/autoplay/ads.js +++ b/examples/autoplay/ads.js @@ -14,24 +14,62 @@ * limitations under the License. */ -var player = videojs('content_video'); - -var options = { - id: 'content_video', - adTagUrl: 'http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&' + - 'iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&' + - 'impl=s&gdfp_req=1&env=vp&output=xml_vmap1&unviewed_position_start=1&' + - 'cust_params=sample_ar%3Dpremidpostpod%26deployment%3Dgmf-js&cmsid=496&' + - 'vid=short_onecue&correlator=' -}; - -player.ima(options); - -// Remove controls from the player on iPad to stop native controls from stealing -// our click -var contentPlayer = document.getElementById('content_video_html5_api'); -if ((navigator.userAgent.match(/iPad/i) || - navigator.userAgent.match(/Android/i)) && - contentPlayer.hasAttribute('controls')) { - contentPlayer.removeAttribute('controls'); + + +var autoplayAllowed = false; +var autoplayRequiresMute = false; + +function checkUnmutedAutoplaySupport() { + canAutoplay + .video({timeout: 100, muted: false}) + .then(({result, error}) => { + if(result === false) { + // Unmuted autoplay is not allowed. + checkMutedAutoplaySupport(); + } else { + // Unmuted autoplay is allowed. + autoplayAllowed = true; + autoplayRequiresMute = false; + initPlayer(); + } + }) +} + +function checkMutedAutoplaySupport() { + canAutoplay + .video({timeout: 100, muted: true}) + .then(({result, error}) => { + if(result === false) { + // Muted autoplay is not allowed. + autoplayAllowed = false; + autoplayRequiresMute = false; + } else { + // Muted autoplay is allowed. + autoplayAllowed = true; + autoplayRequiresMute = true; + } + initPlayer(); + }) } + +function initPlayer() { + var vjsOptions = { + autoplay: autoplayAllowed, + muted: autoplayRequiresMute, + debug: true + } + var player = videojs('content_video', vjsOptions); + + var imaOptions = { + id: 'content_video', + adTagUrl: 'http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&' + + 'iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&' + + 'impl=s&gdfp_req=1&env=vp&output=xml_vmap1&unviewed_position_start=1&' + + 'cust_params=sample_ar%3Dpremidpostpod%26deployment%3Dgmf-js' + + '&cmsid=496&vid=short_onecue&correlator=' + + }; + player.ima(imaOptions); +} + +checkUnmutedAutoplaySupport(); diff --git a/examples/autoplay/index.html b/examples/autoplay/index.html index 243bef7f..56ef7f65 100644 --- a/examples/autoplay/index.html +++ b/examples/autoplay/index.html @@ -26,7 +26,7 @@
@@ -34,6 +34,7 @@ +