
This cookie is set by GDPR Cookie Consent plugin. These cookies ensure basic functionalities and security features of the website, anonymously. This prevents the distracting situation in which a tab begins playing sound and the user can't find the tab among all their tabs and windows.Necessary cookies are absolutely essential for the website to function properly. The default value, true, means that even when otherwise available, autoplay won't take place until after a tab is brought to the foreground. media.block-autoplay-until-in-foregroundĪ Boolean preference which indicates whether or not media playback is blocked when started on a background tab.


If is not set to 0 (autoplay allowed by default), this preference being true allows autoplay of media with audio tracks anyway if the page has been activated by user gestures, and media that isn't audible is not restricted at all. gestures-needed (Nightly builds only)Ī Boolean preference which controls whether or not detection of user gestures is allowed to override the setting of. Īn integer preference which specifies whether per-domain configuration for autoplay support by default is allowed ( 0), blocked ( 1), or prompt-on-use ( 2). The default is false, except on Nightly where it is true. webaudioĪ Boolean preference which indicates whether or not to apply autoplay blocking to the Web Audio API. If this has been changed to false, media with an audio track will not be permitted to play even if muted. mutedĪ Boolean preference which if true (the default) allows audio media which is currently muted to be automatically played. Setting this value to false disables this capability. This Boolean preference, if true, allows browser extensions' background scripts to autoplay audio media. If this is false, the allowedToPlay property is missing from the HTMLMediaElement interface, and is thus not present on either or elements. This is currently false by default (except in nightly builds, where it's true by default). If you want to start playing the video after the first interaction with the page, setInterval() might be used to achieve this:Ī Boolean preference which specifies whether or not the HTMLMediaElement.allowedToPlay property is exposed to the web. If that's the case, we should present a user interface to let the user manually start playback that's handled here by a function showPlayButton().Īny other errors are handled as appropriate. This indicates that playback failed due to a permission issue, such as autoplay being denied. This looks at the error's name to see if it's NotAllowedError. We then add a catch() handler to the promise. If the promise returned by play() is resolved without error, the then() clause is run and can begin whatever needs to be done when autoplay has begun.
RADIANT MEDIA PLAYER AUTOPLAY CODE
Checking for undefined prevents this code from failing with an error on older versions of web browsers. Returning a promise to allow you to determine success or failure of the operation was added more recently.

We check for this because in earlier versions of the HTML specification, play() didn't return a value. The first thing we do with the result of play() is make sure it's not undefined. play ( ) if (startPlayPromise != undefined ) That means that the first time the play event is fired, you know your media is being started for the first time after the page is opened. The play event is sent both when the media is resumed after being paused and when autoplay occurs. You can do this easily, by listening for the play event to be fired on the media element. All you can really do is examine a few values and make an educated guess as to whether or not autoplay worked.Ī better approach, if you're able to adjust the direction you look at things from, is to instead rely on knowing that playback of the media has successfully started, instead of when it fails to start. Nor is there an exception thrown or a callback you can set up or even a flag on the media element that tells you if autoplay worked. There's not an event triggered when autoplay fails. Unfortunately, in the case of the autoplay attribute, recognizing whether or not autoplay successfully began is tricky. If you rely on autoplay for anything important, or if autoplay failure will impact your app in any way, you will probably want to be able to tell when it autoplay didn't begin.
