HTML5 音频在 Chrome 达到其持续时间之前自动停止

HTML5 audio stopping automatically before reaching its duration in Chrome

我有一个 Angular 2 项目正在生产中一段时间​​,我被告知最近某些功能在 Chrome 中无法正常工作。 Safari 运行良好。

经过一些调查,我意识到问题是音频元素 "ended" 事件没有被触发。 我正在打印 currentTime / Duration 并且它们都以随机的完成百分比自动停止。 例如

我完全不知道是什么突然导致了这种情况。有什么想法吗?

        let el = <HTMLMediaElement>document.getElementById(id);

        this.audio.src = <string>(<HTMLSourceElement>el.children[0].getAttribute("src"));
        this.audio.load();
        this.audio.play();


        this.audio.onended = function() {
            ...// THIS NEVER RUNS
        }
        this.audio.ontimeupdate = function() {
            console.log(this.currentTime, this.duration);

            ...// THIS DOES BUT currentTime never reaches duration
        }

更新: 我当时正在使用 Chrome 最新版本 64.0.3282.140 进行测试,当我降级到版本 63 时,问题就消失了...

这是由于 Chrome 更新中的错误导致其音频播放器在再现 "damaged" mp3 文件时出现这种行为。

讨论得更深入 here and on this

修复文件的推荐方法是:

  • mp3val -f(对我不起作用)
  • 用 lame 命令重新编码(对我有用)

根据 chromium 错误线程,它将在版本 66 中修复。