Skip to main content

SourceBuffer

The SourceBuffer interface represents a chunk of media to be passed into an HTMLMediaElement and played, via a MediaSource object. This can be made up of one or several media segments.

MDN Reference

Extends

Methods

abort()

abort(): void;

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

MDN Reference

Returns

void


addEventListener()

Call Signature

addEventListener<K>(
type,
listener,
options?
): void;

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Type Parameters
Type Parameter
K extends keyof SourceBufferEventMap
Parameters
ParameterType
typeK
listener(this, ev) => any
options?boolean | AddEventListenerOptions
Returns

void

Overrides

EventTarget.addEventListener

Call Signature

addEventListener(
type,
listener,
options?
): void;

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Parameters
ParameterType
typestring
listenerEventListenerOrEventListenerObject
options?boolean | AddEventListenerOptions
Returns

void

Overrides
EventTarget.addEventListener

appendBuffer()

appendBuffer(data): void;

The appendBuffer() method of the SourceBuffer interface appends media segment data from an ArrayBuffer, a TypedArray or a DataView object to the SourceBuffer.

MDN Reference

Parameters

ParameterType
dataBufferSource

Returns

void


changeType()

changeType(type): void;

The changeType() method of the SourceBuffer interface sets the MIME type that future calls to appendBuffer() should expect the new media data to conform to. This makes it possible to change codecs or container type mid-stream.

MDN Reference

Parameters

ParameterType
typestring

Returns

void


dispatchEvent()

dispatchEvent(event): boolean;

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

MDN Reference

Parameters

ParameterType
eventEvent

Returns

boolean

Inherited from

EventTarget.dispatchEvent


remove()

remove(start, end): void;

The remove() method of the SourceBuffer interface removes media segments within a specific time range from the SourceBuffer. This method can only be called when SourceBuffer.updating equals false. If SourceBuffer.updating is not equal to false, call SourceBuffer.abort().

MDN Reference

Parameters

ParameterType
startnumber
endnumber

Returns

void


removeEventListener()

Call Signature

removeEventListener<K>(
type,
listener,
options?
): void;

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Type Parameters
Type Parameter
K extends keyof SourceBufferEventMap
Parameters
ParameterType
typeK
listener(this, ev) => any
options?boolean | EventListenerOptions
Returns

void

Overrides

EventTarget.removeEventListener

Call Signature

removeEventListener(
type,
listener,
options?
): void;

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Parameters
ParameterType
typestring
listenerEventListenerOrEventListenerObject
options?boolean | EventListenerOptions
Returns

void

Overrides
EventTarget.removeEventListener

Properties

appendWindowEnd

appendWindowEnd: number;

The appendWindowEnd property of the SourceBuffer interface controls the timestamp for the end of the append window, a timestamp range that can be used to filter what media data is appended to the SourceBuffer. Coded media frames with timestamps within this range will be appended, whereas those outside the range will be filtered out.

MDN Reference


appendWindowStart

appendWindowStart: number;

The appendWindowStart property of the SourceBuffer interface controls the timestamp for the start of the append window, a timestamp range that can be used to filter what media data is appended to the SourceBuffer. Coded media frames with timestamps within this range will be appended, whereas those outside the range will be filtered out.

MDN Reference


buffered

readonly buffered: TimeRanges;

The buffered read-only property of the SourceBuffer interface returns the time ranges that are currently buffered in the SourceBuffer as a normalized TimeRanges object.

MDN Reference


mode

mode: AppendMode;

The mode property of the SourceBuffer interface controls whether media segments can be appended to the SourceBuffer in any order, or in a strict sequence.

MDN Reference


onabort

onabort: ((this, ev) => any) | null;

MDN Reference


onerror

onerror: ((this, ev) => any) | null;

MDN Reference


onupdate

onupdate: ((this, ev) => any) | null;

MDN Reference


onupdateend

onupdateend: ((this, ev) => any) | null;

MDN Reference


onupdatestart

onupdatestart: ((this, ev) => any) | null;

MDN Reference


timestampOffset

timestampOffset: number;

The timestampOffset property of the SourceBuffer interface controls the offset applied to timestamps inside media segments that are appended to the SourceBuffer.

MDN Reference


updating

readonly updating: boolean;

The updating read-only property of the SourceBuffer interface indicates whether the SourceBuffer is currently being updated — i.e., whether an appendBuffer() or remove() operation is currently in progress.

MDN Reference