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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.