SourceBuffer:updateend 事件
注意:此功能在 專用 Web Workers 中可用。
updateend 事件是 SourceBuffer 介面的一個事件,它表示 appendBuffer() 或 remove() 操作(不一定成功)已完成。updating 屬性會從 true 變為 false。此事件在 update、error 或 abort 事件之後觸發。
語法
在諸如 addEventListener() 之類的方法中使用事件名稱,或設定事件處理程式屬性。
js
addEventListener("updateend", (event) => { })
onupdateend = (event) => { }
事件型別
一個通用的 Event。
示例
在追加資料後處理 updateend 事件
本示例演示瞭如何處理 updateend 事件。請注意,我們分別處理每個完成事件,僅將 updateend 用於流的最終化。
js
const sourceBuffer = source.addSourceBuffer(mimeCodec);
sourceBuffer.addEventListener("abort", () => {
downloadStatus.textContent = "Canceled";
});
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-updateend |
| Media Source Extensions™ # dom-sourcebuffer-onupdateend |
瀏覽器相容性
載入中…