Javascript HTML5 音频是否有 oncomplete 事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5092266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:37:20  来源:igfitidea点击:

Is there an oncomplete event for HTML5 audio?

javascripthtmlaudio

提问by james

Is there an oncompleteevent for HTML5 audio? I could not find anything on this. I am trying to play a sound after it completes.

是否有oncompleteHTML5 音频事件?我找不到任何关于此的信息。我正在尝试在完成后播放声音。

Well, specifically I am trying to play through an array of sounds one after the other.

好吧,特别是我试图一个接一个地播放一系列声音。

Thanks.

谢谢。

回答by the JinX

There is the endedevent . . .

ended事件。. .

http://dev.w3.org/html5/spec/Overview.html#event-media-ended

http://dev.w3.org/html5/spec/Overview.html#event-media-ended

Example:

例子:

var audioElement = document.getElementById("myAudio");

audioElement.addEventListener('ended', function() {
    // Audio has ended when this function is executed.
},false);

回答by Tom Sarduy

The correct way to to this is using the addEventListenerfunction:

正确的方法是使用该addEventListener函数:

audio.addEventListener('ended', PlayNext);