Table of Contents

Class MediaStream

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The MediaStream interface of the {{domxref("Media Capture and Streams API", "", "", "nocode")}} represents a stream of media content. A stream consists of several tracks, such as video or audio tracks. Each track is specified as an instance of MediaStreamTrack.

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

Remarks

Constructors

MediaStream()

The MediaStream() constructor returns a newly-created MediaStream, which serves as a collection of media tracks, each represented by a MediaStreamTrack object.

public MediaStream()

Remarks

If any parameters are given, the specified tracks are added to the new stream.
Otherwise, the stream has no tracks.

-MediaStream

See also on MDN

MediaStream(MediaStream)

The MediaStream() constructor returns a newly-created MediaStream, which serves as a collection of media tracks, each represented by a MediaStreamTrack object.

public MediaStream(MediaStream stream)

Parameters

stream MediaStream

Remarks

If any parameters are given, the specified tracks are added to the new stream.
Otherwise, the stream has no tracks.

-MediaStream

See also on MDN

MediaStream(List<MediaStreamTrack>)

The MediaStream() constructor returns a newly-created MediaStream, which serves as a collection of media tracks, each represented by a MediaStreamTrack object.

public MediaStream(List<MediaStreamTrack> tracks)

Parameters

tracks List<MediaStreamTrack>

Remarks

If any parameters are given, the specified tracks are added to the new stream.
Otherwise, the stream has no tracks.

-MediaStream

See also on MDN

Properties

Active

The active read-only property of the
MediaStream interface returns a Boolean value which is
true if the stream is currently active; otherwise, it returns
false. A stream is considered active if at least one of
its MediaStreamTracks does not have its property ReadyState
set to ended. Once every track has ended, the stream&apos;s active property becomes
false.

[Value("active")]
public bool Active { get; }

Property Value

bool

A Boolean value which is true if the stream is currently active;
otherwise, the value is false.

Remarks

Id

The id read-only property of the MediaStream interface is a
string containing 36 characters denoting a unique identifier (GUID)
for the object.

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

Property Value

string

A string.

Remarks

-MediaStream, the interface this property belongs to.

See also on MDN

Onaddtrack

[Value("onaddtrack")]
public EventHandlerNonNull Onaddtrack { get; set; }

Property Value

EventHandlerNonNull

Onremovetrack

[Value("onremovetrack")]
public EventHandlerNonNull Onremovetrack { get; set; }

Property Value

EventHandlerNonNull

Methods

AddTrack(MediaStreamTrack)

The addTrack() method of the MediaStream interface adds a new track to the
stream. The track is specified as a parameter of type MediaStreamTrack.

[Value("addTrack")]
public GlobalObject.Undefined AddTrack(MediaStreamTrack track)

Parameters

track MediaStreamTrack

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

NOTE

If the specified track is already in the stream&apos;s track set, this method has no
effect.

-MediaStream, the interface it belongs to.

See also on MDN

Clone()

The clone() method of the MediaStream
interface creates a duplicate of the MediaStream. This new
MediaStream object has a new unique Id and
contains clones of every MediaStreamTrack contained by the
MediaStream on which clone() was called.

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

Returns

MediaStream

A new MediaStream instance which has a new unique ID and contains clones
of every MediaStreamTrack contained by the MediaStream on
which clone() was called.

Remarks

GetAudioTracks()

The getAudioTracks() method of the
MediaStream interface returns a sequence that represents all the
MediaStreamTrack objects in this
stream&apos;s track set where Kind
is audio.

[Value("getAudioTracks")]
public List<MediaStreamTrack> GetAudioTracks()

Returns

List<MediaStreamTrack>

An array of MediaStreamTrack objects, one for each audio track contained
in the stream. Audio tracks are those tracks whose Kind
property is audio. The array is empty if the stream contains no
audio tracks.

NOTE
The order of the returned tracks is not defined by the
specification and may, in fact, change from one call to getAudioTracks()
to the next.
Early versions of this API included a special AudioStreamTrack interface
which was used as the type for each entry in the list of audio streams; however, this
has since been merged into the main MediaStreamTrack interface.

Remarks

GetTrackById(string)

The getTrackById() method of the MediaStream interface
returns a MediaStreamTrack object representing the track with the specified ID
string. If there is no track with the specified ID, this method returns null.

[Value("getTrackById")]
public MediaStreamTrack? GetTrackById(string trackId)

Parameters

trackId string

Returns

MediaStreamTrack

If a track is found for which Id matches the specified
id string, that MediaStreamTrack object is returned.
Otherwise, the returned value is null.

Remarks

GetTracks()

The getTracks() method of the
MediaStream interface returns a sequence that represents all the
MediaStreamTrack objects in this
stream&apos;s track set,
regardless of Kind.

[Value("getTracks")]
public List<MediaStreamTrack> GetTracks()

Returns

List<MediaStreamTrack>

An array of MediaStreamTrack objects.

Remarks

GetVideoTracks()

The getVideoTracks() method of the
MediaStream interface returns a sequence of
MediaStreamTrack objects representing the video tracks in this stream.

[Value("getVideoTracks")]
public List<MediaStreamTrack> GetVideoTracks()

Returns

List<MediaStreamTrack>

An array of MediaStreamTrack objects, one for each video track contained
in the media stream. Video tracks are those tracks whose
Kind property is video. The array
is empty if the stream contains no video tracks.

NOTE
The order of the tracks is not defined by the specification,
and may not be the same from one call to getVideoTracks() to another.

Remarks

RemoveTrack(MediaStreamTrack)

The removeTrack() method of the MediaStream interface removes a
MediaStreamTrack from a stream.

[Value("removeTrack")]
public GlobalObject.Undefined RemoveTrack(MediaStreamTrack track)

Parameters

track MediaStreamTrack

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks