Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the progress of buffered data in html5 audio?

Tags:

html5-audio

Using html5 audio tags with Ogg media files, how can I using javascript, retrieve how much data has been loaded on the client side (in realtime).

like image 592
Irfan Avatar asked Nov 06 '11 04:11

Irfan


1 Answers

<audio id="warp" preload="auto" controls>
    <source src="warp.mp3" type="audio/mp3">
    <source src="warp.ogg" type="audio/ogg">
</audio>
<script>
    var a = document.getElementById('warp');
    var t = a.currentTime;
    var d = a.duration;
    var z = a.buffered.end(a.buffered.length-1);
</script>

z is the number of seconds of audio that is currently buffered. t is the number of seconds from the beginning of the audio track where the playhead is. d is the total number of seconds of the audio track.

like image 147
Ahi Tuna Avatar answered Nov 09 '22 22:11

Ahi Tuna