search

Home  >  Q&A  >  body text

html5 - audio音频自动播放问题

在页面上有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>
伊谢尔伦伊谢尔伦2767 days ago549

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:04:57

    TryautoplayAttributes

    <audio src="music.mp3" autoplay="autoplay"></audio>

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:04:57

    Safari on iOS has this disabled:

    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

    WeChat browser uses its own X5 kernel

    reply
    0
  • Cancelreply