MediaSource: readyState プロパティ

Limited availability

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

readyStateMediaSource インターフェイスの読み取り専用プロパティで、現在の MediaSource の状態を表す列挙を返します。 3 つの可能な値は次のとおりです。

  • closed: ソースは現在メディア要素に取り付けられていません。
  • open: ソースはメディア要素に取り付けられ、 SourceBuffer オブジェクトを受信する準備ができています。
  • ended: ソースはメディア要素に取り付けられていますが、 MediaSource.endOfStream() の呼び出しを介してストリームが終了しています。

文字列です。

次のスニペットは、Nick Desaulniers によって書かれた簡単な例に基づいています(ライブで完全なデモを見るか、ソースをダウンロードしてさらに調査してください)。ここでは定義されていませんが、関数 getMediaSource()MediaSource を返します。

js
let mediaSource;

if ("MediaSource" in window && MediaSource.isTypeSupported(mimeCodec)) {
  mediaSource = getMediaSource();
  console.log(mediaSource.readyState); // closed
  video.src = URL.createObjectURL(mediaSource);
  mediaSource.addEventListener("sourceopen", sourceOpen);
} else {
  console.error(
    "サポートされていない MIME タイプまたはコーデック: ",
    mimeCodec,
  );
}

function sourceOpen() {
  console.log(this.readyState); // open
  const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
  fetchAB(assetURL, (buf) => {
    sourceBuffer.addEventListener("updateend", () => {
      mediaSource.endOfStream();
      video.play();
      console.log(mediaSource.readyState); // ended
    });
    sourceBuffer.appendBuffer(buf);
  });
}

仕様書

Specification
Media Source Extensions™
# dom-mediasource-readystate

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
readyState

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support

関連情報