MediaStream API
The MediaStream API is designed to allow you to access streams of media from local input devices, such as cameras and microphones. It was initially focused upon the getUserMedia API or gUM for short, but has now been formalized as the broader media capture and streams API, or MediaStream API for short. However, the getUserMedia()
method is still the primary way to initiate access to local input devices.
Each MediaStream object can contain a number of different MediaStreamTrack objects that each represents different input media, such as video or audio from different input sources.
Each MediaStreamTrack can then contain multiple channels (for example, the left and right audio channels). These channels are the smallest units that are defined by the MediaStream API.
MediaStream objects can then be output in two key ways. First, they can be used to render output into a MediaElement such as a <video>
or <audio>
element (although the latter may require pre-processing). Secondly, they can be used to send to an RTCPeerConnection, which can then send this media stream to a remote peer.
Each MediaStreamTrack can be represented in a number of states described by the MediaSourceStates
object returned by the states()
method. Each MediaStreamTrack can also provide a range of capabilities, which can be accessed through the capabilities()
method.
At the top level, a MediaStream object can fire a range of events such as addtrack
, removetrack
, or ended
. And below that a MediaStreamTrack can fire a range of events such as started
, mute
, unmute
, overconstrainted
, and ended
.