在iPad上使用HTML5自动播放音频文件 [英] Autoplay audio files on an iPad with HTML5
问题描述
我试图得到一个音频文件,在Safari自动播放在iPad上。如果我使用Safari去的网页在我的Mac,它的罚款。在iPad上,自动播放不工作。
I'm trying to get an audio file to autoplay in Safari on an iPad. If I go to the page using Safari on my Mac, it's fine. On the iPad, autoplay does not work.
推荐答案
更新:这是一个黑客,它不是在IOS 4.X以上工作了。在IOS 3.2.X这一个工作。
UPDATE: This is a hack and it's not working anymore on IOS 4.X and above. This one worked on IOS 3.2.X.
这不是真的。苹果不希望自动播放,因为你可以在移动网络使用流量的高大写金额的iPad上的视频和音频。我不会用自动播放在线内容。对于离线HTML网站这是一个很大的特点和多数民众赞成什么,我已经使用了。
It's not true. Apple doesn't want to autoplay video and audio on IPad because of the high amout of traffic you can use on mobile networks. I wouldn't use autoplay for online content. For Offline HTML sites it's a great feature and thats what I've used it for.
下面是一个假的JavaScript点击的解决方案: http://www.roblaplaca.com/examples / html5AutoPlay /
Here is a "javascript fake click" solution: http://www.roblaplaca.com/examples/html5AutoPlay/
复制和放大器;从网站上粘贴code:
Copy & Pasted Code from the site:
<script type="text/javascript">
function fakeClick(fn) {
var $a = $('<a href="#" id="fakeClick"></a>');
$a.bind("click", function(e) {
e.preventDefault();
fn();
});
$("body").append($a);
var evt,
el = $("#fakeClick").get(0);
if (document.createEvent) {
evt = document.createEvent("MouseEvents");
if (evt.initMouseEvent) {
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
}
}
$(el).remove();
}
$(function() {
var video = $("#someVideo").get(0);
fakeClick(function() {
video.play();
});
});
</script>
这是不是我的源泉。我发现这个前一段时间和测试code在iPad和IPhone与IOS 3.2.X。
This is not my source. I've found this some time ago and tested the code on an IPad and IPhone with IOS 3.2.X.
这篇关于在iPad上使用HTML5自动播放音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!