SourceBuffer: hủy bỏ sự kiện

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available in Dedicated Web Workers.

Sự kiện abort của giao diện SourceBuffer được kích hoạt khi việc thêm bộ đệm bị hủy bỏ, vì phương thức SourceBuffer.abort() hoặc SourceBuffer.remove() được gọi trong khi thuật toán SourceBuffer.appendBuffer() vẫn đang chạy. Thuộc tính updating chuyển đổi từ true sang false. Sự kiện này được kích hoạt trước sự kiện updateend.

Cú pháp

Sử dụng tên sự kiện trong các phương thức như addEventListener() hoặc đặt thuộc tính xử lý sự kiện.

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

onabort = (event) => { }

Loại sự kiện

Một Event chung.

Ví dụ

Hủy bỏ thao tác chắp thêm

Ví dụ này minh họa cách hủy bỏ thao tác chắp thêm và xử lý sự kiện 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);
  });

Thông số kỹ thuật

Specification
Media Source Extensions™
# dfn-abort
Media Source Extensions™
# dom-sourcebuffer-onabort

Khả năng tương thích của trình duyệt

Xem thêm