MediaStreamTrack

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

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.

Some user agents subclass this interface to provide more precise information or functionality, such as CanvasCaptureMediaStreamTrack.

EventTarget MediaStreamTrack

Instance properties

In addition to the properties listed below, MediaStreamTrack has constrainable properties which can be set using applyConstraints() and accessed using getConstraints() and getSettings(). See Capabilities, constraints, and settings to learn how to correctly work with constrainable properties. Not doing so correctly will result in your code being unreliable.

MediaStreamTrack.contentHint

A string that may be used by the web application to provide a hint as to what type of content the track contains to guide how it should be treated by API consumers. Allowable values depend on the value of the MediaStreamTrack.kind property.

MediaStreamTrack.enabled

A Boolean whose value of true if the track is enabled, that is allowed to render the media source stream; or false if it is disabled, that is not rendering the media source stream but silence and blackness. If the track has been disconnected, this value can be changed but has no more effect.

Note: You can implement standard "mute" functionality by setting enabled to false. The muted property refers to a condition in which there's no media because of a technical issue.

MediaStreamTrack.id Read only

Returns a string containing a unique identifier (GUID) for the track; it is generated by the browser.

MediaStreamTrack.kind Read only

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.

MediaStreamTrack.label Read only

Returns a string containing a user agent-assigned label that identifies the track source, as in "internal microphone". The string may be left empty and is empty as long as no source has been connected. When the track is disassociated from its source, the label is not changed.

MediaStreamTrack.muted Read only

Returns a Boolean value indicating whether the track is unable to provide media data due to a technical issue.

Note: You can implement standard "mute" functionality by setting enabled to false, and unmute the media by setting it back to true again.

MediaStreamTrack.readyState Read only

Returns an enumerated string giving the status of the track. This will be one of the following values:

  • "live" which indicates that an input is connected and does its best-effort in providing real-time data. In that case, the output of data can be switched on or off using the enabled attribute.
  • "ended" which indicates that the input is not giving any more data and will never provide new data.

Instance methods

MediaStreamTrack.applyConstraints()

Lets the application specify the ideal and/or ranges of acceptable values for any number of the available constrainable properties of the MediaStreamTrack.

MediaStreamTrack.clone()

Returns a duplicate of the MediaStreamTrack.

MediaStreamTrack.getCapabilities()

Returns an object detailing the accepted values or value range for each constrainable property of the associated MediaStreamTrack.

MediaStreamTrack.getConstraints()

Returns a MediaTrackConstraints object containing the currently set constraints for the track; the returned value matches the constraints last set using applyConstraints().

MediaStreamTrack.getSettings()

Returns a MediaTrackSettings object containing the current values of each of the MediaStreamTrack's constrainable properties.

MediaStreamTrack.stop()

Stops playing the source associated to the track, both the source and the track are disassociated. The track state is set to ended.

Events

Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface:

ended

Sent when playback of the track ends (when the value readyState changes to ended), except when the track is ended by calling MediaStreamTrack.stop.

mute

Sent to the MediaStreamTrack when the value of the muted property is changed to true, indicating that the track is unable to provide data temporarily (such as when the network is experiencing a service malfunction).

unmute

Sent to the track when data becomes available again, ending the muted state.

Specifications

Specification
Media Capture and Streams
# mediastreamtrack

Browser compatibility

BCD tables only load in the browser

See also