我没有看到很多关于 <audio>
的文档HTML5 中的标签。我正在尝试在音频播放完毕后触发一个事件。
HTML:
<audio id="audio">
<source src="'.$query['audioPronunciation'].'" type="audio/mp3">
Your browser does not support the audio element.
</audio>
JavaScript/jQuery 播放和暂停:
function audio() {
if ($("#audioControl").hasClass("glyphicon-play")) {
$("#audioControl").addClass("glyphicon-pause").removeClass("glyphicon-play");
$("#audio").trigger("play");
} else if ($("#audioControl").hasClass("glyphicon-pause")) {
$("#audioControl").removeClass("glyphicon-pause").addClass("glyphicon-play");
$("#audio").trigger("pause");
}
}
JavaScript/jQuery,“结束时”
$("#audio").addEventListener('ended', function() {
alert("Audio has finished playing!");
});
最佳答案
您不需要事件监听器,只需:
var audio1 = document.getElementById("myAudio1");
audio1.onended = function() {
alert("audio playback has ended");
};
关于javascript - 音频播放完毕触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34247487/