知道“音频”标签html何时播放

时间:2011-10-14 15:40:04

标签: javascript html5 audio

我正在使用音频标签,我希望它可以计算播放了多少次。

我的代码是这样的:

<audio id="sound" controls="controls" onplaying="doing(this.id)">;
    <source src="path/filename" type="audio/wav/">; 
</audio>; 
<input type="text" id="numbers" value= "0" >

然后在javascript文件中

Var n=0;
function doing(onplaying)
{
    n = n+1;
    document.getElementById("numbers").value =  n;
}

但它不起作用,有人知道如何做到这一点,就像这样或以不同的方式。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

您可能想要play个活动,而不是playinghttp://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;
}