MediaStream
Media Capture and Streams
Media Capture and Streams
The MediaStream interface of the 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 MediaDevices.getUserMedia(), MediaDevices.getDisplayMedia(), or HTMLCanvasElement.captureStream() and HTMLMediaElement.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 of MediaStreamTrack objects).
Instance properties
This interface inherits properties from its parent, EventTarget.
- MediaStream.active
- : A Boolean value that returns
trueif theMediaStreamis active, orfalseotherwise. - MediaStream.id
- : A string containing a 36-character universally unique identifier (UUID) for the object.
Instance methods
This interface inherits methods from its parent, EventTarget.
- MediaStream.addTrack()
- : Stores a copy of the MediaStreamTrack given as argument. If the track has already been added to the
MediaStreamobject, nothing happens. - MediaStream.clone()
- : Returns a clone of the
MediaStreamobject. The clone will, however, have a unique value for id. - MediaStream.getAudioTracks()
- : Returns a list of the MediaStreamTrack objects stored in the
MediaStreamobject 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. - MediaStream.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. - MediaStream.getTracks()
- : Returns a list of all MediaStreamTrack objects stored in the
MediaStreamobject, 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. - MediaStream.getVideoTracks()
- : Returns a list of the MediaStreamTrack objects stored in the
MediaStreamobject 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. - MediaStream.removeTrack()
- : Removes the MediaStreamTrack given as argument. If the track is not part of the
MediaStreamobject, nothing happens.
Events
- addtrack
- : Fired when a new MediaStreamTrack object is added.
- removetrack
- : Fired when a MediaStreamTrack object has been removed.
- active
- : Fired when the MediaStream is activated.
- inactive
- : Fired when the MediaStream is inactivated.
Specifications
Browser compatibility
See also
- Using the MediaStream Recording API
- WebRTC API
- Web Audio API
- MediaStreamTrack