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

前端 未结 9 2342
时光说笑
时光说笑 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:35

    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)

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

    For future reference to people who find this page later you can use:

    <audio controls autoplay loop hidden>
    <source src="kooche.mp3" type="audio/mpeg">
    <p>If you can read this, your browser does not support the audio element.</p>
    </audio>
    
    0 讨论(0)
  • 2021-02-08 14:37

    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

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

    "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
    0 讨论(0)
  • 2021-02-08 14:41

    I used this code,

     <div style="visibility:hidden">
        <audio autoplay loop>
            <source src="Aakaasam-Yemaaya Chesave.mp3">
        </audio> 
    </div>
    

    It is working well but i want stop and pause button. So, we can stop if we don't want to listen.

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

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

    autoPlay
    

    React wants it to be camelcase!

    0 讨论(0)
提交回复
热议问题