简体   繁体   English

将音频嵌入到具有JavaScript功能的IE(7+)中以静音和取消静音

[英]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. 我一直在寻找一种将音频嵌入网站的方法,可以循环播放和自动播放,还可以使用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). 我知道这在html5中是可行且非常容易的,但是我听说IE还不支持html5(或者可能是音频标签)。

I also need my embedded audio to work as far back as IE7. 我还需要嵌入式音频才能工作到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; 因此,我认为使用标记将可用于除IE之外的所有其他浏览器,而我希望类似的东西可用于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; 不幸的是,它不支持从javascript进行静音和取消静音的调用-这是因为我不希望音频播放器中的任何控件可见。 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. 考虑使用默认情况下使用HTML 5的播放器,但如果不支持该播放器,则可以使用Flash。

JPlayer can do that, and has a mute function. JPlayer可以做到这一点,并具有静音功能。

HTML5 is your best bet. HTML5是您最好的选择。

<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; 您可能要在音频标签中指定的属性是controls='controls'以启用播放选项,例如播放暂停和音量控制(包括静音); loop='loop' to enable auto-loop; loop='loop'启用自动循环; autoplay='autoplay' obviously to autoplay; autoplay='autoplay'显然可以自动播放; and preload='auto' to load the audio on page load (you can also specify "metadata" or "none") preload='auto'以在页面加载时加载音频(您也可以指定“元数据”或“无”)

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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