diff --git a/modules/player/popcorn.player.js b/modules/player/popcorn.player.js index 895f66968..208756caf 100644 --- a/modules/player/popcorn.player.js +++ b/modules/player/popcorn.player.js @@ -343,7 +343,7 @@ // Popcorn.smart will attempt to find you a wrapper or player. If it can't do that, // it will default to using an HTML5 video in the target. - Popcorn.smart = function( target, src, options ) { + Popcorn.smart = function( target, src, popcornOptions, options ) { var node = typeof target === "string" ? Popcorn.dom.find( target ) : target, i, srci, j, media, mediaWrapper, popcorn, srcLength, // We leave HTMLVideoElement and HTMLAudioElement wrappers out @@ -367,8 +367,8 @@ for ( j = 0; j < wrappers.length; j++ ) { mediaWrapper = Popcorn[ wrappers[ j ] ]; if ( mediaWrapper && mediaWrapper._canPlaySrc( srci ) === "probably" ) { - media = mediaWrapper( node ); - popcorn = Popcorn( media, options ); + media = mediaWrapper( node, options ); + popcorn = Popcorn( media, popcornOptions ); // Set src, but not until after we return the media so the caller // can get error events, if any. setTimeout( function() { @@ -382,8 +382,8 @@ for ( var key in Popcorn.player.registry ) { if ( Popcorn.player.registry.hasOwnProperty( key ) ) { if ( Popcorn.player.registry[ key ].canPlayType( node.nodeName, srci ) ) { - // Popcorn.smart( player, src, /* options */ ) - return Popcorn[ key ]( node, srci, options ); + // Popcorn.smart( player, src, /* popcornOptions */ ) + return Popcorn[ key ]( node, srci, popcornOptions, options ); } } } @@ -392,7 +392,7 @@ // If we don't have any players or wrappers that can handle this, // Default to using HTML5 video. Similar to the HTMLVideoElement // wrapper, we put a video in the div passed to us via: - // Popcorn.smart( div, src, options ) + // Popcorn.smart( div, src, popcornOptions ) var videoHTML, videoElement, videoID = Popcorn.guid( "popcorn-video-" ), @@ -419,7 +419,7 @@ videoElement.src = decodeDiv.firstChild.nodeValue; }, 0 ); - return Popcorn( '#' + videoID, options ); + return Popcorn( '#' + videoID, popcornOptions ); } node.appendChild( videoHTMLContainer ); @@ -432,9 +432,9 @@ videoHTML += ""; videoHTMLContainer.innerHTML = videoHTML; - if ( options && options.events && options.events.error ) { - node.addEventListener( "error", options.events.error, false ); + if ( popcornOptions && popcornOptions.events && popcornOptions.events.error ) { + node.addEventListener( "error", popcornOptions.events.error, false ); } - return Popcorn( '#' + videoID, options ); + return Popcorn( '#' + videoID, popcornOptions ); }; })( Popcorn ); diff --git a/wrappers/adaptive/popcorn.HTMLAdaptiveMediaElement.js b/wrappers/adaptive/popcorn.HTMLAdaptiveMediaElement.js index 9226ff51d..ca4b59f0c 100644 --- a/wrappers/adaptive/popcorn.HTMLAdaptiveMediaElement.js +++ b/wrappers/adaptive/popcorn.HTMLAdaptiveMediaElement.js @@ -68,12 +68,13 @@ } } - function wrapMedia(id, mediaType) { + function wrapMedia(id, mediaType, options = {}) { var parent = typeof id === 'string' ? document.querySelector(id) : id, media = document.createElement(mediaType); var impl = { autoplay: EMPTY_STRING, + muted: options.muted, }; media.dispatchEvent = function (name, data) { @@ -92,6 +93,8 @@ media.setAttribute('playsinline', ''); media.setAttribute('webkit-playsinline', ''); + media.setAttribute('muted', true); + media.muted = true; var source = document.createElement('source'); media.appendChild(source); @@ -101,7 +104,7 @@ [ 'seeked', 'timeupdate', 'progress', 'play', 'pause', 'seeking', 'waiting', 'playing', - 'error', 'volumechange', 'loadedmetadata' + 'error', 'volumechange', 'loadedmetadata', 'mute', 'unmute' ].forEach(function (event) { media.addEventListener(event, function() { media.dispatchEvent(event); @@ -201,8 +204,8 @@ return media; } - Popcorn.HTMLAdaptiveMediaElement = function (id) { - return wrapMedia(id, 'video'); + Popcorn.HTMLAdaptiveMediaElement = function (id, options) { + return wrapMedia(id, 'video', options); }; Popcorn.HTMLAdaptiveMediaElement._canPlaySrc = canPlaySrc; diff --git a/wrappers/html5/popcorn.HTMLMediaElement.js b/wrappers/html5/popcorn.HTMLMediaElement.js index 8ea4bd02b..d760e489d 100644 --- a/wrappers/html5/popcorn.HTMLMediaElement.js +++ b/wrappers/html5/popcorn.HTMLMediaElement.js @@ -63,12 +63,14 @@ return "probably"; } - function wrapMedia(id, mediaType) { + function wrapMedia(id, mediaType, options = {}) { var parent = typeof id === "string" ? document.querySelector(id) : id, media = document.createElement(mediaType); + media.setAttribute('muted', true); media.setAttribute('playsinline', ''); media.setAttribute('webkit-playsinline', ''); + media.muted = true; var source = document.createElement('source'); media.appendChild(source); @@ -87,7 +89,9 @@ media._play = media.play; media._pause = media.pause; media.play = function () { - media._play(); + media._play().catch(err => { + console.error(err.message); + }); }; media.pause = function () { media._pause(); @@ -122,14 +126,14 @@ return media; } - Popcorn.HTMLVideoElement = function (id) { - return wrapMedia(id, "video"); + Popcorn.HTMLVideoElement = function (id, options) { + return wrapMedia(id, "video", options); }; Popcorn.HTMLVideoElement._canPlaySrc = canPlayVideoSrc; - Popcorn.HTMLAudioElement = function (id) { - return wrapMedia(id, "audio"); + Popcorn.HTMLAudioElement = function (id, options) { + return wrapMedia(id, "audio", options); }; Popcorn.HTMLAudioElement._canPlaySrc = canPlayAudioSrc; diff --git a/wrappers/null/popcorn.HTMLNullVideoElement.js b/wrappers/null/popcorn.HTMLNullVideoElement.js index d19ee678b..8dce1da8a 100644 --- a/wrappers/null/popcorn.HTMLNullVideoElement.js +++ b/wrappers/null/popcorn.HTMLNullVideoElement.js @@ -72,7 +72,7 @@ }; - function HTMLNullVideoElement( id ) { + function HTMLNullVideoElement( id, options = {} ) { var self = new Popcorn._MediaElementProto(), parent = typeof id === "string" ? document.querySelector( id ) : id, @@ -83,13 +83,13 @@ src: EMPTY_STRING, networkState: self.NETWORK_EMPTY, readyState: self.HAVE_NOTHING, - autoplay: EMPTY_STRING, + autoplay: 1, preload: EMPTY_STRING, controls: EMPTY_STRING, loop: false, poster: EMPTY_STRING, volume: 1, - muted: false, + muted: true, width: parent.width|0 ? parent.width : self._util.MIN_WIDTH, height: parent.height|0 ? parent.height : self._util.MIN_HEIGHT, seeking: false, diff --git a/wrappers/vrview/popcorn.HTMLVRViewVideoElement.js b/wrappers/vrview/popcorn.HTMLVRViewVideoElement.js index a695fa859..200ce2a22 100644 --- a/wrappers/vrview/popcorn.HTMLVRViewVideoElement.js +++ b/wrappers/vrview/popcorn.HTMLVRViewVideoElement.js @@ -65,7 +65,7 @@ return false; } - function HTMLVRViewVideoElement(id) { + function HTMLVRViewVideoElement(id, options = {}) { if (!window.postMessage) { throw 'ERROR: HTMLVRViewVideoElement requires window.postMessage'; @@ -79,13 +79,13 @@ networkState: self.NETWORK_EMPTY, readyState: self.HAVE_NOTHING, seeking: false, - autoplay: EMPTY_STRING, + autoplay: options.autoplay || EMPTY_STRING, preload: EMPTY_STRING, controls: false, loop: false, poster: EMPTY_STRING, volume: 1, - muted: false, + muted: options.muted || false, currentTime: 0, duration: NaN, ended: false, @@ -610,8 +610,8 @@ return self; } - Popcorn.HTMLVRViewVideoElement = function (id) { - return new HTMLVRViewVideoElement(id); + Popcorn.HTMLVRViewVideoElement = function (id, options) { + return new HTMLVRViewVideoElement(id, options); }; // Helper for identifying URLs we know how to play. diff --git a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js index f379cb17b..858a32778 100644 --- a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js +++ b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js @@ -58,7 +58,7 @@ ytCallbacks.push( callback ); } - function HTMLYouTubeVideoElement( id ) { + function HTMLYouTubeVideoElement( id, options = {} ) { // YouTube iframe API requires postMessage if( !window.postMessage ) { @@ -74,13 +74,13 @@ networkState: self.NETWORK_EMPTY, readyState: self.HAVE_NOTHING, seeking: false, - autoplay: EMPTY_STRING, + autoplay: options.autoplay || EMPTY_STRING, preload: EMPTY_STRING, controls: false, loop: false, poster: EMPTY_STRING, volume: 1, - muted: false, + muted: options.muted || false, currentTime: 0, duration: NaN, ended: false, @@ -799,8 +799,8 @@ return self; } - Popcorn.HTMLYouTubeVideoElement = function( id ) { - return new HTMLYouTubeVideoElement( id ); + Popcorn.HTMLYouTubeVideoElement = function( id, options ) { + return new HTMLYouTubeVideoElement( id, options ); }; // Helper for identifying URLs we know how to play.