Tuesday, 31 July 2018

HTML5 audio on IOS: how can currentTime be less than initial value?

I have to play a short fragment of bigger audio. I use currentTime to set starting point in time, and timeupdate event to stop audio when required.

I noticed that on few early timeupdate events sometimes currentTime is less than its initial value, despite there is (obviously) no "rewind" actions.

Here is code example:

var start = 1;
var end = 1.3;
var audio = document.getElementById('audio');
audio.addEventListener('timeupdate', function () {
   console.log(audio.currentTime);
   if (audio.currentTime < start || audio.currentTime > end) {
      audio.pause();
   }
});
audio.currentTime = start;
audio.play();

For example, output of console log can be this:

1
0.85
0.85
1
1.02
...

Here's an example.

Tested on iPad with iOS 11.4.1. This problem appears only on very short time ranges ~0.3sec.



from HTML5 audio on IOS: how can currentTime be less than initial value?

No comments:

Post a Comment