I'm looking for a way to make html5 audio play as soon as button is clicked. Right now, it does work; but not very reliably.
My file is a 300Kb MP3 (128Kbps) that is hosted on AWS Cloudfront.
<audio id="i-audio" src="https://cdn/url/to/i-audio.mp3" preload="auto" type="audio/mp3"></audio>
this.iAudio = document.getElementById('i-audio');
$("#button").on('click', function() {
this.iAuido.play();
});
I learn that play()
will return a promise; and I'm not sure how can I be sure that audio plays all the time; reliably.
Right now, the play would work at random times or just throw an error.