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

标签 html angular google-chrome html5-audio

我有一个 Angular 2 项目已经投入生产一段时间了,我被告知最近某些功能在 Chrome 中无法正常工作。 Safari 工作正常。

经过一番调查,我意识到问题是音频元素“结束”事件没有被触发。 我正在打印当前时间/持续时间,并且所有这些都会自动以随机的完成百分比停止。 例如

enter image description here

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

        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 更新中的一个错误引起的,该错误导致其音频播放器在再现“损坏的”mp3 文件时出现这种行为。

更深入地讨论了here对此stackoverflow thread .

修复文件的推荐方法是:

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

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

关于HTML5 音频在 Chrome 中达到其持续时间之前会自动停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48711658/

相关文章:

angular - 使用 Observable<void> 或 Observable<any> 发出 `null` 值?

javascript - 是否可以从弹出窗口更改 Chrome 扩展程序的设置?

html - 将页脚文本居中对齐 - Bootstrap

javascript - 如何使用 JavaScript 设置函数参数?

css - 在 NgStyle 中设置高度的 TypeScript 函数不起作用

Angular 2 : How to display data in html format in angular2 data binding?

asp.net - 来自 Visual Studio 调试的 localhost 的 ERR_SSL_PROTOCOL_ERROR

google-chrome - 带有永久过滤器的 Google 搜索

html - Bootstrap 的容器是否会在特定的浏览器宽度下停止提供边框?

javascript - 在子悬停时更改父 css