tousignant-christopher
5/22/2018 - 5:43 PM

Jquery Plugin - Video Autoplay

To get videos to autoplay on Google and Safari

Thanks to @greggnakamura

$.extend( {
  gnAutoplay : function( videoId ) {
		var promise = document.getElementById(videoId).play();
		
		if (promise !== undefined) {
			promise
				.then(_ => {
					console.log('Autoplay started!');
				})
				.catch(error => {
					unmuteButton.addEventListener('click', function() {
						video.muted = false;
					});
				});
		}
	}
} );