Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74846

Html5 audio ios play event

$
0
0

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.

https://jsfiddle.net/pmw8fa5e/1/


Viewing all articles
Browse latest Browse all 74846

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>