JavaScript - 随机播放音频
我正在创建一个网页,该网页使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两个想法(抱歉,我现在在 Mac 上,所以在 IE 中测试不是一个很好的选择):
我看到你试图隐藏控件的参数,但你是否也尝试过应用 css到对象标签还是到包裹在它周围的容器?它可能就像为包装器 div 提供
display: none
或visibility: hide
样式一样简单。这不是对您问题的直接答案,但您是否研究过任何插件,例如 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):
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
orvisibility: hidden
.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.
我已经成功解决了 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!