SourceBuffer: abort 事件
注意:此功能在 專用 Web Workers 中可用。
SourceBuffer 介面的 abort 事件,當在 演算法仍在執行時呼叫 SourceBuffer.appendBuffer() 或 SourceBuffer.abort() 方法,導致緩衝區追加操作被中止時觸發。此時 SourceBuffer.remove() 屬性會從 updatingtrue 變為 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 |
瀏覽器相容性
載入中…