Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. MediaStream

MediaStream

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨September 2017⁩.

TheMediaStream interface of theMedia Capture and Streams API represents a stream of media content. A stream consists of severaltracks, such as video or audio tracks. Each track is specified as an instance ofMediaStreamTrack.

You can obtain aMediaStream object either by using the constructor or by calling functions such asMediaDevices.getUserMedia(),MediaDevices.getDisplayMedia(), orHTMLCanvasElement.captureStream() andHTMLMediaElement.captureStream().

EventTarget MediaStream

Constructor

MediaStream()

Creates and returns a newMediaStream 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 ofMediaStreamTrack objects).

Instance properties

This interface inherits properties from its parent,EventTarget.

MediaStream.activeRead only

A Boolean value that returnstrue if theMediaStream is active, orfalse otherwise.

MediaStream.idRead only

A string containing a 36-character universally unique identifier (UUID) for the object.

Instance methods

This interface inherits methods from its parent,EventTarget.

MediaStream.addTrack()

Stores a copy of theMediaStreamTrack given as argument. If the track has already been added to theMediaStream object, nothing happens.

MediaStream.clone()

Returns a clone of theMediaStream object. The clone will, however, have a unique value forid.

MediaStream.getAudioTracks()

Returns a list of theMediaStreamTrack objects stored in theMediaStream object that have theirkind attribute set toaudio. 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 returnsnull. If several tracks have the same ID, it returns the first one.

MediaStream.getTracks()

Returns a list of allMediaStreamTrack objects stored in theMediaStream object, regardless of the value of thekind 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 theMediaStreamTrack objects stored in theMediaStream object that have theirkind 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 theMediaStreamTrack given as argument. If the track is not part of theMediaStream object, nothing happens.

Events

addtrack

Fired when a newMediaStreamTrack object is added.

removetrack

Fired when aMediaStreamTrack object has been removed.

activeNon-standard

Fired when the MediaStream is activated.

inactiveNon-standard

Fired when the MediaStream is inactivated.

Specifications

Specification
Media Capture and Streams
# mediastream

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp