Skip to content

Instantly share code, notes, and snippets.

@AppLoidx
Last active April 3, 2024 22:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AppLoidx/2f5fca393c72609b01d9550fe93d57f5 to your computer and use it in GitHub Desktop.
Save AppLoidx/2f5fca393c72609b01d9550fe93d57f5 to your computer and use it in GitHub Desktop.
Way to autoplay audio on html5

This is the method I use to automatically play the audio on the page when I open it

  1. Creating iframe with empty audio:
<iframe src="assets/music/silence.mp3" allow="autoplay" id="audio" style="display:none"></iframe>

You can use this sound: silence

  1. Add audio tag with your original sound:
    <audio id="player" preload="auto" autoplay loop>
            <source src="assets/music/loop.mp3" type="audio/mp3">
    </audio>

I found this solution on stackoverflow

This is my examples (they have a background sound):

@kromruak14
Copy link

ya no funciona

@bagussatoto
Copy link

How to use that script, if there is no use of boolean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment