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.
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 istrue if the track is allowed to render the source stream orfalse 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,enabledindicates that the track is permitted to
render its actual media to the output. Whenenabledis set tofalse, 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 theenabledproperty.
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
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
Remarks
Isolated
[Value("isolated")]
public bool Isolated { get; }
Property Value
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
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.
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
trueif the track is currently muted, orfalseif the track is currently unmuted.NOTE
When possible, avoid pollingmutedto 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 settingenabledtofalse, it generates only empty frames
(audio frames in which every sample is 0, or video frames in which every pixel is
black).
Oncapturehandlechange
[Value("oncapturehandlechange")]
public EventHandlerNonNull Oncapturehandlechange { get; set; }
Property Value
Onended
[Value("onended")]
public EventHandlerNonNull Onended { get; set; }
Property Value
Onisolationchange
[Value("onisolationchange")]
public EventHandlerNonNull Onisolationchange { get; set; }
Property Value
Onmute
[Value("onmute")]
public EventHandlerNonNull Onmute { get; set; }
Property Value
Onunmute
[Value("onunmute")]
public EventHandlerNonNull Onunmute { get; set; }
Property Value
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
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
constraintsMediaTrackConstraints
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 isOverconstrainedErrorwith 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.
Clone()
The clone() method of the MediaStreamTrack
interface creates a duplicate of the MediaStreamTrack. This newMediaStreamTrack 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
MediaTrackCapabilitiesobject which specifies the accepted value or range of values supported for each of the user agent'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:
For audio tracks only:For video tracks only:For more information about what each property means, see MediaTrackConstraints.NOTE
For historical reasons, these two properties are strings instead of an array of strings like all other capabilities.
Remarks
Once you know what the browser'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.
GetCaptureHandle()
[Value("getCaptureHandle")]
public CaptureHandle? GetCaptureHandle()
Returns
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't necessarily describe
the actual state of the media. Even if any of the constraints couldn't be met, they
are still included in the returned object as originally set by the site'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.
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'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's code. To instead fetch the most-recently established
constraints for the track's properties, as specified by the site's code, use
GetConstraints().
Remarks
See Capabilities, constraints, and settings for details on how to work with constrainable properties.
GetSupportedCaptureActions()
[Value("getSupportedCaptureActions")]
public List<string> GetSupportedCaptureActions()
Returns
SendCaptureAction(CaptureAction)
[Value("sendCaptureAction")]
public Task<GlobalObject.Undefined> SendCaptureAction(CaptureAction action)
Parameters
actionCaptureAction
Returns
Stop()
The stop() method of the MediaStreamTrack interface stops the track.
[Value("stop")]
public GlobalObject.Undefined Stop()
Returns
Remarks
-MediaStreamTrack, the interface it belongs to.
-ReadyState
-MediaStreamTrackended