Autoplay an audio with HTML5 embed tag while the player is invisible

142,459

Solution 1

Alternatively you can try the basic thing to get your need,

<audio autoplay loop>
      <source src="johann_sebastian_bach_air.mp3">
</audio>

For further reference click here

Solution 2

If you are using React, make sure autoplay is set to,

autoPlay

React wants it to be camelcase!

Solution 3

You can use this simple code:

<embed src="audio.mp3" AutoPlay loop hidden>

for the result seen here: https://hataken.000webhostapp.com/list-anime.html

Solution 4

Sometimes autoplay is needed. Someone once pointed out that the famous Les Paul Google Doodle (2011) required autoplay, even though the sound didn't play until you moused over the guitar strings. If it's done with class and great design it can be beautiful (especially movie websites with immersive design)

Solution 5

"Sensitive" era

Modern browsers today seem to block (by default) these autoplay features. They are somewhat treated as pop-ops. Very intrusive. So yeah, users now have the complete control on when the sounds are played. [1,2,3]

HTML5 era

<audio controls autoplay loop hidden>
    <source src="audio.mp3" type="audio/mpeg">
</audio>

Early days of HTML

<embed src="audio.mp3" style="visibility:hidden" />

References

  1. Jer Noble, New <video> Policies for iOS, WebKit, link
  2. Allow or block media autoplay in Firefox, FireFox Help, link
  3. Mounir Lamouri, Unified autoplay, Chromium Blog, link
  4. Embedded content, World Wide Web Consortium, link
Share:
142,459
Nima
Author by

Nima

Updated on July 05, 2022

Comments

  • Nima
    Nima almost 2 years

    I want to autoplay a MP3 audio file and I don't want the player to be visible.

    <div id="music"><embed src="Comfortably_Numb.mp3" autostart=true loop=false></div>
    

    When I added display:none to the audio tag using css, it doesn't play the music at all. Could someone explain me how to play the music without displaying the player?

  • huykon225
    huykon225 about 7 years
    I am using audio tag and it is working perfect but when I check on mobile. Html5 audio tag not sound autoplay. how to fix it ?
  • Daniel
    Daniel over 6 years
    Welcome to Stack Overflow, please review: stackoverflow.com/help/how-to-answer
  • Dan Zuzevich
    Dan Zuzevich over 6 years
    If you came here using React, check my answer below.
  • Admin
    Admin over 5 years
    Where could you host the mp3?
  • Vinith
    Vinith over 5 years
    Hundereds of option to store and stream MP3, common ones are amazon s3, opendrive, kiwi6 etc
  • Kyle Pennell
    Kyle Pennell over 4 years
    you're a savior!