Know when "audio" tag html has been play
I'm using audio tags, what I want it开发者_JS百科's to count how many times has been played.
My code it's like this:
<audio id="sound" controls="controls" onplaying="doing(this.id)">;
<source src="path/filename" type="audio/wav/">;
</audio>;
<input type="text" id="numbers" value= "0" >
Then in a javascript file
Var n=0;
function doing(onplaying)
{
n = n+1;
document.getElementById("numbers").value = n;
}
But it does not work, does someone know how to do this, like this or in a different way. Thanks in advance.
You probably want the play
event, not playing
: http://jsfiddle.net/a84rC/.
document.getElementById("sound").addEventListener('play', doing); // bind event
var n = 0;
function doing() {
n++; // increase (this is a shortcut to n = n + 1)
document.getElementById("numbers").value = n;
}
精彩评论