【问题标题】:Javascript pause audio playing after x secondsJavascript 在 x 秒后暂停音频播放
【发布时间】:2017-04-28 16:08:19
【问题描述】:

我首先以秒为单位定义了音频播放的开始时间和结束时间

var a = document.getElementById("audioplayer");
a.addEventListener("progress", function () {
    if ($("#audioplayer")[0].currentTime > Math.round(Number(globalStart) + Number(globalDuration)))  {
        $("#audioplayer")[0].pause();
    }
}, true);

我想在当前时间达到 x 秒时停止播放音频

我该怎么做?

【问题讨论】:

  • 我找不到“正在播放”的活动

标签: javascript audio html5-audio


【解决方案1】:

您必须在 timeupdate

上添加事件监听器
a.addEventListener('timeupdate', function () {
    if (this.currentTime > Math.round(Number(globalStart) + Number(globalDuration)) && !this.paused)  {
        this.pause();
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 2021-03-30
    相关资源
    最近更新 更多