知道什么时候“音频”标签HTML已经发挥了作用

Know when "audio" tag html has been play

本文关键字:作用 HTML 标签 什么时候 音频      更新时间:2023-09-26

我正在使用音频标签,我想要的是计算播放了多少次。

我的代码是这样的

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

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

您可能需要play事件,而不是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;
}