在 IE(7+) 中嵌入音频,并具有 JavaScript 静音和取消静音功能

发布于 2024-12-07 16:45:03 字数 323 浏览 1 评论 0原文

我一直在寻找一种将音频嵌入网站的方法,具有循环和自动播放的能力,并且还能够使用 JavaScript 将音频静音和取消静音。我知道这在 html5 中是可能的并且非常容易,但我听说 IE 还不支持 html5(或者可能不支持音频标签)。

我还需要我的嵌入式音频能够在 IE7 之前工作。所以我认为使用标签适用于除 IE 之外的所有其他浏览器,而我希望类似的东西也适用于 IE;不幸的是,它不支持从 javascript 调用静音和取消静音 - 这是因为我不希望音频播放器中的任何控件可见;只是一个自定义声音按钮,用户可以单击该按钮来静音和取消静音。有什么想法吗?似乎这样的事情是最简单的事情,但却是最难编码的事情:/

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 :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烈酒灼喉 2024-12-14 16:45:03

考虑使用默认使用 HTML 5 的播放器,但如果不支持 Flash,则可以使用 Flash。

JPlayer 可以做到这一点,并且有一个 静音功能。

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.

安静 2024-12-14 16:45:03

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>

您可能需要在音频标记中指定的属性是 controls='controls' 以启用播放选项,例如播放暂停和音量控制(包括静音); loop='loop' 启用自动循环; autoplay='autoplay' 显然是自动播放;和 preload='auto' 在页面加载时加载音频(您也可以指定“元数据”或“无”),

您的播放器可能如下所示:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文