post image

New Policies for Autoplaying Audio & Video on Websites

Automatically playing a video or audio on page load is probably one of the annoying things that a website can do to a user. A muted video is still probably okay, but any kind of autoplaying sound comes as more of a surprise to the user!

To deter websites from autoplaying audio and video, browsers have brought out new policies for them. In general, browsers will now block an autoplaying video or audio from playing. In addition, users can set their preferences as to which websites can be allowed to autoplay, and which cannot. Good news for end users, bad news for marketing guys.

Each browser has their own rules for autoplaying media, but more or less they are the same.

Autoplaying Rules for Google Chrome

  • A muted autoplay will be allowed to play.
  • An autoplay with sound is allowed only when the user has done some kind of gesture with the website before — click, tap etc.
  • On desktop, an autoplay with sound is also allowed when the the user's MEI (Media Engagement Index) for the website domain has crossed a certain limit. MEI is an indication that the user has previously played a media with sound on the website before, so its okay to autoplay the media in the current case.
    Chrome has some rules for calculating the MEI, like the the usage of media beforehand must be greater than 7 seconds, size of the video played beforehand must be greater than 200x140 px etc.
  • On mobiles, autoplaying with sound will always be allowed if the user has placed the website to their home screen.

You can check the MEI for your visited websites by entering chrome://media-engagement/ in Chrome's navigation bar.

The complete list and more information can be found on Autoplay Policy Changes for Google Chrome

Autoplaying Rules for Safari

  • If the user had done some kind of interaction like click, touch, keypress then autoplaying is allowed.
  • If the user had not done some kind of interaction, then a muted video or video that has no audio tracks will be allowed to play. If the video gradually plays an audio, the video will be paused.
  • Autoplaying video caused due to the autoplay attribute will play only when they are visible in the viewport. They are paused if they are scrolled out of the viewport.
    Autoplaying video caused due to the play() method will keep on playing even if they are scrolled out of the viewport.

The complete set of rules can be found on New <video> Policies for iOS.

Autoplaying Rules for Firefox

  • Muted autoplay is always allowed.
  • Autplaying will never be allowed if no user interaction has been performed
  • An audible autoplay is allowed if the user has granted camera/microphone permissions

More information on Firefox 66 to block automatically playing audible video and audio.

Best Practices for Allowing Autoplay Media to Work Properly

Autoplaying rules for all browsers are somewhat similar :

  • Wait for the user to perform some kind of gesture before autoplaying. For example wait for the user to click somewhere, press a key, or scroll down the page. Then autoplay the media.
  • Videos can be autoplayed with sound muted. If the user gains interest he can unmute it himself.
    <video id="video" muted autoplay>

The whole point is not to annoy or surprise the user.

How to Know Autoplaying Was Blocked

  • If autoplay happened due to the play() method :

    The Promise returned by the media element's play method will throw an exception if autoplaying is blocked. You will then need to show the "Play" button.

    var played = document.querySelector('#video').play();
    played.then(function() {
    	// autoplay started
    }).catch(function(error) {
    	// autoplay blocked
    	// handle blocking : show the play button
  • If autoplay happened due to the set autoplay attribute :

    There is no error thrown in this case. The video will just stop playing with proper controls still there and you don't need to do anything.