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?<
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();
});
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.