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

瀏覽器相容性

另見