The MediaStream
interface represents a stream of media content. A stream consists of several tracks such as video or audio tracks.
Some user agents subclass this interface to provide more precise information or functionality, like in CanvasCaptureMediaStream
.
Properties
This interface inherits properties from its parent, EventTarget
.
MediaStream.active
Read only- A Boolean value that returns
true
if the MediaStream is active, orfalse
otherwise. MediaStream.ended
Read only- Is a Boolean value set to
true
if theended
event has been fired on the object, meaning that the stream has been completely read, orfalse
if the end of the stream has not been reached.
MediaStream.id
Read only- Is a
DOMString
containing 36 characters denoting a universally unique identifier (UUID) for the object.
Event handlers
MediaStream.onaddtrack
- Is an
EventHandler
containing the action to perform when anaddtrack
event is fired when a newMediaStreamTrack
object is added. MediaStream.onremovetrack
- Is an
EventHandler
containing the action to perform when anremovetrack
event is fired when aMediaStreamTrack
object is removed from it.
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 theMediaStream
object, nothing happens; if the track is in thefinished
state - that is, has already reached its end - the exceptionINVALID_STATE_RAISE
is raised.
MediaStream.clone()
- Returns a clone of the
MediaStream
object. The clone will have a new ID value.
MediaStream.getAudioTracks()
- Returns a list of the
MediaStreamTrack
objects stored in theMediaStream
object that have theirkind
attribute set to"audio"
. 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 theMediaStream
object, regardless of the value of thekind
attribute. 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 theMediaStream
object that have theirkind
attribute 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 theMediaStream
object, nothing happens; if the track is in thefinished
state - that is, it has already reached its end - the exceptionINVALID_STATE_RAISE
is raised.
Specifications
Specification | Status | Comment |
---|---|---|
Media Capture and Streams The definition of 'MediaStream' in that specification. |
Editor's Draft |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | No support | No support | ? |
getAudioTracks() and getVideoTracks() |
(Yes) | 23.0 (23.0) | No support | No support | ? |
id |
(Yes) | 41.0 (41.0) | ? | ? | ? |
ended , label , and stop() |
No support [1] |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | (Yes) | (Yes) | No support | No support | ? | (Yes) |
getAudioTracks() and getVideoTracks() |
? | (Yes) | 23.0 (23.0) | No support | No support | ? | (Yes) |
id |
? | (Yes) | 41.0 (41.0) | ? | ? | ? | (Yes) |
ended , label , and stop() |
? | No support [1] | No support [1] |
[1] Deprecated in Chrome 45, removed in Chrome 47.
See also
- Using the MediaStream API