MediaStream object

A new stream of existing tracks.

Syntax


var mediastream = new MediaStream(MediaStream stream);

DOM Information

Inheritance Hierarchy

 MediaStream
   MediaStream

Members

The MediaStream object has these types of members:

Events

The MediaStream object has these events.

EventDescription
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.

MethodDescription
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.

PropertyAccess typeDescription

active

Read-only

Indicates if the MediaStream is active.

id

Read-only

The identifier string of an object.

srcObject

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 NameAttribute TypeValid Values When Using a MediaStreamAdditional Considerations
currentSrc DOMStringThe empty string.When srcObject is specified, it will set this to the empty string.
preload DOMStringNoneA MediaStream cannot be preloaded.
buffered TimeRangesbuffered.length will return 0.A MediaStream cannot be preloaded.
networkState unsigned shortNETWORK_IDLThe media element does not fetch the MediaStream so there is no network traffic.
readyState unsigned shortHAVE_NOTHING, HAVE_ENOUGH_DATAA 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 doubleAny 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 InfinityA MediaStream does not have a pre-defined duration.
seeking boolean falseA MediaStream is not seekable. Therefore, this attribute will always have the value false.
defaultPlaybackRate double 1.0A 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.0A MediaStream is not seekable. Therefore, this attribute will always have the value 1.0 and any attempt to alter it will fail.
played TimeRangesplayed.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 TimeRangesseekable.length returns 0.A MediaStream is not seekable.
loop booleantrue, falseSetting the loop attribute has no effect since a MediaStream has no defined end and therefore cannot be looped.

 

See also

MediaStream

 

 

Show: