Skip to content

Instantly share code, notes, and snippets.

@rescenic
Forked from AppLoidx/Audio-on-HTML5.md
Created April 3, 2024 22:30
Show Gist options
  • Save rescenic/60be88b7a6c5323a2a862069137a00c7 to your computer and use it in GitHub Desktop.
Save rescenic/60be88b7a6c5323a2a862069137a00c7 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):

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