SourceBuffer Class

A source buffer of a MediaSource (https://w3c.github.io/media-source/#sourcebuffer): the scripts append the initialization segments and the media segments of a byte stream, which the media backend parses (MediaSegmentParser). The library keeps the position of the coded frames on the media timeline (not their data) in the track buffers, as specified: the coded frame processing algorithm (SourceBuffer.TimestampOffset, SourceBuffer.Mode, the append window, the coded frame groups, the frames that overlap), the removals, the eviction when the buffer is full, and the SourceBuffer.Buffered ranges.

public class SourceBuffer : EventTarget
Inheritance
EventTarget SourceBuffer

Properties

NameDescription
AppendWindowEndGets or sets the end of the append window, in seconds (https://w3c.github.io/media-source/#dom-sourcebuffer-appendwindowend): the coded frames that end after it are dropped.
AppendWindowStartGets or sets the start of the append window, in seconds (https://w3c.github.io/media-source/#dom-sourcebuffer-appendwindowstart): the coded frames that start before it are dropped.
AudioTracksGets the audio tracks created by the source buffer (https://w3c.github.io/media-source/#dom-sourcebuffer-audiotracks).
BufferedGets the time ranges that are buffered (https://w3c.github.io/media-source/#dom-sourcebuffer-buffered): the intersection of the ranges of the audio and video track buffers. The same object is returned while the ranges do not change. Throws an InvalidStateError when the source buffer is removed.
ModeGets or sets how the media segments are placed on the media timeline (https://w3c.github.io/media-source/#dom-sourcebuffer-mode). The setter throws an InvalidStateError when the source buffer is removed, is updating or is parsing a media segment, and a TypeError when the timestamps of the byte stream format are generated (the mode is always AppendMode.Sequence).
OnAbortGets or sets the event handler of the abort event.
OnErrorGets or sets the event handler of the error event.
OnUpdateGets or sets the event handler of the update event.
OnUpdateEndGets or sets the event handler of the updateend event.
OnUpdateStartGets or sets the event handler of the updatestart event.
TextTracksGets the text tracks created by the source buffer (https://w3c.github.io/media-source/#dom-sourcebuffer-texttracks): the list is always empty (the text tracks of the byte streams are not supported, as in the browsers).
TimestampOffsetGets or sets the offset applied to the timestamps of the next media segments, in seconds (https://w3c.github.io/media-source/#dom-sourcebuffer-timestampoffset).
UpdatingGets a value indicating whether an append or a removal is being processed (https://w3c.github.io/media-source/#dom-sourcebuffer-updating).
VideoTracksGets the video tracks created by the source buffer (https://w3c.github.io/media-source/#dom-sourcebuffer-videotracks).

AppendWindowEnd

SourceBuffer.cs

Gets or sets the end of the append window, in seconds (https://w3c.github.io/media-source/#dom-sourcebuffer-appendwindowend): the coded frames that end after it are dropped.

public double AppendWindowEnd { get; set; }

AppendWindowStart

SourceBuffer.cs

Gets or sets the start of the append window, in seconds (https://w3c.github.io/media-source/#dom-sourcebuffer-appendwindowstart): the coded frames that start before it are dropped.

public double AppendWindowStart { get; set; }

AudioTracks

SourceBuffer.cs

Gets the audio tracks created by the source buffer (https://w3c.github.io/media-source/#dom-sourcebuffer-audiotracks).

public AudioTrackList AudioTracks { get; }

Gets the time ranges that are buffered (https://w3c.github.io/media-source/#dom-sourcebuffer-buffered): the intersection of the ranges of the audio and video track buffers. The same object is returned while the ranges do not change. Throws an InvalidStateError when the source buffer is removed.

public TimeRanges Buffered { get; }

Gets or sets how the media segments are placed on the media timeline (https://w3c.github.io/media-source/#dom-sourcebuffer-mode). The setter throws an InvalidStateError when the source buffer is removed, is updating or is parsing a media segment, and a TypeError when the timestamps of the byte stream format are generated (the mode is always AppendMode.Sequence).

public AppendMode Mode { get; set; }

Gets or sets the event handler of the abort event.

public Action<Event>? OnAbort { get; set; }

Gets or sets the event handler of the error event.

public Action<Event>? OnError { get; set; }

Gets or sets the event handler of the update event.

public Action<Event>? OnUpdate { get; set; }

OnUpdateEnd

SourceBuffer.cs

Gets or sets the event handler of the updateend event.

public Action<Event>? OnUpdateEnd { get; set; }

OnUpdateStart

SourceBuffer.cs

Gets or sets the event handler of the updatestart event.

public Action<Event>? OnUpdateStart { get; set; }

TextTracks

SourceBuffer.cs

Gets the text tracks created by the source buffer (https://w3c.github.io/media-source/#dom-sourcebuffer-texttracks): the list is always empty (the text tracks of the byte streams are not supported, as in the browsers).

public TextTrackList TextTracks { get; }

TimestampOffset

SourceBuffer.cs

Gets or sets the offset applied to the timestamps of the next media segments, in seconds (https://w3c.github.io/media-source/#dom-sourcebuffer-timestampoffset).

public double TimestampOffset { get; set; }

Gets a value indicating whether an append or a removal is being processed (https://w3c.github.io/media-source/#dom-sourcebuffer-updating).

public bool Updating { get; }

VideoTracks

SourceBuffer.cs

Gets the video tracks created by the source buffer (https://w3c.github.io/media-source/#dom-sourcebuffer-videotracks).

public VideoTrackList VideoTracks { get; }

Methods

NameDescription
Abort()Aborts the current segment and resets the segment parser (https://w3c.github.io/media-source/#dom-sourcebuffer-abort): a pending append is aborted (abort, updateend), and the append window is reset.
AppendBuffer(ReadOnlySpan<byte>)Appends segment data (https://w3c.github.io/media-source/#dom-sourcebuffer-appendbuffer): the data is parsed in a task (updatestart, then update or error, then updateend). Throws an InvalidStateError when the source buffer is removed or updating, or when the media element has an error, and a QuotaExceededError when the buffer is full.
ChangeType(string)Changes the MIME type of the next appended bytes (https://w3c.github.io/media-source/#dom-sourcebuffer-changetype): the next segment must be an initialization segment. Throws a TypeError for an empty type and a NotSupportedError when the media backend does not support the type.
Remove(double, double)Removes the media of a time range (https://w3c.github.io/media-source/#dom-sourcebuffer-remove), in a task (updatestart, update, updateend).

Aborts the current segment and resets the segment parser (https://w3c.github.io/media-source/#dom-sourcebuffer-abort): a pending append is aborted (abort, updateend), and the append window is reset.

public void Abort()

AppendBuffer(ReadOnlySpan<byte>)

SourceBuffer.cs

Appends segment data (https://w3c.github.io/media-source/#dom-sourcebuffer-appendbuffer): the data is parsed in a task (updatestart, then update or error, then updateend). Throws an InvalidStateError when the source buffer is removed or updating, or when the media element has an error, and a QuotaExceededError when the buffer is full.

public void AppendBuffer(ReadOnlySpan<byte> data)

ChangeType(string)

SourceBuffer.cs

Changes the MIME type of the next appended bytes (https://w3c.github.io/media-source/#dom-sourcebuffer-changetype): the next segment must be an initialization segment. Throws a TypeError for an empty type and a NotSupportedError when the media backend does not support the type.

public void ChangeType(string type)

Remove(double, double)

SourceBuffer.cs

Removes the media of a time range (https://w3c.github.io/media-source/#dom-sourcebuffer-remove), in a task (updatestart, update, updateend).

public void Remove(double start, double end)