MediaStream Class

A stream of media (https://w3c.github.io/mediacapture-main/#mediastream): a set of audio and video tracks, played by the media elements (HtmlMediaElement.SrcObject), the Web Audio API and the other sinks.

public sealed class MediaStream : EventTarget
Inheritance
EventTarget MediaStream

Constructors

NameDescription
MediaStream()Creates a stream without track (https://w3c.github.io/mediacapture-main/#dom-mediastream-constructor).
MediaStream(MediaStream)Creates a stream with the tracks of another stream (the same track objects).
MediaStream(IEnumerable<MediaStreamTrack>)Creates a stream with tracks (a track given several times is added once).

MediaStream overloads

MediaStream()

MediaStream.cs

Creates a stream without track (https://w3c.github.io/mediacapture-main/#dom-mediastream-constructor).

public MediaStream()

MediaStream(MediaStream)

MediaStream.cs

Creates a stream with the tracks of another stream (the same track objects).

public MediaStream(MediaStream stream)
Parameters
stream MediaStream
The stream whose tracks are added.
See also

MediaStream(IEnumerable<MediaStreamTrack>)

MediaStream.cs

Creates a stream with tracks (a track given several times is added once).

public MediaStream(IEnumerable<MediaStreamTrack> tracks)

Properties

NameDescription
ActiveGets whether the stream has a track that is not ended.
IdGets the identifier of the stream (a UUID).
OnAddTrackGets or sets the event handler of the addtrack event.
OnRemoveTrackGets or sets the event handler of the removetrack event.

Gets whether the stream has a track that is not ended.

public bool Active { get; }

Gets the identifier of the stream (a UUID).

public string Id { get; }

OnAddTrack

MediaStream.cs

Gets or sets the event handler of the addtrack event.

public Action<Event>? OnAddTrack { get; set; }

OnRemoveTrack

MediaStream.cs

Gets or sets the event handler of the removetrack event.

public Action<Event>? OnRemoveTrack { get; set; }

Methods

NameDescription
AddTrack(MediaStreamTrack)Adds a track to the stream, unless it is already in the stream. No event is fired.
Clone()Creates a stream with the clones of the tracks of the stream (https://w3c.github.io/mediacapture-main/#dom-mediastream-clone).
GetAudioTracks()Returns the audio tracks of the stream.
GetTrackById(string)Returns the track of the stream with an identifier, or null.
GetTracks()Returns the tracks of the stream.
GetVideoTracks()Returns the video tracks of the stream.
RemoveTrack(MediaStreamTrack)Removes a track from the stream. No event is fired.

AddTrack(MediaStreamTrack)

MediaStream.cs

Adds a track to the stream, unless it is already in the stream. No event is fired.

public void AddTrack(MediaStreamTrack track)

Creates a stream with the clones of the tracks of the stream (https://w3c.github.io/mediacapture-main/#dom-mediastream-clone).

public MediaStream Clone()

GetAudioTracks()

MediaStream.cs

GetTrackById(string)

MediaStream.cs

Returns the track of the stream with an identifier, or null.

public MediaStreamTrack? GetTrackById(string trackId)

GetTracks()

MediaStream.cs

GetVideoTracks()

MediaStream.cs

RemoveTrack(MediaStreamTrack)

MediaStream.cs

Removes a track from the stream. No event is fired.

public void RemoveTrack(MediaStreamTrack track)