Html html5 <audio> 不在 IOS Safari 上播放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6288130/
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
html5 <audio> not playing on IOS Safari
提问by testndtv
I have an mp3 which plays correctly via the embed tag in older browsers, but for iPad, when I try to play the same mp3 via <audio>
, it says movie not supported. Is this a MIME type issue? This method works on desktop Safari.
我有一个 mp3,它可以通过旧浏览器中的 embed 标签正确播放,但对于 iPad,当我尝试通过 播放相同的 mp3 时<audio>
,它说不支持电影。这是 MIME 类型的问题吗?此方法适用于桌面 Safari。
How do I get it to play on Safari under IOS4.3?
如何让它在 IOS4.3 下的 Safari 上播放?
Here's my code:
这是我的代码:
var audio = document.createElement('audio');
audio.type = "audio/mpeg";
audio.src = audioUrl;
x.appendChild(audio);
audio.load();
audio.play();
回答by Anssi Moilanen
As of 4.x iOS no longer supports autoplay for html5 audio objects. See: Autoplay audio files on an iPad with HTML5
从 4.x 开始,iOS 不再支持 html5 音频对象的自动播放。请参阅:使用 HTML5 在 iPad 上自动播放音频文件
edit (2011-10-04): This was regarding to how the original posters code snippet was presented. If given code is not executed via an event triggered by user action (f.ex click), the audio won't play. If you have this code inside a function that is bound to click event on some button, it should work (haven't tested).
编辑(2011-10-04):这是关于原始海报代码片段的呈现方式。如果给定的代码不是通过用户操作(例如单击)触发的事件执行的,音频将不会播放。如果您在绑定到某个按钮上的单击事件的函数中包含此代码,则它应该可以工作(尚未测试)。
回答by Jacob Mouka
The issue is the load has to happen in a user-triggered event (button click, etc). I'm not sure which iOS version this is, but I confirmed it in 4.3.5. I've written up a bit more details and a possible workaround here:
问题是负载必须发生在用户触发的事件(按钮单击等)中。我不确定这是哪个 iOS 版本,但我在 4.3.5 中确认了它。我在这里写了更多细节和可能的解决方法:
Autoplay audio files on an iPad with HTML5
Edit: Apple's explanation: http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
编辑:苹果的解释:http: //developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
So the issue is iOS 4+
所以问题是 iOS 4+
回答by stack collision with heap
I have to add something to the answer by kinakuta
我必须在 kinakuta 的答案中添加一些内容
I tried the link in the comment to the answer apples html5 showcaseThe music plays with Firefox 16, Internet Explorer 9, Google Chrome 22 and Opera if you mask Opera as firefox.
我尝试了答案中的链接apples html5 展示如果您将 Opera 屏蔽为 firefox,则音乐可在 Firefox 16、Internet Explorer 9、Google Chrome 22 和 Opera 上播放。
But Apples OWN Demo DOES NOT WORK with Apple Safari 5.1.7 on my Machine because I don't have Quicktime on my machine. HTML5 Audio is not working very well with Safari, there are others having trouble with it. this can be irritation during development If one does not want quicktime installed on the computer.
但是 Apples OWN Demo 在我的机器上不适用于 Apple Safari 5.1.7,因为我的机器上没有 Quicktime。HTML5 音频在 Safari 上运行得不是很好,还有其他人遇到了问题。如果不想在计算机上安装 quicktime,这在开发过程中可能会很烦人。
回答by ajl
Note that if you are serving the content over https you need to have a valid certificate or it will not play on iOS devices (or on Safari on a Mac). You won't get an SSL error or any obvious SSL related messages -- it just won't work on iOS devices and Safari for the Mac, but will work for Chrome and Firefox (for example) on a Mac.
请注意,如果您通过 https 提供内容,您需要拥有有效证书,否则它将无法在 iOS 设备(或 Mac 上的 Safari)上播放。您不会收到 SSL 错误或任何明显的 SSL 相关消息——它只是不适用于 iOS 设备和 Mac 的 Safari,但适用于 Mac 上的 Chrome 和 Firefox(例如)。
See herefor a related question where SSL was the issue (as it was for me).
请参阅此处了解 SSL 是问题所在的相关问题(对我而言也是如此)。