Q:

Chrome video autoplay

Following Chrome & Firefox's recent update autoplay videos are no longer supported - I've tried to add some code to play this on startup but it doesn't seem to work?
    var vid = document.getElementById("attractor"); 

    function playVid() { 
        vid.play(); 
    } 

Has anyone found a workaround to this?
We do a lot of touch-screen interactives and rely on this method for our attractor videos.

A:

autoplay will only work if you specify it as muted by default, like this. 
    <video autoplay muted>
      <source src="video.mp4" type="video/mp4"></source>
   </video>

Don't worry, users will be able to unmute the video as part of the html5 video element.

A:

I've found a good way how to autoplay the video and avoid a js error in console.

const myVideo = document.getElementById('my-video');

// Not all browsers return promise from .play().
const playPromise = myVideo.play() || Promise.reject('');
playPromise.then(() => {
  // Video could be autoplayed, do nothing.
}).catch(err => {
  // Video couldn't be autoplayed because of autoplay policy. Mute it and play.
  myVideo.muted = true;
  myVideo.play();
});
<video id="my-video" src="https://sample-videos.com/video123/mp4/240/big_buck_bunny_240p_2mb.mp4">

This code tries to start autoplay with sound, and if it's not possible then it will mute the video and autoplay the video without sound. I think it's an optimal way and prevents JS errors.

A:

According to my own observations and many articles like this one for example, Chrome now blocks autoplay for videos unless they are muted. Videos with sound enabled can only be played by user interaction, e.g. a mouse click or a touch tap and cannot be started by javascript.
By doing this Google wants to "(make) auto-play more consistent with user expectations and [...] give users more control over audio" [1]

