Web/API/SourceBuffer/abort

From Get docs

Draft This page is not complete.


This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.


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

Syntax

sourceBuffer.abort();

Parameters

None.

Return value

undefined.

Exceptions

Exception Explanation
InvalidStateError The MediaSource.readyState property of the parent media source is not equal to open, or this SourceBuffer has been removed from the MediaSource.

Example

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 is set to 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().)

Specifications

Specification Status Comment
Media Source ExtensionsThe definition of 'abort()' in that specification. Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
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

Full support 23

Edge

Full support 12

Firefox Full support 42


Full support 42


No support 25 — 42

Notes' Disabled'

Notes' 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' From version 25 until version 42 (exclusive): this feature is behind the media.mediasource.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

IE Full support 11

Notes'

Full support 11

Notes'

Notes' Only works on Windows 8+.

Opera

Full support 15

Safari

Full support 8

WebView Android

Full support 4.4.3

Chrome Android

Full support 25

Firefox Android

No support No

Opera Android

Full support 14

Safari iOS

No support No

Samsung Internet Android

Full support 2.0

Legend

Full support  
Full support
No support  
No support
See implementation notes.'
See implementation notes.
User must explicitly enable this feature.'
User must explicitly enable this feature.


See also