这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

endOfStream() 方法在 MediaSource interface signals the end of the stream.

句法

mediaSource.endOfStream(endOfStreamError);
					

参数

endOfStreamError 可选
DOMString representing an error to throw when the end of the stream is reached. The possible values are:
  • network : Terminates playback and signals that a network error has occured. This can be used create a custom error handler related to media streams. For example, you might have a function that handles media chunk requests, separate from other network requests. When you make an XMLHttpRequest call for a media chunk, and onabort or onerror triggers, you might want to call endOfStream('network') , display a descriptive message in the UI, and maybe retry the network request immediately or wait until the network is back up (via some kind of polling.)
  • decode : Terminates playback and signals that a decoding error has occured. This can be used to indicate that a parsing error has occured while fetching media data; maybe the data is corrupt, or is encoded using a codec that the browser doesn't know how to decode.

返回值

undefined

异常

异常 解释
InvalidStateError MediaSource.readyState 不等于 open , or one or more of the SourceBuffer 对象在 MediaSource.sourceBuffers are being updated (i.e. their SourceBuffer.updating 特性为 true )。

范例

The following snippet is from a simple example written by Nick Desaulniers ( view the full demo live ,或 download the source for further investigation.)

var assetURL = 'frag_bunny.mp4';
// Need to be specific for Blink regarding codecs
// ./mp4info frag_bunny.mp4 | grep Codec
var mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
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);
  });
};
					

规范

规范 状态 注释
媒体源扩展
The definition of 'endOfStream()' in that specification.
推荐 初始定义。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
endOfStream Chrome 23 Edge 12 Firefox 42
42
25 — 42 注意事项 Disabled
Limited support to an allowed list of sites, for example YouTube, Netflix, and other popular streaming sites. The limitation was removed when Media Source Extensions was enabled by default in Firefox 42.
Disabled preference. To change preferences in Firefox, visit about:config.
IE 11 Opera 15 Safari 8 WebView Android 4.4.3 Chrome Android 25 Firefox Android 41 Opera Android 14 Safari iOS 不支持 No Samsung Internet Android 1.5

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: