【问题标题】:Triggering Event When Audio Has Finished Playing音频播放完毕触发事件
【发布时间】:2016-03-18 18:43:12
【问题描述】:

我没有看到太多关于 HTML5 中 <audio> 标记的文档。我正在尝试在音频播放完毕时触发一个事件。

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!");

});

【问题讨论】:

    标签: javascript jquery html audio


    【解决方案1】:

    您不需要事件监听器,只需:

    var audio1 = document.getElementById("myAudio1");
    audio1.onended = function() {
        alert("audio playback has ended");
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多