【问题标题】:chrome adEventListner not wotking on notification soundchrome addEventListener 无法处理通知声音
【发布时间】:2019-08-17 21:04:33
【问题描述】:

我正在尝试在 chrome 上添加音频加载通知。 下面是我的 Js 代码。 它在 Firefox 上运行良好,但有时在 chrome 上它没有运行 m

错误

未捕获(承诺)DOMException

audio_notice = new Audio('http://www.sousound.com/music/healing/healing_01.mp3');
     audio_notice.autoplay = true;
    audio_notice.addEventListener('ended', function () {
        try {
            this.currentTime = 0;
            this.play();
        } catch (e) {
        }
    }, false);
    audio_notice.addEventListener('load', function () {
        try {
            this.play();
        } catch (e) {
        }
    }, true);

## LIve example ##

【问题讨论】:

    标签: javascript audio html5-audio


    【解决方案1】:

    我认为“加载”事件不正确,它不在list of compatible events 中。

    您可以改用loadeddata

    audio_notice.addEventListener('loadeddata', function () {
        try {
            this.play();
        } catch (e) {
        }
    }, true);
    

    【讨论】:

    • 我在使用你的代码 this.play() 时遇到这个错误;未捕获(承诺)DOMException
    • 我在 SO 上找到了这篇文章,我认为它很有帮助 stackoverflow.com/questions/40276718/…
    • 我在这里试过。 jsfiddle.net/lemonkazi/ohg2y47b 有时播放声音有时不播放。可能是镀铬问题。有没有其他方法可以设置自动播放
    • @LemonKazi 有几条信息here
    猜你喜欢
    • 2018-01-31
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多