I am trying to detect when audio starts playing on ios. The problem is that play, playing events fire immediatelly when I press play but audio start playing couple seconds later. I am using ~ 5mb audio file.
Why is there such delay between these evets and audio start, and how can I detect when sound actually starts?
document.getElementById('audio').addEventListener("play", play, false);
document.getElementById('audio').addEventListener("playing", playing, false);
function play() {
var h = document.createElement("H1");
var t = document.createTextNode('play');
h.appendChild(t);
document.body.appendChild(h);
}
function playing() {
var h = document.createElement("H1");
var t = document.createTextNode('playing');
h.appendChild(t);
document.body.appendChild(h);
}
<audio id="audio" controls preload="auto"><source src="https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_5MG.mp3" type="audio/mpeg" /></audio>
Here is jsfiddle, you can check on ipad.