Skip to main content

MediaStreamTrack

The MediaStreamTrack interface of the Media Capture and Streams API represents a single media track within a stream; typically, these are audio or video tracks, but other track types may exist as well.

MDN Reference

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.

MDN Reference

Type Parameters
Type Parameter
K extends keyof MediaStreamTrackEventMap
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

applyConstraints()

applyConstraints(constraints?): Promise<void>;

The applyConstraints() method of the MediaStreamTrack interface applies a set of constraints to the track; these constraints let the website or app establish ideal values and acceptable ranges of values for the constrainable properties of the track, such as frame rate, dimensions, echo cancellation, and so forth.

MDN Reference

Parameters

ParameterType
constraints?MediaTrackConstraints

Returns

Promise<void>


clone()

clone(): MediaStreamTrack;

The clone() method of the MediaStreamTrack interface creates a duplicate of the MediaStreamTrack. This new MediaStreamTrack object is identical except for its unique id.

MDN Reference

Returns

MediaStreamTrack


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


getCapabilities()

getCapabilities(): MediaTrackCapabilities;

The getCapabilities() method of the MediaStreamTrack interface returns an object detailing the accepted values or value range for each constrainable property of the associated MediaStreamTrack, based upon the platform and user agent.

MDN Reference

Returns

MediaTrackCapabilities


getConstraints()

getConstraints(): MediaTrackConstraints;

The getConstraints() method of the MediaStreamTrack interface returns a MediaTrackConstraints object containing the set of constraints most recently established for the track using a prior call to applyConstraints(). These constraints indicate values and ranges of values that the website or application has specified are required or acceptable for the included constrainable properties.

MDN Reference

Returns

MediaTrackConstraints


getSettings()

getSettings(): MediaTrackSettings;

The getSettings() method of the MediaStreamTrack interface returns a MediaTrackSettings object containing the current values of each of the constrainable properties for the current MediaStreamTrack.

MDN Reference

Returns

MediaTrackSettings


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 MediaStreamTrackEventMap
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

stop()

stop(): void;

The stop() method of the MediaStreamTrack interface stops the track.

MDN Reference

Returns

void

Properties

contentHint

contentHint: string;

The contentHint property of the MediaStreamTrack interface is a string that hints at the type of content the track contains. Allowable values depend on the value of the MediaStreamTrack.kind property.

MDN Reference


enabled

enabled: boolean;

The enabled property of the MediaStreamTrack interface is a Boolean value which is true if the track is allowed to render the source stream or false if it is not. This can be used to intentionally mute a track.

MDN Reference


id

readonly id: string;

The id read-only property of the MediaStreamTrack interface returns a string containing a unique identifier (GUID) for the track, which is generated by the user agent.

MDN Reference


kind

readonly kind: string;

The kind read-only property of the MediaStreamTrack interface returns a string set to "audio" if the track is an audio track and to "video" if it is a video track. It doesn't change if the track is disassociated from its source.

MDN Reference


label

readonly label: string;

The label read-only property of the MediaStreamTrack interface returns a string containing a user agent-assigned label that identifies the track source, as in "internal microphone".

MDN Reference


muted

readonly muted: boolean;

The muted read-only property of the MediaStreamTrack interface returns a boolean value indicating whether or not the track is currently unable to provide media output.

MDN Reference


onended

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

MDN Reference


onmute

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

MDN Reference


onunmute

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

MDN Reference


readyState

readonly readyState: MediaStreamTrackState;

The readyState read-only property of the MediaStreamTrack interface returns an enumerated value giving the status of the track.

MDN Reference