如何检测HTML5音频播放完毕(不止一次)? [英] How do you detect when HTML5 audio has finished playing (more than once)?

查看:114
本文介绍了如何检测HTML5音频播放完毕(不止一次)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检测标签播放完mp3时遇到问题。当我做这样的事情时:

  myAudio.addEventListener(ended,function()
{
警报(结束);
});

仅在第一次播放音频时出现。当我再次播放音频时,没有任何反应。同样的事情发生在我使用 onended = doThis(); 方法时。我听说也许有办法在jQuery中做到这一点,但我一直无法使它工作。我也听说有可能通过在每次播放mp3时更改音频div id 来修复它,但这不适用于我,因为我需要 id 保持不变。



有没有人有任何想法?
<在 .currentTime 基础上创建结束事件的解决方案 >属性。
http://w3c.github。 io / html / semantics-embedded-content.html#eventdef-media-ended



因此,您只需设置 .currentTime 再次归零。

  myAudio.addEventListener(ended,function() {
myAudio.currentTime = 0;
console.log(ended);
});


I am having a problem detecting when an tag is finished playing an mp3. When I do something like this:

     myAudio.addEventListener("ended", function() 
     {
          alert("ended");
     });

It only occurs the first time the audio is played. When I play the audio again, nothing happens. The same thing happens when I use the onended=doThis(); method. I've heard maybe there is a way to do it in jQuery, but I haven't been able to get it to work. I've also heard there might be a way to fix it by changing the audio div id every time the mp3 is played, but this doesn't work for me because I need the id to stay the same.

Did anyone get any ideas?

解决方案

The ended event is created based on .currentTime attribute. http://w3c.github.io/html/semantics-embedded-content.html#eventdef-media-ended

So, all you have to do is set the .currentTime to zero again.

myAudio.addEventListener("ended", function(){
     myAudio.currentTime = 0;
     console.log("ended");
});

这篇关于如何检测HTML5音频播放完毕(不止一次)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆