html5在 Android / IOS上不能自动播放
试了很多办法都不能让html5在手机上自动播放音乐或视频。在PC上是可以滴。据说是专门弄成这样地,目的是为了限制手机流量。
Audio/video autoplay is not allowed on iPhone, iPad and Android. It’s a limit from the device, and there is no way to bypass it.
试过的:
1.
<audio id="audio1" autobuffer autoplay loop >
<source src="../bell02.mp3" type="audio/mpeg" />
</audio>
2.
<embed mastersound name="sound1" src="../bell02.mp3" volume="100" hidden="true" autostart="true">
3.
<html>
<audio id="audio1" autobuffer autoplay loop >
<source src="../bell02.mp3" type="audio/mpeg" />
</audio>
<a href="#" id="play-button">play!</a>
<script>
var audio = document.getElementById('audio1');
var button = document.getElementById('play-button');
//- 按 play 出声:
button.addEventListener('click',function(){
audio.play();
});
//--时间中断不出声:
setTimeout(function() { audio.play(); }, 2000 );
</script>
4.
<script>
var audio = new Audio('"../bell02.mp3');
audio.play();
</script>
-----全都不行(PC上可以)