Community
cancel
Showing results for 
Search instead for 
Did you mean: 
217 Views

addEventListener timeupdate not working?

Hello, im trying to use the timeupdate eventlistener for make a time music played, but time is not started.

The code im currently using is:

===HTML===
<span id="curtimeText">00:00</span>

===Javascript===
audio = new Audio();
audio.src = "http://streamRadioURL/;stream.mp3";
audio.addEventListener("timeupdate", function(){ seektimeupdate(); });

function seektimeupdate(){
	var curmins = Math.floor(audio.currentTime / 60);
	var cursecs = Math.floor(audio.currentTime - curmins * 60);
	if(cursecs < 10){ cursecs = "0"+cursecs; }
	if(curmins < 10){ curmins = "0"+curmins; }
	var waktu = curmins+":"+cursecs;
        alert(waktu);
}

This wont however work.

Thank you before.

Tags (2)
0 Kudos
1 Reply
217 Views

Update:

function seektimeupdate(){
	var curmins = Math.floor(audio.currentTime / 60);
	var cursecs = Math.floor(audio.currentTime - curmins * 60);
	if(cursecs < 10){ cursecs = "0"+cursecs; }
	if(curmins < 10){ curmins = "0"+curmins; }
	var waktu = curmins+":"+cursecs;
        $("#curtimeText").text(waktu);
}

 

Reply