MediaSource.sourceBuffers
MediaSource
接口的只读属性 sourceBuffers
返回一个 SourceBufferList
对象,该对象包含着与 MediaSource
关联的 SourceBuffer
对象列表。
值
一个 SourceBufferList
。
示例
以下片段基于 Nick Desaulniers 编写的一个简单示例(查看完整的在线演示,或者下载源代码进行进一步研究)。
js
function sourceOpen() {
//console.log(this.readyState); // open
const mediaSource = this;
const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
fetchAB(assetURL, function (buf) {
sourceBuffer.addEventListener("updateend", () => {
mediaSource.endOfStream();
console.log(mediaSource.sourceBuffers); // will contain the source buffer that was added above
video.play();
//console.log(mediaSource.readyState); // ended
});
sourceBuffer.appendBuffer(buf);
});
}
// …
规范
Specification |
---|
Media Source Extensions™ # dom-mediasource-sourcebuffers |
浏览器兼容性
BCD tables only load in the browser