开发者

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

开发者 https://www.devze.com 2023-04-09 04:23 出处:网络
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 javascri开发者_如何学Pythonpt. I know th

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 javascri开发者_如何学Pythonpt. 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号