Unable to autoplay video or audio

Symptoms

  • Video or audio in the web page doesn't autoplay as expected.
  • Or when trying to play video or audio with JavaScript, a NotAllowedError is thrown:

    Uncaught NotAllowedError: play() failed because the user didn't interact with the document first.

Cause

By default browsers block web pages from autoplaying video or audio.

Resolution

Use Web.SetAutoplayEnabled() to enable autoplaying video and audio, like this:

void Awake() {
    Web.SetAutoplayEnabled(true);
}