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
You can obtain a MediaStream object either by using the constructor or by calling functions such as GetUserMedia(MediaStreamConstraints), GetDisplayMedia(DisplayMediaStreamOptions), or CaptureStream(Number) and CaptureStream().
-Using the MediaStream Recording API
-WebRTC API
-Web Audio API
-MediaStreamTrack
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(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
streamMediaStream
Remarks
If any parameters are given, the specified tracks are added to the new stream.
Otherwise, the stream has no tracks.
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
tracksList<MediaStreamTrack>
Remarks
If any parameters are given, the specified tracks are added to the new stream.
Otherwise, the stream has no tracks.
Properties
Active
The active read-only property of the
MediaStream interface returns a Boolean value which istrue if the stream is currently active; otherwise, it returnsfalse. 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's active property becomesfalse.
[Value("active")]
public bool Active { get; }
Property Value
- bool
A Boolean value which is
trueif the stream is currently active;
otherwise, the value isfalse.
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.
Onaddtrack
[Value("onaddtrack")]
public EventHandlerNonNull Onaddtrack { get; set; }
Property Value
Onremovetrack
[Value("onremovetrack")]
public EventHandlerNonNull Onremovetrack { get; set; }
Property Value
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
trackMediaStreamTrack
Returns
Remarks
NOTE
If the specified track is already in the stream's track set, this method has no
effect.
-MediaStream, the interface it belongs to.
Clone()
The clone() method of the MediaStream
interface creates a duplicate of the MediaStream. This newMediaStream object has a new unique Id and
contains clones of every MediaStreamTrack contained by theMediaStream 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 theMediaStreamon
whichclone()was called.
Remarks
GetAudioTracks()
The getAudioTracks() method of the
MediaStream interface returns a sequence that represents all the
MediaStreamTrack objects in this
stream'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 isaudio. The array is empty if the stream contains no
audio tracks.
Early versions of this API included a specialNOTE
The order of the returned tracks is not defined by the
specification and may, in fact, change from one call togetAudioTracks()
to the next.AudioStreamTrackinterface
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
trackIdstring
Returns
- MediaStreamTrack
If a track is found for which Id matches the specified
idstring, that MediaStreamTrack object is returned.
Otherwise, the returned value isnull.
Remarks
GetTracks()
The getTracks() method of the
MediaStream interface returns a sequence that represents all the
MediaStreamTrack objects in this
stream'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 isvideo. 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 togetVideoTracks()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
trackMediaStreamTrack