Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  34] [ 6]  / answers: 1 / hits: 84294  / 14 Years ago, mon, february 14, 2011, 12:00:00

I would like to display the current time of of an html 5 audio element and the duration of that element. I've been looking over the internet but can't find a functional script which allows me to display how long the audio files is and what the time currently is e.g. 1:35 / 3:20.



Any one got any ideas :)?


More From » html

 Answers
23

Here's an example:



<audio id=track src=http://upload.wikimedia.org/wikipedia/commons/a/a9/Tromboon-sample.ogg
ontimeupdate=document.getElementById('tracktime').innerHTML = Math.floor(this.currentTime) + ' / ' + Math.floor(this.duration);>
<p>Your browser does not support the audio element</p>
</audio>
<span id=tracktime>0 / 0</span>
<button onclick=document.getElementById('track').play();>Play</button>


This should work in Firefox and Chrome, for other browsers you'll probably need to add alternative encodings.


[#93747] Friday, February 11, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
finn

Total Points: 154
Total Questions: 88
Total Answers: 82

Location: Lithuania
Member since Mon, Nov 16, 2020
4 Years ago
;