MediaStream object
A new stream of existing tracks.
Syntax
var mediastream = new MediaStream(MediaStream stream);
DOM Information
Inheritance Hierarchy
Members
The MediaStream object has these types of members:
Events
The MediaStream object has these events.
| Event | Description |
|---|---|
| onactive |
This event is fired when the MediaStream becomes active. |
| onaddtrack |
This event is fired when a MediaStreamTrack is added to the MediaStream. |
| oninactive |
This event is fired when the MediaStream becomes inactive. |
| onremovetrack |
This event is fired when a MediaStreamTrack is removed from the MediaStream. |
Methods
The MediaStream object has these methods.
| Method | Description |
|---|---|
| addTrack |
Adds the MediaStreamTrack to this MediaStream |
| clone |
Clones the MediaStream and all of its tracks and generates a new id for the cloned object. |
| getAudioTracks |
Returns a sequence of MediaStreamTrack objects in the stream's track set whose kind is set to "audio". |
| getTrackById |
Returns a MediaStreamTrack object from the stream's track set. |
| getTracks |
Returns a sequence of MediaStreamTrack objects in the stream's track set, regardless of kind. |
| getVideoTracks |
Returns a sequence of MediaStreamTrack objects in the stream's track set whose kind is set to "video". |
| removeTrack |
Removes the MediaStreamTrack object from this MediaStream. |
Properties
The MediaStream object has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only |
Indicates if the MediaStream is active. | |
| Read-only |
The identifier string of an object. | |
|
Holds the MediaStream that provides media for this element. |
Remarks
When playing a MediaStream, there are certain restrictions on the behaviors of media element attributes. The table below shows the legal values for the properties of a media element bound to a MediaStream.
Media Element Attributes when Playing a MediaStream
| Attribute Name | Attribute Type | Valid Values When Using a MediaStream | Additional Considerations |
|---|---|---|---|
| currentSrc | DOMString | The empty string. | When srcObject is specified, it will set this to the empty string. |
| preload | DOMString | None | A MediaStream cannot be preloaded. |
| buffered | TimeRanges | buffered.length will return 0. | A MediaStream cannot be preloaded. |
| networkState | unsigned short | NETWORK_IDL | The media element does not fetch the MediaStream so there is no network traffic. |
| readyState | unsigned short | HAVE_NOTHING, HAVE_ENOUGH_DATA | A MediaStream may be created before there is any data available. The value of the readyState of the media element will be HAVE_NOTHING before the first media arrives and HAVE_ENOUGH_DATA once the first media has arrived. |
| currentTime | double | Any non-negative integer. The initial value is 0 and the values increments linearly in real time whenever the stream is playing. | The value is the current stream position, in seconds. On any attempt to set this attribute, the InvalidStateError exception will be thrown. |
| duration | unrestricted double | Infinity | A MediaStream does not have a pre-defined duration. |
| seeking | boolean | false | A MediaStream is not seekable. Therefore, this attribute will always have the value false. |
| defaultPlaybackRate | double | 1.0 | A MediaStream is not seekable. Therefore, this attribute will always have the value 1.0 and any attempt to alter it will fail. |
| playbackRate | double | 1.0 | A MediaStream is not seekable. Therefore, this attribute will always have the value 1.0 and any attempt to alter it will fail. |
| played | TimeRanges | played.length returns 1. played.start(0) returns 0. played.end(0) returns the last known currentTime. | A MediaStream's timeline always consists of a single range, starting at 0 and extending up to the currentTime. |
| seekable | TimeRanges | seekable.length returns 0. | A MediaStream is not seekable. |
| loop | boolean | true, false | Setting the loop attribute has no effect since a MediaStream has no defined end and therefore cannot be looped. |
See also