使用 iOS 5 Mobile Safari 自动播放音频,还有解决方法吗?
我们都知道 Apple 不允许使用 Mobile Safari 在 html5 音频标签上自动播放。 iOS 4 的解决方法是使用带有 mp3 src 的 iframe。苹果似乎已经在 iOS 5 上修复了这个问题。
<html>
<body>
iframe mp3 autoplay test
<iframe src='iframe.mp3' width='0px' height='0px' scrolling='no'></iframe>
</body>
</html>
这适用于 iOS 4.3.1,但不适用于 5.0.1。
还有什么解决方法吗?或者苹果终于修复了所有自动播放漏洞吗?
We all know Apple doesn't allow autoplay on html5 audio tags with Mobile Safari. The workaround for iOS 4 was to use an iframe with an mp3 src. Apple seems to have patched this on iOS 5.
<html>
<body>
iframe mp3 autoplay test
<iframe src='iframe.mp3' width='0px' height='0px' scrolling='no'></iframe>
</body>
</html>
This works on iOS 4.3.1, but not on 5.0.1.
Any workarounds left, or has Apple finally patched all the autoplay loopholes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案可能就在这篇文章中,似乎没有其他对你有用。
在 iOS 和 Android 中播放声音文件
The answer might be inside of this post here, of nothing else seems to work for you.
Play sound file in iOS and Android
实际上,苹果已经禁用了移动 Safari 的自动播放功能。
“在 iPhone 操作系统(适用于所有设备,包括 iPad)上的 Safari 中,用户可能使用蜂窝网络并按数据单位付费,自动缓冲和自动播放被禁用。在用户启动之前不会加载任何数据。这意味着JavaScript play() 和 load() 方法在用户启动播放之前也处于非活动状态,除非 play() 方法是由用户操作触发的。换句话说,用户启动的“播放”按钮有效,但 onLoad 播放事件无效。 ”
可以通过首先加载视频然后伪造用户点击事件来完成,如以下链接所述
查看此链接以获取解决方法,
http://roblaplaca.com/blog/2010/04/14/ipad-and-iphone-html5-video-autoplay/
查看本页源代码
http://www.roblaplaca.com/examples/html5AutoPlay/
Actually Apple have disabled the auto play feature for mobile safari.
"In Safari on iPhone OS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, autobuffering and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad play event does not."
It can be done by first loading the video and then faking the user click event as described in the following link
Have a look at this link for a work around,
http://roblaplaca.com/blog/2010/04/14/ipad-and-iphone-html5-video-autoplay/
view source code of this page
http://www.roblaplaca.com/examples/html5AutoPlay/
这使用了 jQuery,并且大多数用户在加载页面后都会触摸屏幕。
通过使用 .one,声音仅在第一次触摸屏幕时“自动启动”。
This uses jQuery and the point that most users will touch the screen after loading a page.
By using .one the sound "autostarts" only the first time one touches the screen..