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 |
浏览器兼容性
加载中…