SourceBuffer: abort 事件
注意:此功能在 专用 Web Workers 中可用。
SourceBuffer 接口的 abort 事件,当在 算法仍在运行时调用 SourceBuffer.appendBuffer() 或 SourceBuffer.abort() 方法,导致缓冲区追加操作被中止时触发。此时 SourceBuffer.remove() 属性会从 updatingtrue 变为 false。此事件会在 事件之前触发。updateend
语法
在诸如 addEventListener() 之类的方法中使用事件名称,或设置事件处理程序属性。
js
addEventListener("abort", (event) => { })
onabort = (event) => { }
事件类型
一个通用的 Event。
示例
中止追加操作
本示例演示了如何中止追加操作并处理 abort 事件。
js
const sourceBuffer = source.addSourceBuffer(mimeCodec);
sourceBuffer.addEventListener("abort", () => {
downloadStatus.textContent = "Canceled";
});
sourceBuffer.addEventListener("update", () => {
downloadStatus.textContent = "Done";
});
sourceBuffer.addEventListener("updateend", () => {
source.endOfStream();
});
cancelButton.addEventListener("click", () => {
if (sourceBuffer.updating) {
sourceBuffer.abort();
}
});
downloadStatus.textContent = "Downloading...";
fetch(assetURL)
.then((response) => response.arrayBuffer())
.then((data) => {
downloadStatus.textContent = "Decoding...";
sourceBuffer.appendBuffer(data);
});
规范
| 规范 |
|---|
| Media Source Extensions™ # dfn-abort |
| Media Source Extensions™ # dom-sourcebuffer-onabort |
浏览器兼容性
加载中…