SourceBuffer: abort 事件

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

注意:此功能在 专用 Web Workers 中可用。

SourceBuffer 接口的 abort 事件,当在 SourceBuffer.appendBuffer() 算法仍在运行时调用 SourceBuffer.abort()SourceBuffer.remove() 方法,导致缓冲区追加操作被中止时触发。此时 updating 属性会从 true 变为 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

浏览器兼容性

另见