ManagedMediaSource: thuộc tính streaming

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.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính chỉ đọc streaming của giao diện ManagedMediaSource là một giá trị boolean cho biết liệu ứng dụng có nên chủ động tải và nối thêm dữ liệu media hay không.

Giá trị của thuộc tính này được cập nhật bởi thuật toán giám sát của tác nhân người dùng. Khi nó thay đổi, sự kiện startstreaming hoặc endstreaming tương ứng sẽ được kích hoạt.

Giá trị

Một giá trị boolean, ban đầu là false. Khi là true, tác nhân người dùng cần thêm dữ liệu để đảm bảo phát lại không bị gián đoạn. Khi là false, tác nhân người dùng đã có đủ dữ liệu được đệm và ứng dụng có thể dừng tải các phân đoạn mới.

Ví dụ

Kiểm tra trạng thái streaming

Ví dụ này tạo một ManagedMediaSource, gắn nó vào phần tử <video>, và ghi lại giá trị của streaming mỗi khi nó thay đổi giữa truefalse.

js
const mediaType = 'video/mp4; codecs="avc1.64001F, mp4a.40.2"';

if (ManagedMediaSource.isTypeSupported(mediaType)) {
  const video = document.createElement("video");
  const source = new ManagedMediaSource();

  video.controls = true;
  video.disableRemotePlayback = true;
  video.src = URL.createObjectURL(source);
  document.body.appendChild(video);

  console.log(source.streaming); // false

  source.addEventListener("startstreaming", () => {
    console.log(source.streaming); // true — start fetching data
  });

  source.addEventListener("endstreaming", () => {
    console.log(source.streaming); // false — stop fetching data
  });

  source.addEventListener("sourceopen", () => {
    source.addSourceBuffer(mediaType);
  });
}

Thông số kỹ thuật

Thông số kỹ thuật
Media Source Extensions™
# dom-managedmediasource-streaming

Tương thích trình duyệt

Xem thêm