Is there a way to ask for autoplay permission in firefox using javascript ? Autoplay can be activated manually, but what I want is to ask for permission programmatically. (For example, when I want to use webcam, it asks to the user if webcam can be used, I want to know if there is a way to do like this, but for video/audio autoplay)

<audio autoplay>
   <source src="path/to/the/audio/file.mp3">
</audio>

I expect the sound plays automatically, but I get the following error:

NotAllowedError: The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

1 Answers

0
wasanga7 On

Try this:

<audio id='audio'>
    <source src="path/to/the/audio/file.mp3">
</audio>

<script>
    document.querySelector('#audio').autoplay = true;
</script>