Наши волонтёры ещё не перевели данную статью на Русский. Присоединяйтесь к нам и помогите сделать эту работу!
Вы можете также прочитать эту статью на English (US).

The MediaStream interface 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 MediaDevices.getUserMedia().

Some user agents subclass this interface to provide more precise information or functionality, like in CanvasCaptureMediaStream.

Constructor

MediaStream()
Creates and returns a new MediaStream object. 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).

Properties

This interface inherits properties from its parent, EventTarget.

MediaStream.active Read only
A Boolean value that returns true if the MediaStream is active, or false otherwise.
MediaStream.ended Read only  
A Boolean value set to true if the end of the stream has been reached. This has been removed from the specification; you should instead check the value of MediaStreamTrack.readyState to see if its value is "ended" for the track or tracks you want to ensure have finished playing.
MediaStream.id Read only
A DOMString containing 36 characters denoting a universally unique identifier (UUID) for the object.

Event handlers

MediaStream.onaddtrack
An EventHandler containing the action to perform when an addtrack event is fired when a new MediaStreamTrack object is added.
MediaStream.onremovetrack
An EventHandler containing the action to perform when a removetrack event is fired when a  MediaStreamTrack 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 the MediaStream object, nothing happens.
MediaStream.clone()
Returns a clone of the MediaStream object. The clone will, however, have a unique value for id.
MediaStream.getAudioTracks()
Returns a list of the MediaStreamTrack objects stored in the MediaStream object that have their kind 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 returns null. If several tracks have the same ID, it returns the first one.
MediaStream.getTracks()
Returns a list of all MediaStreamTrack objects stored in the MediaStream object, regardless of the value of the kind 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 the MediaStream object that have their kind 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 the MediaStream object, nothing happens.

Specifications

Specification Status Comment
Media Capture and Streams
The definition of 'MediaStream' in that specification.
Candidate Recommendation  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes Yes Yes No No ?
MediaStream55 Yes44 No42 No
active Yes1252 ? ? ?
ended Yes — 541 ? No ? Yes — 39 ?
id Yes — 541241 ? Yes — 39 ?
onaddtrack Yes1250 ? ? ?
onremovetrack Yes12 No ? ? ?
addTrack Yes1244 ? ? ?
clone Yes1248 ? ? ?
getAudioTracks Yes12 ? ? Yes ?
getTrackById Yes1249 No ? ?
getTracks Yes12 ? ? Yes ?
getVideoTracks Yes12 ? ? Yes ?
removeTrack Yes12 ? ? Yes ?
label Yes — 542 ? ? No No ?
stop No13 ? No No ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes ? No ? Yes
MediaStream5555 Yes42 ? No6.0
active Yes Yes Yes52 ? ? Yes
ended Yes — 541 Yes — 541 Yes No Yes — 39 ? Yes
id Yes — 54 Yes — 54 Yes41 Yes — 39 ? Yes
onaddtrack Yes Yes Yes50 ? ? Yes
onremovetrack Yes Yes Yes No ? ? Yes
addTrack Yes Yes Yes No ? ? Yes
clone Yes Yes Yes48 ? ? Yes
getAudioTracks Yes Yes Yes ? ? ? Yes
getTrackById Yes Yes Yes49 ? ? Yes
getTracks Yes Yes Yes ? ? ? Yes
getVideoTracks Yes Yes Yes ? ? ? Yes
removeTrack Yes Yes ? ? ? ? Yes
label Yes — 542 Yes — 542 ? ? No ? Yes
stop No No ? ? No ? No

1. Deprecated in Chrome 52.

2. Deprecated in Chrome 45.

See also

Метки документа и участники

Внесли вклад в эту страницу: mec, jwhitlock, jpmedley, Sheppy, libbymc, Jib, chrisdavidmills, fscholz, teoli, eharris, forceuser, Rahulraja, AbrahamT, kscarfone, ethertank
Обновлялась последний раз: mec,