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

前端 未结 9 2343
时光说笑
时光说笑 2021-02-08 14:07

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

相关标签:
9条回答
  • 2021-02-08 14:43
    <div id="music">
    <audio autoplay>
      <source src="kooche.mp3" type="audio/mpeg">
      <p>If you can read this, your browser does not support the audio element.</p>
    </audio>
    </div>
    

    And the css:

    #music {
      display:none;
    }
    

    Like suggested above, you probably should have the controls available in some form. Maybe use a toggle link/checkbox that slides the controls in via jquery.

    Source: HTML5 Audio Autoplay

    0 讨论(0)
  • 2021-02-08 14:53

    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

    0 讨论(0)
  • 2021-02-08 14:53

    You Could use this code, It's Works with me

    <div style="visibility:hidden">
        <audio autoplay loop>
            <source src="../audio/audio.mp3">
        </audio> 
    </div>
    
    0 讨论(0)
提交回复
热议问题