如何在移动设备上自动开始播放音频?

How to start play audio automaticly on mobyle device?

我创建音频标签,并使用 'autoplay' 启动音频。在桌面上运行良好,但在移动设备上运行不佳:ipad、winphon、android 4+...

<audio id="myAudio"  onerror="toConvert()" class="full-width"  src="{{ direct_link }}" controls autoplay  onpause="$('#play_ico').show()"   onplaying="$('#play_ico').hide()"></audio>

我尝试使用 jquery、js、canplay、canplaythrougt 和许多其他网络方法,但它们在移动设备上不起作用,但在桌面上运行良好....

如何开始在移动设备上播放音频?

我使用:goRatchet、Bootstrap 和 Django。

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload 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() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not.

This plays the movie: <input type="button" value="Play" onclick="document.myMovie.play()">

This does nothing on iOS: <body onload="document.myMovie.play()">

您可以参考:Playing Sounds with the Web Audio API.