SourceBuffer:update 事件

可用性有限

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

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

SourceBuffer 接口的 update 事件表示 SourceBuffer.appendBuffer()SourceBuffer.remove() 操作成功完成。 updating 属性从 true 变为 false。此事件在 updateend 事件之前触发。

语法

在诸如 addEventListener() 之类的方法中使用事件名称,或设置事件处理程序属性。

js
addEventListener("update", (event) => { })

onupdate = (event) => { }

事件类型

一个通用的 Event

示例

追加数据后处理 update 事件

本示例演示了如何在成功执行 appendBuffer() 操作后处理 update 事件。

js
const sourceBuffer = source.addSourceBuffer(mimeCodec);
sourceBuffer.addEventListener("error", () => {
  downloadStatus.textContent = "Error occurred during decoding";
});
sourceBuffer.addEventListener("update", () => {
  downloadStatus.textContent = "Done";
});
sourceBuffer.addEventListener("updateend", () => {
  source.endOfStream();
});
downloadStatus.textContent = "Downloading...";
fetch(assetURL)
  .then((response) => response.arrayBuffer())
  .then((data) => {
    downloadStatus.textContent = "Decoding...";
    sourceBuffer.appendBuffer(data);
  });

规范

规范
Media Source Extensions™
# dfn-update
Media Source Extensions™
# dom-sourcebuffer-onupdate

浏览器兼容性

另见