Media Capture and Streams API (Media Stream)
TheMedia Capture and Streams API, often called theMedia Streams API orMediaStream API, is an API related toWebRTC which provides support for streaming audio and video data.
It provides the interfaces and methods for working with the streams and their constituent tracks, the constraints associated with data formats, the success and error callbacks when using the data asynchronously, and the events that are fired during the process.
Concepts and usage
The API is based on the manipulation of aMediaStream
object representing a flux of audio- or video-related data. See an example inGet the media stream.
AMediaStream
consists of zero or moreMediaStreamTrack
objects, representing various audio or videotracks. EachMediaStreamTrack
may have one or morechannels. The channel represents the smallest unit of a media stream, such as an audio signal associated with a given speaker, likeleft orright in a stereo audio track.
MediaStream
objects have a singleinput and a singleoutput. AMediaStream
object generated bygetUserMedia()
is calledlocal, and has as its source input one of the user's cameras or microphones. A non-localMediaStream
may be representing a media element, like<video>
or<audio>
, a stream originating over the network, and obtained via the WebRTCRTCPeerConnection
API, or a stream created using theWeb Audio APIMediaStreamAudioDestinationNode
.
The output of theMediaStream
object is linked to aconsumer. It can be a media element, like<audio>
or<video>
, the WebRTCRTCPeerConnection
API or aWeb Audio APIMediaStreamAudioSourceNode
.
Interfaces
In these reference articles, you'll find the fundamental information you'll need to know about each of the interfaces that make up the Media Capture and Streams API.
Events
Guides and tutorials
TheCapabilities, constraints, and settings article discusses the concepts ofconstraints andcapabilities, as well as media settings, and includes aConstraint Exerciser that lets you experiment with the results of different constraint sets being applied to the audio and video tracks coming from the computer's A/V input devices (such as its webcam and microphone).
TheTaking still photos with getUserMedia() article shows how to usegetUserMedia()
to access the camera on a computer or mobile phone withgetUserMedia()
support and take a photo with it.
Specifications
Specification |
---|
Media Capture and Streams |
Media Capture from DOM Elements |
Browser compatibility
api.MediaStream
api.MediaStreamTrack
api.MediaDevices
api.MediaDeviceInfo
api.InputDeviceInfo
api.CanvasCaptureMediaStreamTrack
See also
- WebRTC - the introductory page to the API
- Taking still photos with WebRTC: a demonstration and tutorial about using
getUserMedia()
.