javascript - 异常的 HTML 音频竞争条件
问题描述
我正在尝试录制音频剪辑并创建一个用于播放的对象 URL。我希望在页面加载后立即发生这种情况,但是似乎存在竞争条件。Blob 总是被创建并充满数据,但有时audioURL
它是可播放的,有时不是。为什么会存在这种竞争条件?
const MicRecorder = require("mic-recorder-to-mp3");
this.recorder = new MicRecorder({
bitRate: 128,
});
this.recorder.start();
// wait for some button press.
this.recorder
.stop()
.getMp3()
.then(([buffer, blob]) => {
this.buffer = buffer;
this.blob = blob;
console.log(blob.arrayBuffer()); // The blob always prints and is full of data.
// Create Audio for playing
const audioUrl = URL.createObjectURL(this.blob);
console.log(audioUrl); // This audio Url is sometimes playable, sometimes not
this.audio = new Audio(audioUrl);
...
// Some button is clicked.
this.audio.play();
Uncaught (in promise) DOMException: The element has no supported sources.
解决方案
推荐阅读
- mysql - 如何使用其属性名称导出表?
- java - 当协议与 http 不同时,未使用 ApachePOI 在 Numbers 中添加超链接地址
- php - 方法覆盖并遵循 SOLID 原则
- java - 在 Postgres 中将 POJO 列表存储为 JSON 对象
- kendo-treeview - Kendo Treeview Angular - 加载完整的数据集
- groovy - CrafterCMS:找不到合适的 ClassLoader 可供抓取
- java - 如何向 Scala 提供 Java 回调(带有“void”返回类型)?
- hyperledger-fabric - 如何使用 grafana 监控 Hyperledger Fabric 网络?
- java - 在java中使用apache poi从xlsx读取多个表
- ios - 如何让 UIView 在 iOS 中“包装内容”?