javascript 在 Internet Explorer 中播放 HTML 音频?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12894468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Play HTML audio in Internet Explorer?
提问by Max Williams
I have this html and js which I'm using to play some audio:
我有我用来播放一些音频的 html 和 js:
HTML
HTML
<div id="audio-clips">
<audio src="/audio/cha-ching.wav" type="audio/wav" id="audio-cha-ching">
</div>
JavaScript
JavaScript
var sfx = $("#audio-clips #audio-cha-ching")[0];
sfx.play();
This is failing in IE 8, due to it not recognising the "play" method. Is there a jQuery audio-playing method which works cross-browser, with the same code? I'd rather do that then try to fall back to some IE-specific solution (as browser-specific solutions are always brittle).
这在 IE 8 中失败,因为它无法识别“播放”方法。是否有使用相同代码的跨浏览器的 jQuery 音频播放方法?我宁愿这样做然后尝试回退到某些特定于 IE 的解决方案(因为特定于浏览器的解决方案总是脆弱的)。
回答by Raphael Serota
I would strongly recommend using howler.js for playing audio files. It has great compatibility across browsers and devices. It uses HTML5 audio when available, and falls back to older technologies when necessary.
我强烈建议使用 howler.js 来播放音频文件。它在浏览器和设备之间具有很好的兼容性。它在可用时使用 HTML5 音频,并在必要时回退到旧技术。
回答by Mario Corchero
HTML5 support on IE started on IE9 :(.
IE 上的 HTML5 支持始于 IE9 :(。
By the way, I am not sure if WAV is played by IE(I would not say so): http://en.wikipedia.org/wiki/HTML5_Audio
顺便说一句,我不确定 IE 是否可以播放 WAV(我不会这么说):http: //en.wikipedia.org/wiki/HTML5_Audio
回答by Fenton
The audio
tag is available in Internet Explorer 9 and above. You can check this using Can I Use - Audio.
该audio
标签在 Internet Explorer 9 及更高版本中可用。您可以使用Can I Use-Audio 进行检查。
The wav
format is supported by Firefox 3.6+, Safari 5+, Opera 10.5+ and Internet Explorer 9+ on the audio tag. You would need to add an MP3
source in addition to the wav
source to get Chrome support.
wav
音频标签上的 Firefox 3.6+、Safari 5+、Opera 10.5+ 和 Internet Explorer 9+ 支持该格式。MP3
除了源之外,您还需要添加wav
源才能获得 Chrome 支持。
To get backwards compatible support, you use the following - Flash element omitted for brevity.
要获得向后兼容的支持,请使用以下内容 - 为简洁起见省略了 Flash 元素。
<audio controls preload="auto" autobuffer>
<source src="sound.mp3" />
<source src="sound.ogg" />
<source src="sound.wav" />
<!-- now include flash fall back -->
</audio>
回答by VVictor
Encode your audio in mp4 format, instead of wav. This works for me in IE 11.
将您的音频编码为 mp4 格式,而不是 wav。这在 IE 11 中对我有用。