SourceBuffer: sự kiện lỗi

Khả dụng hạn chế

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 error của giao diện SourceBuffer được kích hoạt khi xảy ra lỗi trong quá trình xử lý thao tác appendBuffer(). Điều này có thể xảy ra, ví dụ: nếu dữ liệu được thêm vào không ở định dạng mong muốn, SourceBuffer ở trạng thái không hợp lệ hoặc tác nhân người dùng không thể xử lý dữ liệu. 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("error", (event) => { })

onerror = (event) => { }

Loại sự kiện

Một Event chung.

Ví dụ

Xử lý lỗi trong quá trình addBuffer()

Ví dụ này trình bày cách xử lý các lỗi xảy ra trong thao tác appendBuffer().

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);
  });

Thông số kỹ thuật

Thông số kỹ thuật
Media Source Extensions™
# dfn-error
Media Source Extensions™
# dom-sourcebuffer-onerror

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

Xem thêm