MediaSource.readyState

Limited availability

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

實驗性質: 這是一個實驗中的功能
此功能在某些瀏覽器尚在開發中,請參考兼容表格以得到不同瀏覽器用的前輟。

MediaSource 介面的唯讀屬性 readyState 回傳表示當前 MediaSource 狀態的列舉值。三種可能的值為:

  • closed: 來源 (source) 目前沒有附加到媒體元件 (media element) 。
  • open: 來源已經附加且可以接收 SourceBuffer 物件。
  • ended: 來源已經附加但是串流已經經由 MediaSource.endOfStream() 結束。

語法

js
var myReadyState = mediaSource.readyState;

回傳值

一個 DOMString

範例

以下片段是由 Nick Desaulniers 所撰寫的簡單範例(在此實際觀看,或者下載原始碼以更進一步研究)

js
if ("MediaSource" in window && MediaSource.isTypeSupported(mimeCodec)) {
  var mediaSource = new MediaSource();
  //console.log(mediaSource.readyState); // closed
  video.src = URL.createObjectURL(mediaSource);
  mediaSource.addEventListener("sourceopen", sourceOpen);
} else {
  console.error("Unsupported MIME type or codec: ", mimeCodec);
}

function sourceOpen(_) {
  //console.log(this.readyState); // open
  var mediaSource = this;
  var sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
  fetchAB(assetURL, function (buf) {
    sourceBuffer.addEventListener("updateend", function (_) {
      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

相關資料