开发者

Know when "audio" tag html has been play

开发者 https://www.devze.com 2023-04-12 21:29 出处:网络
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:

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号