简体   繁体   English

Javascript-HTML5音频绑定事件

[英]Javascript - HTML5 Audio bind event

I am trying to bind an event where when the audio finished playing, it would fire a certain function, but however, when I bind the event it says aux.bind is not a function. 我正在尝试绑定一个事件,当音频播放完毕时,它将触发某个功能,但是,当我绑定事件时,它说aux.bind不是一个函数。

var aux = new Audio("file.mp3");
aux.bind("ended", function(e){
    aux.volume = 1.0;
});

I have even tried aux.on(...) and it does not work either. 我什至尝试了aux.on(...) ,它也不起作用。

UPDATE : I will require to unbind the event later after the "ended" has fired 更新我将需要在“结束”触发后取消绑定事件

Use the onended() event from the Audio object. 使用Audio对象的onended()事件。 Eg. 例如。

var aux = new Audio("file.mp3");
aud.play();
aud.onended = function() {
    alert("The audio has ended");
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM