web api interface
MediaStream
The MediaStream interface of the Media Capture and Streams API 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.
You can obtain a MediaStream object either by using the constructor or by calling functions such as getUserMedia(), getDisplayMedia(), or captureStream() and captureStream().
Constructor
MediaStream()- : Creates and returns a new
MediaStreamobject. You can create an empty stream, a stream which is based upon an existing stream, or a stream that contains a specified list of tracks (specified as an array ofMediaStreamTrackobjects).
- : Creates and returns a new
Instance properties
This interface inherits properties from its parent, EventTarget.
activeRead only- : A Boolean value that returns
trueif theMediaStreamis active, orfalseotherwise.
- : A Boolean value that returns
idRead only- : A string containing a 36-character universally unique identifier (UUID) for the object.
Instance methods
This interface inherits methods from its parent, EventTarget.
addTrack()- : Stores a copy of the
MediaStreamTrackgiven as argument. If the track has already been added to theMediaStreamobject, nothing happens.
- : Stores a copy of the
clone()- : Returns a clone of the
MediaStreamobject. The clone will, however, have a unique value forid.
- : Returns a clone of the
getAudioTracks()- : Returns a list of the
MediaStreamTrackobjects stored in theMediaStreamobject that have theirkindattribute set toaudio. The order is not defined, and may not only vary from one browser to another, but also from one call to another.
- : Returns a list of the
getTrackById()- : Returns the track whose ID corresponds to the one given in parameters,
trackId. If no parameter is given, or if no track with that ID does exist, it returnsnull. If several tracks have the same ID, it returns the first one.
- : Returns the track whose ID corresponds to the one given in parameters,
getTracks()- : Returns a list of all
MediaStreamTrackobjects stored in theMediaStreamobject, regardless of the value of thekindattribute. The order is not defined, and may not only vary from one browser to another, but also from one call to another.
- : Returns a list of all
getVideoTracks()- : Returns a list of the
MediaStreamTrackobjects stored in theMediaStreamobject that have theirkindattribute set to"video". The order is not defined, and may not only vary from one browser to another, but also from one call to another.
- : Returns a list of the
removeTrack()- : Removes the
MediaStreamTrackgiven as argument. If the track is not part of theMediaStreamobject, nothing happens.
- : Removes the
Events
addtrack- : Fired when a new
MediaStreamTrackobject is added.
- : Fired when a new
removetrack- : Fired when a
MediaStreamTrackobject has been removed.
- : Fired when a
active- : Fired when the MediaStream is activated.
inactive- : Fired when the MediaStream is inactivated.
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.