Table of Contents

Class MediaStreamTrack

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

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

[Value("MediaStreamTrack")]
public class MediaStreamTrack : EventTarget
Inheritance
MediaStreamTrack
Derived
Inherited Members

Remarks

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

-Media Capture and Streams API
-MediaStream

See also on MDN

Constructors

MediaStreamTrack()

public MediaStreamTrack()

Properties

ContentHint

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 Kind property.

[Value("contentHint")]
public string ContentHint { get; set; }

Property Value

string

A string with one of the following values:

Remarks

Enabled

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.

[Value("enabled")]
public bool Enabled { get; set; }

Property Value

bool

When true, enabled indicates that the track is permitted to
render its actual media to the output. When enabled is set to
false, the track only generates empty frames.Empty audio frames have every sample's value set to 0. Empty video frames have every
pixel set to black.

NOTE
When implementing a mute/unmute feature, you should use the
enabled property.

Remarks

When enabled, a track's data is output from the source to the
destination; otherwise, empty frames are output.

In the case of audio, a disabled track generates frames of silence (that is, frames in
which every sample's value is 0). For video tracks, every frame is filled entirely with
black pixels.

The value of enabled, in essence, represents what a typical user would
consider the muting state for a track, whereas the Muted
property indicates a state in which the track is temporarily unable to output
data, such as a scenario in which frames have been lost in transit.

NOTE

If the track has been disconnected, the value of this property
can be changed, but has no effect.

-Media Capture and Streams API
-MediaStream
-MediaStreamTrack
-WebRTC

See also on MDN

Id

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.

[Value("id")]
public string Id { get; }

Property Value

string

Remarks

Isolated

[Value("isolated")]
public bool Isolated { get; }

Property Value

bool

Kind

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.

[Value("kind")]
public string Kind { get; }

Property Value

string

The possible values are a string with one of the following values:

Remarks

Label

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

[Value("label")]
public string Label { get; }

Property Value

string

Remarks

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.

-WebRTC

See also on MDN

Muted

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.

[Value("muted")]
public bool Muted { get; }

Property Value

bool

A boolean which is true if the track is currently muted, or
false if the track is currently unmuted.

NOTE
When possible, avoid polling muted to monitor the track's muting status.
Instead, add event listeners for the MediaStreamTrack.Mute and MediaStreamTrack.Unmute events.

Remarks

NOTE

To implement a way for users to mute and unmute a track, use the
Enabled property. When a track is disabled
by setting enabled to false, it generates only empty frames
(audio frames in which every sample is 0, or video frames in which every pixel is
black).

See also on MDN

Oncapturehandlechange

[Value("oncapturehandlechange")]
public EventHandlerNonNull Oncapturehandlechange { get; set; }

Property Value

EventHandlerNonNull

Onended

[Value("onended")]
public EventHandlerNonNull Onended { get; set; }

Property Value

EventHandlerNonNull

Onisolationchange

[Value("onisolationchange")]
public EventHandlerNonNull Onisolationchange { get; set; }

Property Value

EventHandlerNonNull

Onmute

[Value("onmute")]
public EventHandlerNonNull Onmute { get; set; }

Property Value

EventHandlerNonNull

Onunmute

[Value("onunmute")]
public EventHandlerNonNull Onunmute { get; set; }

Property Value

EventHandlerNonNull

ReadyState

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

[Value("readyState")]
public MediaStreamTrackState ReadyState { get; }

Property Value

MediaStreamTrackState

It takes one of the following values:

Remarks

-Media Capture and Streams API
-WebRTC
-The MediaStreamTrack.Ended event

See also on MDN

Methods

ApplyConstraints(MediaTrackConstraints)

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.

[Value("applyConstraints")]
public Task<GlobalObject.Undefined> ApplyConstraints(MediaTrackConstraints constraints = null)

Parameters

constraints MediaTrackConstraints

Returns

Task<GlobalObject.Undefined>

A Promise which resolves when the constraints have been successfully applied.
If the constraints cannot be applied, the promise is rejected with a OverconstrainedError that is a DOMException whose name is OverconstrainedError with additional parameters, and, to indicate that the constraints could not be met.
This can happen if the specified constraints are too strict to find a match when attempting to configure the track.

Remarks

Constraints can be used to ensure that the media meets certain guidelines you prefer.
For example, you may prefer high-density video but require that the frame rate be a little low to help keep the data rate low enough not overtax the network.
Constraints can also specify ideal and/or acceptable sizes or ranges of sizes.
See Applying constraints in Capabilities, constraints, and settings for more information on how to apply your preferred constraints.

-MediaStream Image Capture API

See also on MDN

Clone()

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

[Value("clone")]
public MediaStreamTrack Clone()

Returns

MediaStreamTrack

A new MediaStreamTrack instance which is identical to the one
clone() was called, except for its new unique
Id.

Remarks

GetCapabilities()

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.

[Value("getCapabilities")]
public MediaTrackCapabilities GetCapabilities()

Returns

MediaTrackCapabilities

A MediaTrackCapabilities object which specifies the accepted value or range of values supported for each of the user agent&apos;s constrainable properties. Note that not every property appears on every track, the available members depend on whether the track is audio or video. This can contain the following members:For both audio and video tracks:

NOTE
For historical reasons, these two properties are strings instead of an array of strings like all other capabilities.
For audio tracks only:For video tracks only:For more information about what each property means, see MediaTrackConstraints.

Remarks

Once you know what the browser&apos;s capabilities are, your script can use
ApplyConstraints(MediaTrackConstraints) to ask for the
track to be configured to match ideal or acceptable settings. See Capabilities, constraints, and settings for details of how to work with constrainable properties.

-GetCapabilities(), which also return a MediaTrackCapabilities object.

See also on MDN

GetCaptureHandle()

[Value("getCaptureHandle")]
public CaptureHandle? GetCaptureHandle()

Returns

CaptureHandle

GetConstraints()

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(MediaTrackConstraints). These
constraints indicate values and ranges of values that the website or application has
specified are required or acceptable for the included constrainable properties.

[Value("getConstraints")]
public MediaTrackConstraints GetConstraints()

Returns

MediaTrackConstraints

A 'MediaTrackConstraints' object which indicates the constrainable
properties the website or app most recently set using
ApplyConstraints(MediaTrackConstraints). The properties
in the returned object are listed in the same order as when they were set, and only
properties specifically set by the site or app are included.

NOTE
The returned set of constraints doesn&apos;t necessarily describe
the actual state of the media. Even if any of the constraints couldn&apos;t be met, they
are still included in the returned object as originally set by the site&apos;s code. To get
the currently active settings for all constrainable properties, you should instead
call GetSettings().

Remarks

Constraints can be used to ensure that the media meets certain guidelines you prefer.
For example, you may prefer high definition video but require that the frame rate be a
little low to help keep the data rate low enough not overtax the network. Constraints
can also specify ideal and/or acceptable sizes or ranges of sizes. See Capabilities, constraints, and settings for details on how to work with constrainable properties.

See also on MDN

GetSettings()

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.

[Value("getSettings")]
public MediaTrackSettings GetSettings()

Returns

MediaTrackSettings

A MediaTrackSettings object describing the current configuration of the
track&apos;s constrainable properties.

NOTE
The returned object identifies the current values of every
constrainable property, including those which are platform defaults rather than having
been expressly set by the site&apos;s code. To instead fetch the most-recently established
constraints for the track&apos;s properties, as specified by the site&apos;s code, use
GetConstraints().

Remarks

See Capabilities, constraints, and settings for details on how to work with constrainable properties.

See also on MDN

GetSupportedCaptureActions()

[Value("getSupportedCaptureActions")]
public List<string> GetSupportedCaptureActions()

Returns

List<string>

SendCaptureAction(CaptureAction)

[Value("sendCaptureAction")]
public Task<GlobalObject.Undefined> SendCaptureAction(CaptureAction action)

Parameters

action CaptureAction

Returns

Task<GlobalObject.Undefined>

Stop()

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

[Value("stop")]
public GlobalObject.Undefined Stop()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

-MediaStreamTrack, the interface it belongs to.
-ReadyState
-MediaStreamTrackended

See also on MDN