简体   繁体   中英

Embedding audio in IE(7+) with javascript capability to mute and unmute

I've been looking around for a method to embed audio onto a website, have a capability to loop and autoplay and also be able to mute and unmute the audio with javascript. I know that this is possible and very easy in html5, but I've heard that IE doesn't support html5 yet (or the audio tags perhaps).

I also need my embedded audio to work as far back as IE7. So i think that using the tags will work for all other browsers but IE, while I was hoping something like could work for IE; unfortunately, it doesn't support calls from javascript to mute and unmute - this is because I don't want any controls from the audio player to be visible; simply a custom sound button that the user can click to mute and unmute the audio. Any ideas? Seems that something like this is the most simple thing, but the hardest thing to code :/

Consider using a player that uses HTML 5 by default, but can fall back on Flash if it's not supported.

JPlayer can do that, and has a mute function.

HTML5 is your best bet.

<audio>
    <source src="horse.ogg" type="audio/ogg" />
    <source src="horse.mp3" type="audio/mp3" />
    <!--
        You can put a flash player here in case the users browser doesn't support HTML5 or any of the audio formats you have added.
    -->
</audio>

the attributes you might want to specify in the audio tag are controls='controls' to enable playback options like play pause and volume controls including mute; loop='loop' to enable auto-loop; autoplay='autoplay' obviously to autoplay; and preload='auto' to load the audio on page load (you can also specify "metadata" or "none")

your player would probably look like:

<audio preload='auto' autoplay='autoplay' controls='controls' loop='loop'>
    <source src="yoursound.ogg" type="audio/ogg" />
    <source src="yoursound.mp3" type="audio/mp3" />
    <!--
        Flash player here to fall back on if the users browser doesn't support HTML5
    -->
</audio>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM