This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.
The MediaStream interface represents a stream of media content. A stream consists of several tracks, like video or audio tracks.
Attributes
-
MediaStream.idRead only -
Is a
DOMStringcontaining 36 characters denoting a unique identifier (GUID) for the object. -
MediaStream.endedRead only -
Is a Boolean value with a value of
trueif theendedevent has been fired on the object, meaning that the stream has been completely read, orfalseif the end of hte stream has not been reached.
Event handlers
-
MediaStream.onaddtrack -
Is a
EventHandlercontaining the action to perform when anaddtrackevent is fired on the object, that is when a newMediaStreamTrackobject is added. -
MediaStream.onended -
Is a
EventHandlercontaining the action to perform when anendedevent is fired on the object, that is when the streaming is terminating. -
MediaStream.onremovetrack -
Is a
EventHandlercontaining the action to perform when anremovetrackevent is fired on the object, that is when aMediaStreamTrackobject is removed from it.
Methods
-
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 exists, it returnsnull. If several tracks have the same id, it returns the first one.
-
MediaStream.addTrack() -
Stores a copy of the
MediaStreamTrackgiven as argument. If the track has already been added to theMediaStreamobject, nothing happens; if the track is in thefinishedstate, that is has already reached its end, the exceptionINVALID_STATE_RAISEis raised. -
MediaStream.removeTrack() -
Removes the
MediaStreamTrackgiven as argument. If the track is not part of theMediaStreamobject, nothing happens; if the track is in thefinishedstate, that is has already reached its end, the exceptionINVALID_STATE_RAISEis raised. -
MediaStream.getAudioTracks() -
Returns a list of the
MediaStreamTrackstored in theMediaStreamobject that have theirkindattribute set to"audio". The order is not defined, and may vary from one browser to an other, but also from one call to the method to another. -
MediaStream.getVideoTracks() -
Returns a list of the
MediaStreamTrackstored in theMediaStreamobject that have theirkindattribute set to"video". The order is not defined, and may vary from one browser to an other, but also from one call to the method to another.
Examples
Specifications
| Specification | Status | Comment |
|---|---|---|
| Media Capture and Streams | Working Draft |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | Not supported | Not supported | ? |
getAudioTracks() and getVideoTracks() |
? | 23.0 (23.0) | Not supported | Not supported | ? |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | ? | (Yes) | Not supported | Not supported | ? |
getAudioTracks() and getVideoTracks() |
? | 23.0 (23.0) | Not supported | Not supported | ? |
See also
- Using the MediaStream API
Mozilla Developer Network