MediaSource
The MediaSource interface of the Media Source Extensions API represents a source of media data for an HTMLMediaElement object. A MediaSource object can be attached to a HTMLMediaElement to be played in the user agent.
Extends
Methods
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.
Type Parameters
| Type Parameter |
|---|
K extends keyof MediaSourceEventMap |
Parameters
| Parameter | Type |
|---|---|
type | K |
listener | (this, ev) => any |
options? | boolean | AddEventListenerOptions |
Returns
void
Overrides
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.
Parameters
| Parameter | Type |
|---|---|
type | string |
listener | EventListenerOrEventListenerObject |
options? | boolean | AddEventListenerOptions |
Returns
void
Overrides
EventTarget.addEventListener
addSourceBuffer()
addSourceBuffer(type): SourceBuffer;
The addSourceBuffer() method of the MediaSource interface creates a new SourceBuffer of the given MIME type and adds it to the MediaSource's sourceBuffers list. The new SourceBuffer is also returned.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
clearLiveSeekableRange()
clearLiveSeekableRange(): void;
The clearLiveSeekableRange() method of the MediaSource interface clears a seekable range previously set with a call to setLiveSeekableRange().
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().
Parameters
| Parameter | Type |
|---|---|
event | Event |
Returns
boolean
Inherited from
endOfStream()
endOfStream(error?): void;
The endOfStream() method of the MediaSource interface signals the end of the stream.
Parameters
| Parameter | Type |
|---|---|
error? | EndOfStreamError |
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.
Type Parameters
| Type Parameter |
|---|
K extends keyof MediaSourceEventMap |
Parameters
| Parameter | Type |
|---|---|
type | K |
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.
Parameters
| Parameter | Type |
|---|---|
type | string |
listener | EventListenerOrEventListenerObject |
options? | boolean | EventListenerOptions |
Returns
void
Overrides
EventTarget.removeEventListener
removeSourceBuffer()
removeSourceBuffer(sourceBuffer): void;
The removeSourceBuffer() method of the MediaSource interface removes the given SourceBuffer from the SourceBufferList associated with this MediaSource object.
Parameters
| Parameter | Type |
|---|---|
sourceBuffer | SourceBuffer |
Returns
void
setLiveSeekableRange()
setLiveSeekableRange(start, end): void;
The setLiveSeekableRange() method of the MediaSource interface sets the range that the user can seek to in the media element.
Parameters
| Parameter | Type |
|---|---|
start | number |
end | number |
Returns
void
Properties
activeSourceBuffers
readonly activeSourceBuffers: SourceBufferList;
The activeSourceBuffers read-only property of the MediaSource interface returns a SourceBufferList object containing a subset of the SourceBuffer objects contained within sourceBuffers — the list of objects providing the selected video track, enabled audio tracks, and shown/hidden text tracks.
duration
duration: number;
The duration property of the MediaSource interface gets and sets the duration of the current media being presented.
onsourceclose
onsourceclose: ((this, ev) => any) | null;
onsourceended
onsourceended: ((this, ev) => any) | null;
onsourceopen
onsourceopen: ((this, ev) => any) | null;
readyState
readonly readyState: ReadyState;
The readyState read-only property of the MediaSource interface returns an enum representing the state of the current MediaSource. The three possible values are:
sourceBuffers
readonly sourceBuffers: SourceBufferList;
The sourceBuffers read-only property of the MediaSource interface returns a SourceBufferList object containing the list of SourceBuffer objects associated with this MediaSource.