I’ve a webpage which displays random videos on load. These random videos are being stored in an array.
function playVideo() {
const videoEl = $('.video');
const videoSrc = $('.video source');
const vid = Math.floor(Math.random() * videos.length);
console.log(vid, videos[vid]);
videoSrc.attr('src', videos[vid]);
videoEl[0].autoplay = true;
// videoEl[0].controls = true;
videoEl[0].load();
}
The src contains the right path and each time different video is added to the page, but the autoplay option doesn’t work. I’ve tried replacing it with play(), creating a new video tag and appending it to the body, but these methods haven’t worked either.
Why is the autoplay option being blocked? In Safari, when I click on spacebar for the first time, it plays. Could it be a browser related issue?