在页面上有audio标签,页面加载完用play()
方法开始播放,在微信里面可以正常播放,IOS和Android都没问题。但是在app里面不行,需要手动触发。用Safari和安卓的内置浏览器都不能自动播放。
IOS上微信内置浏览器不是调用Safari的吗,很奇怪为什么在微信可以播放,在Safari就不行
<audio src="music.mp3" id="audio"></audio>
<script>
window.onload = function() {
var audio = document.getElementById('audio');
audio.play();
}
</script>
PHP中文网2017-04-17 13:04:57
iOS中的Safari禁用了这种操作:
the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action
-https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW1
微信浏览器用的是自己的X5内核