SourceBuffer: cập nhật sự kiện cuối

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 updateend của giao diện SourceBuffer báo hiệu sự hoàn thành (không nhất thiết thành công) của thao tác appendBuffer() hoặc remove(). Thuộc tính updating chuyển đổi từ true sang false. Sự kiện này được kích hoạt sau các sự kiện update, error hoặc abort.

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("updateend", (event) => { })

onupdateend = (event) => { }

Loại sự kiện

Một [[[PH10]] chung chung.

Ví dụ

Xử lý sự kiện updateend sau khi thêm dữ liệu

Ví dụ này minh hoạ cách xử lý sự kiện updateend. Lưu ý rằng chúng tôi xử lý riêng từng sự kiện hoàn thành và chỉ sử dụng updateend để hoàn tất luồng.

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

Thông số kỹ thuật

Specification
Media Source Extensions™
# dfn-updateend
Media Source Extensions™
# dom-sourcebuffer-onupdateend

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

Xem thêm