JavaScript - 随机播放音频

发布于 2024-12-09 03:22:08 字数 353 浏览 1 评论 0原文

我正在创建一个网页,该网页使用 JavaScript 来随机播放一系列音频文件问题及其匹配的拖放答案。我已经使用原生 HTML5 音频标签成功实现了这一点,但也有 IE 7/8 的后备部分,因为这些浏览器无法读取音频标签。此后备部分使用对象和参数标记周围的条件注释,如本文末尾处。

它的工作原理是它在 IE 中进行随机播放,但它会显示我专门隐藏的丑陋的媒体播放器样式控件,因为此活动使用“播放声音”按钮而不是音频播放器控件。

如果有人需要查看代码的特定部分,请告诉我。

非常感谢!

I am creating a webpage that uses JavaScript to shuffle a series of audio file questions and their matching drag-and-drop answers. I have successfully implemented this using the native HTML5 audio tags but also have a fallback section for IE 7/8 since these browsers cannot read the audio tag. This fallback section uses conditional comments around object and param tags as demonstrated at the end of this article here.

It works in that it does shuffle in IE, but breaks in that it displays the ugly Media Player-style controls that I had specifically hidden, as this activity uses "play sound" buttons instead of audio player controls.

If anyone needs to see specific parts of code, just let me know.

Many thanks in advance!

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

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

发布评论

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

评论(2

睫毛溺水了 2024-12-16 03:22:08

两个想法(抱歉,我现在在 Mac 上,所以在 IE 中测试不是一个很好的选择):

  1. 我看到你试图隐藏控件的参数,但你是否也尝试过应用 css到对象标签还是到包裹在它周围的容器?它可能就像为包装器 div 提供 display: nonevisibility: hide 样式一样简单。

  2. 这不是对您问题的直接答案,但您是否研究过任何插件,例如 SoundManager 2?它使用 HTML5 音频和 Flash 后备;我以前用过它并取得了成功。显然,它需要在较旧的浏览器上使用 Flash,但如果这不是问题,那么它可能比尝试找出如何隐藏控件更容易。

顺便说一句,这是一个不错的小页面。祝你好运!

要解决您的第二个问题/评论:使用对象/嵌入标签意味着您依赖浏览器/操作系统来决定它将使用什么插件来播放音频。一些谷歌搜索发现了 IE 和 Quicktime 的问题,以及一种可能的解决方案:

希望有帮助。如果您一直碰壁,SoundManager 2 可能值得尝试,但要注意,使用 SM2 将强制使用旧版浏览器的用户安装 Flash 并解锁。

Two thoughts (sorry, I'm on a mac at the moment so testing in IE isn't a great option):

  1. I see the parameters where you're trying to hide the controls, but have you also tried applying css to the object tag or to a container wrapped around it? It might be as simple as giving a wrapper div a style of display: none or visibility: hidden.

  2. This isn't a direct answer to your question, but have you investigated any plugins such as SoundManager 2? It uses HTML5 audio with a Flash fallback; I've used it before and had success. Obviously it requires Flash on older browsers, but if that's not an issue it could be easier than trying to figure out how to hide the controls.

It's a nice little page by the way. Good luck!

To address your second question/comment: using an object/embed tag means that you're relying on the browser/OS deciding on what plugin it will use to play audio. Some Googling turns up issues with IE and quicktime, and one possible solution:

Hope it helps. SoundManager 2 might be worth trying if you keep hitting walls, just be aware that using SM2 will mandate that users with older browsers have Flash installed and unblocked.

青巷忧颜 2024-12-16 03:22:08

我已经成功解决了 IE 中音频的第二个问题 - 为了让 shuffle 脚本与 IE 中的音频一起工作,你必须在音频代码之前调用 shuffle - 在我的例子中,我将所有条件注释移到了 < code>.shuffle(); 东西,不用担心!

I’ve managed to out the second issue with the audio in IE – for the shuffle script to work with the audio in IE, you have to call the shuffle BEFORE the audio code – in my case I moved all the conditional comments below the .shuffle(); stuff and it works no worries!

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