'Ask user for permission to autoplay videos on website

I'm building a small video-oriented course platform, it will be constructed as one issue/problem topic = one video regarding that issue. All that topics will be gathered in modules. I've made some auto forwarding - when the video finish, you are automatically taken to the next topic (new page). But... My video won't autoplay due to the modern autoplay policies. And that's fair, no problem. However, I'd like to ask the user to enable autoplay for my site. Is that somehow possible? Maybe by some cookies or whatever?

I'm using php and js/jquery.



Solution 1:[1]

It depends entirely on user's browser configuration, you don't need to keep track of preferences on your own cookies.

MDN has some example on how to test if autoplay failed. In that case, you can display a modal window to inform the user and ask him to enable autoplay permission:

let startPlayPromise = videoElem.play();

if (startPlayPromise !== undefined) {
  startPlayPromise.then(() => {
    // Start whatever you need to do only after playback
    // has begun.
  }).catch(error => {
    if (error.name === "NotAllowedError") {
      doSomethingToInformTheUser();
    } else {
      // Handle a load or playback error
    }
  });
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 madbob