Join us online - 19th of November
Save your spot
For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.

Interface MediaStream

The MediaStream interface of the Media Capture and Streams API 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.

MDN Reference

interface MediaStream {
    active: boolean;
    id: string;
    onaddtrack: ((this: MediaStream, ev: MediaStreamTrackEvent) => any) | null;
    onremovetrack:
        | ((this: MediaStream, ev: MediaStreamTrackEvent) => any)
        | null;
    addEventListener<K extends keyof MediaStreamEventMap>(
        type: K,
        listener: (this: MediaStream, ev: MediaStreamEventMap[K]) => any,
        options?: boolean | AddEventListenerOptions,
    ): void;
    addEventListener(
        type: string,
        listener: EventListenerOrEventListenerObject,
        options?: boolean | AddEventListenerOptions,
    ): void;
    addTrack(track: MediaStreamTrack): void;
    clone(): MediaStream;
    dispatchEvent(event: Event): boolean;
    getAudioTracks(): MediaStreamTrack[];
    getTrackById(trackId: string): MediaStreamTrack | null;
    getTracks(): MediaStreamTrack[];
    getVideoTracks(): MediaStreamTrack[];
    removeEventListener<K extends keyof MediaStreamEventMap>(
        type: K,
        listener: (this: MediaStream, ev: MediaStreamEventMap[K]) => any,
        options?: boolean | EventListenerOptions,
    ): void;
    removeEventListener(
        type: string,
        listener: EventListenerOrEventListenerObject,
        options?: boolean | EventListenerOptions,
    ): void;
    removeTrack(track: MediaStreamTrack): void;
}

Hierarchy

  • EventTarget
    • MediaStream
Index
active: boolean

The active read-only property of the MediaStream interface returns a Boolean value which is true if the stream is currently active; otherwise, it returns false. A stream is considered active if at least one of its MediaStreamTracks does not have its property MediaStreamTrack.readyState set to ended. Once every track has ended, the stream's active property becomes false.

MDN Reference

id: string

The id read-only property of the MediaStream interface is a string containing 36 characters denoting a unique identifier (GUID) for the object.

MDN Reference

onaddtrack: ((this: MediaStream, ev: MediaStreamTrackEvent) => any) | null
onremovetrack: ((this: MediaStream, ev: MediaStreamTrackEvent) => any) | null
  • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

    MDN Reference

    Type Parameters

    Parameters

    Returns void

  • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

    MDN Reference

    Parameters

    Returns void

  • The addTrack() method of the MediaStream interface adds a new track to the stream. The track is specified as a parameter of type MediaStreamTrack.

    MDN Reference

    Parameters

    Returns void

  • The clone() method of the MediaStream interface creates a duplicate of the MediaStream. This new MediaStream object has a new unique id and contains clones of every MediaStreamTrack contained by the MediaStream on which clone() was called.

    MDN Reference

    Returns MediaStream

  • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

    MDN Reference

    Parameters

    • event: Event

    Returns boolean

  • The getAudioTracks() method of the MediaStream interface returns a sequence that represents all the MediaStreamTrack objects in this stream's track set where MediaStreamTrack.kind is audio.

    MDN Reference

    Returns MediaStreamTrack[]

  • The getTrackById() method of the MediaStream interface returns a MediaStreamTrack object representing the track with the specified ID string. If there is no track with the specified ID, this method returns null.

    MDN Reference

    Parameters

    • trackId: string

    Returns MediaStreamTrack | null

  • The getTracks() method of the MediaStream interface returns a sequence that represents all the MediaStreamTrack objects in this stream's track set, regardless of MediaStreamTrack.kind.

    MDN Reference

    Returns MediaStreamTrack[]

  • The getVideoTracks() method of the MediaStream interface returns a sequence of MediaStreamTrack objects representing the video tracks in this stream.

    MDN Reference

    Returns MediaStreamTrack[]

  • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

    MDN Reference

    Type Parameters

    Parameters

    Returns void

  • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

    MDN Reference

    Parameters

    Returns void

Was this helpful?