大网数据广告活动
Web 标准与前端开发

SourceBuffer: abort() method

· 52CE 我爱测

Media Source Extensionswindow_and_dedicated

Media Source Extensionswindow_and_dedicated

The abort() method of the SourceBuffer interface aborts the current segment and resets the segment parser.

Syntax

abort()

Parameters

None.

Return value

None (undefined).

Exceptions

  • InvalidStateError DOMException
    • : Thrown if the MediaSource.readyState property of the parent media source is not equal to open, or this SourceBuffer has been removed from the MediaSource.

Examples

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 occurring on a source buffer, and then immediately start performing operations on it again. For example, consider this code:

sourceBuffer.addEventListener("updateend", (ev) => {
  // …
});

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.

Specifications

Browser compatibility

See also

  • MediaSource
  • SourceBufferList

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。