How to start play audio automaticly on mobyle device?

112 Views Asked by At

I crate audio tag, and use 'autoplay' to start audio. On Descktop work well, but not work on mobile device: 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>

I tried using jquery, js, canplay, canplaythrougt and many other methods from web, but they dont work in mobile and working well on descktop....

How can I start playing audio on mobile device?

I use: goRatchet, Bootstrap and Django.

1

There are 1 best solutions below

4
anonystick On BEST ANSWER

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()">

You can ref: Playing Sounds with the Web Audio API.