2018-05-15 @ 08:29: Autoplay HTML5 videos with sound in Chromium based browsers BrowsersJavaScript

UPDATE: Unfortunately, the following does no longer work with the latest Chromium version. 🙁
 

So, the autoplay policy for HTML5 videos in Chromium based browsers has been changed some time ago to disallow autoplay if the video contains audio. The intent was to not bother the user with sound being played automatically upon visitin a website, and in turn give him an option to selectively choose to have sound turned on/off for HTML5 videos. Well, I’ve found a nifty workaorund which allows you to play videos with sound automatically.

Create a video element as usual:

<video id="myvideo" src="myvideo.mp4" preload="auto" autoplay loop muted></video>

 

As you see the video is muted and will therefore play automatically in Chromium based browsers.

Now add this small JavaScript to unmute the video:

setTimeout(function() {
	var video = document.getElementById("myvideo");
	video.muted = false;
	console.log('Video unmuted.');
}, 1000);

 

This will unmute the video after one second. Bingo! Works like a charm. 🙂

Comments Off on Autoplay HTML5 videos with sound in Chromium based browsers

  • About

    We never asked for this.