【问题标题】:Know when "audio" tag html has been play知道“音频”标签 html 何时播放
【发布时间】:2011-10-14 15:40:04
【问题描述】:

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

我的代码是这样的:

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

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

【问题讨论】:

  • 请注意,在 HTML 中,您不需要用 ; 分隔代码行 - 那些 ;s 实际上会显示为文本。
  • 怎么不行?它会抛出您可以在控制台中看到的错误吗?

标签: javascript html audio


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    相关资源
    最近更新 更多