草案
此页面不完整。

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

abort() 方法在 SourceBuffer interface aborts the current segment and resets the segment parser.

句法

sourceBuffer.abort();
					

参数

None.

返回值

undefined .

异常

异常 解释
InvalidStateError MediaSource.readyState property of the parent media source is not equal to open , or this SourceBuffer has been removed from the MediaSource .

范例

The spec description of abort() is somewhat confusing — consider for example step 1 of reset parser state . The MSE API is fully asynchronous, but this step seems to suggest a synchronous (blocking) operation, which doesn't make sense.

Saying that, current implementations can be useful in certain situations, when you want to stop the current append (or whatever) operation occuring on a sourcebuffer, and then immediately start performing operations on it again. For example, consider this code:

sourceBuffer.addEventListener('updateend', function (_) {
  ...
});
sourceBuffer.appendBuffer(buf);
					

Let's say that after the call to appendBuffer BUT before the updateend event fires (i.e. a buffer is being appended but the operation has not yet completed) a user "scrubs" the video seeking to a new point in time.  In this case you would want to manually call abort() on the source buffer to stop the decoding of the current buffer, then fetch and append the newly requested segment that relates to the current new position of the video.

You can see something similar in action in Nick Desaulnier's bufferWhenNeeded demo — in line 48, an event listener is added to the playing video so a function called seek() is run when the seeking event fires. In lines 92-101, the seek() function is defined — note that abort() is called if MediaSource.readyState 被设为 open , which means that it is ready to receive new source buffers — at this point it is worth aborting the current segment and just getting the one for the new seek position (see checkBuffer() and getCurrentSegment() )。

规范

规范 状态 注释
媒体源扩展
The definition of 'abort()' 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
abort Chrome 23 Edge 12 Firefox 42 IE 11 Opera 15 Safari 8 WebView Android 4.4.3 Chrome Android 25 Firefox Android 不支持 No Opera Android 14 Safari iOS 不支持 No Samsung Internet Android 2.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

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

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

另请参阅

元数据

  • 最后修改: