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

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 update của giao diện SourceBuffer báo hiệu việc hoàn thành thành công 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 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("update", (event) => { })

onupdate = (event) => { }

Loại sự kiện

Một [[[PH8]] chung chung.

Ví dụ

Xử lý sự kiện cập nhật sau khi thêm dữ liệu

Ví dụ này minh họa cách xử lý sự kiện update sau khi thao tác appendBuffer() thành công.

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

Specification
Media Source Extensions™
# dfn-update
Media Source Extensions™
# dom-sourcebuffer-onupdate

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

Xem thêm