Use Player to start playing a WebRTS stream.

You can implement and use a custom Source by passing it as the second argument in the constructor. If not provided, Player.start will attempt to determine the protocol from Connect.Params.endPoint to instantiate the corresponding Source.registerClass or fall back to the default HTTPAdaptiveSource.

You can initialize tracks selection by playing with onMetadata

Example

const player = new Player(videoElement);
// const player = new Player(videoElement, MySource);
player.onStart = () => {
console.log('start playing');
}
player.onStop = _ => {
console.log('stop playing');
}

// optional : set initial video track to the best track (by default take the middle rendition)
player.onMetadata = (metadata) => ({ video: metadata.videoTracks[0].id });
// optional : fix video track to the best track and disable MBR
player.onMetadata = (metadata) => player.videoTrack = metadata.videoTracks[0].id;

// start playback
player.start({
endPoint: <endPoint>
});
...
// stop playback
player.stop();

Hierarchy (view full)

Implements

Constructors

  • Constructs a new Player instance to render on the HTMLVideoElement passed in first argument, with an optionally Source to custom how getting the stream.

    This doesn't start the playback, you must call Player.start method

    Parameters

    • video: HTMLVideoElement

      HTMLVideoElement object to render the video

    • Optional SourceClass: (new (playing, params) => Source)

      Optional Source logic to use, by default it uses HTTPAdaptiveSource unless Connect.Params.endPoint begin with ws:// see Player.start

    Returns Player

    Example

    // Default build
    const player = new Player(video);

    // Build with custom source implementation
    const player = new Player(MySource);

Properties

SourceClass?: (new (playing, params) => Source)

Optional Source logic to use, by default it uses HTTPAdaptiveSource unless Connect.Params.endPoint begin with ws:// see Player.start

Type declaration

_bufferLimitHigh: number
_bufferLimitLow: number
_bufferLimitMiddle: number
_bufferState: BufferState
_buffering: boolean
_controller: AbortController
_maximumResolution?: Resolution
_mediaSource?: MediaSource
_metadata: Metadata
_paused: boolean
_playback?: MediaPlayback
_playbackPrevTime?: number
_playbackSpeed: ByteRate
_source?: Source
_timeout?: {
    id: Timeout;
    value: number;
}

Type declaration

  • id: Timeout
  • value: number
_video: HTMLVideoElement
log: ILog

Start a log

Param: args

Returns

a Log object with the levels of log to call

Accessors

  • get audioPerSecond(): number
  • Get the number of audio sample per second currently decoding

    Returns number

  • get audioTrack(): undefined | number
  • Index of the audio track, can be undefined if player is not playing

    Returns undefined | number

  • set audioTrack(idx): void
  • Sets the current audio track to the index provided, must be set after starting. It disables MBR, set it to undefined to reactivate MBR.

    Parameters

    • idx: undefined | number

    Returns void

  • get bufferAmount(): number
  • Gets the current playback buffer duration in milliseconds

    Returns number

  • get bufferLimitHigh(): number
  • Gets the high-buffer threshold for BufferState.HIGH in milliseconds

    Returns number

  • set bufferLimitHigh(value): void
  • Set the high-buffer threshold for BufferState.HIGH in milliseconds

    Parameters

    • value: number

    Returns void

  • get bufferLimitLow(): number
  • Gets the low-buffer threshold for BufferState.LOW in milliseconds

    Returns number

  • set bufferLimitLow(value): void
  • Set the low‐buffer threshold for BufferState.LOW in milliseconds

    Parameters

    • value: number

    Returns void

  • get bufferLimitMiddle(): number
  • Gets the target (middle) buffer size in milliseconds. Latency control mechanisms will try to drive the buffer toward this value.

    Returns number

  • get cmcdSid(): string
  • The CMCD session ID

    Returns string

  • set cmcdSid(value): void
  • Set the CMCD session ID, if undefined reset to empty string

    Parameters

    • value: undefined | string

    Returns void

  • get currentTime(): number
  • Gets the current playback time in seconds

    Returns number

  • get endTime(): number
  • Gets the playback end time in seconds

    Returns number

  • get latency(): undefined | number
  • Gets an estimation of playback latency in milliseconds, Computed as the difference between the estimated live time and the current playback time.

    Returns undefined | number

  • get maximumResolution(): undefined | Resolution
  • Get maximum resolution that the MBR algo can reach, undefined means no limit. Defaults to the value of Media.screenResolution

    Returns undefined | Resolution

  • set maximumResolution(value): void
  • Set maximum resolution that the MBR algo can reach, undefined means no limit. Defaults to the value of Media.screenResolution

    Parameters

    Returns void

  • get passthroughCMAF(): undefined | boolean
  • Source is CMAF and passthrough it to MSE, it's a debugging mode activable when you set Connect.Params.mediaExt to 'cmaf'

    Returns undefined | boolean

  • get paused(): boolean
  • Returns true if player is paused

    Returns boolean

  • set paused(value): void
  • Enable or disable player's pause

    Parameters

    • value: boolean

    Returns void

  • get playbackRate(): number
  • Gets the current playback rate. A value of 1.0 represents real-time playback.

    Returns number

  • get playbackSpeed(): number
  • Gets the effective playback speed. A value of 1.0 represents real-time playback.

    Returns number

  • get recvByteRate(): number
  • Gets the current receive byte rate

    Returns number

  • get reliable(): boolean
  • Gets whether playback is reliable By default is false while playback is in an unreliable mode with frame skipping enabled, otherwise can returns true when configured to not tolerate any frame loss

    Returns boolean

  • set reliable(value): void
  • Sets whether playback should be treated as reliable. When false, playback operates in an unreliable mode with frame skipping enabled; when true, frame skipping is not tolerated and reliable mode is enforced.

    Parameters

    • value: boolean

    Returns void

  • get signal(): AbortSignal
  • Gets an AbortSignal useful for subscribing to playback stop events.

    Returns AbortSignal

  • get startTime(): number
  • Gets the playback start time in seconds

    Returns number

  • get trackSelectable(): undefined | boolean
  • Returns true if manual track selection is supported by the source implementation, can also returns undefined if player is not running

    Returns undefined | boolean

  • get videoPerSecond(): number
  • Get the number of video frame per second currently decoding

    Returns number

  • get videoTrack(): undefined | number
  • Index of the video track, can be undefined if player is not playing

    Returns undefined | number

  • set videoTrack(idx): void
  • Sets the current video track to the index provided, must be set after starting. It disables MBR, set it to undefined to reactivate MBR.

    Parameters

    • idx: undefined | number

    Returns void

Methods

  • Returns undefined | MediaSource

  • Parameters

    • audioTrack: number
    • videoTrack: number

    Returns void

  • Moves the playback head as close as possible to the live point, while respecting the configured bufferLimitLow and bufferLimitHigh buffer thresholds.

    Parameters

    • Optional reason: string

      add a log reason to display to explain this goLive call

    Returns void

  • Event unsubscription

    Parameters

    • name: "data" | "stop" | "start" | "metadata" | "Data" | "BufferState" | "Stall" | "AudioSkipping" | "VideoSkipping" | "bufferstate" | "stall" | "audioskipping" | "videoskipping" | "Metadata" | "TrackChange" | "FinalizeRequest" | "trackchange" | "finalizerequest" | "Start" | "Stop" | "AudioAppended" | "VideoAppended" | "audioappended" | "videoappended"

      Name of event without the 'on' prefix (ex: 'log' to 'onLog' event declared)

    • event: Function

      Unsubscriber Function, must be the one passed to on or once subscription methods

    Returns boolean

  • Event subscription

    Parameters

    • name: "data" | "stop" | "start" | "metadata" | "Data" | "BufferState" | "Stall" | "AudioSkipping" | "VideoSkipping" | "bufferstate" | "stall" | "audioskipping" | "videoskipping" | "Metadata" | "TrackChange" | "FinalizeRequest" | "trackchange" | "finalizerequest" | "Start" | "Stop" | "AudioAppended" | "VideoAppended" | "audioappended" | "videoappended"

      Name of event without the on prefix (ex: log to onLog event declared)

    • event: Function

      Subscriber Function

    • Optional options: {
          signal?: AbortSignal;
      }
      • Optional signal?: AbortSignal

        Optional AbortSignal to stop this or multiple subscriptions in same time

    Returns void

  • Event subscription only one time, once time fired it's automatically unsubscribe

    Parameters

    • name: "data" | "stop" | "start" | "metadata" | "Data" | "BufferState" | "Stall" | "AudioSkipping" | "VideoSkipping" | "bufferstate" | "stall" | "audioskipping" | "videoskipping" | "Metadata" | "TrackChange" | "FinalizeRequest" | "trackchange" | "finalizerequest" | "Start" | "Stop" | "AudioAppended" | "VideoAppended" | "audioappended" | "videoappended"

      Name of event without the on prefix (ex: log to onLog event declared)

    • event: Function

      Subscriber Function

    • Optional options: {
          signal?: AbortSignal;
      }
      • Optional signal?: AbortSignal

    Returns void

  • Starts playing the stream

    Parameters

    • params: Params

      Connection parameters Connect.Params

    • Optional idleTimeout: number

      idle timeout, default value is around 14s. It sets the timeout error in the absence of connection activity or data fetching, you can tune it to implement your reliable and consistent fallback mechanism.

    Returns void

    Example

    player.start({
    endPoint: <endPoint>
    });
  • Stops playback. If an error is provided, it is treated as an improper stop and propagated to onStop.

    Parameters

    • Optional error: PlayerError

      optional error describing why playback stopped improperly

    Returns void

Events

  • Event fire when audio data are appended to media source, basically here to debug MSE ingestion

    Parameters

    • data: Uint8Array

    Returns void

  • Event fired when data is received in the stream

    Parameters

    • trackId: number
    • time: number
    • data: any

    Returns void

  • Fired when the URL and headers can be finalized before sending the request to the server.

    Parameters

    • url: URL

      the request URL to finalize or modify if needed

    • headers: Headers

      the request headers to adjust if needed

    Returns void

  • Event fired when metadata is available in the stream.

    On the first occurrence, the optional return value allows specifying which track to use when starting the stream. By default, the middle-quality track is selected.

    Note that this differs from using videoTrack or audioTrack, where a specific track is fixed, which disables any Adaptive Bitrate algorithm.

    Parameters

    • metadata: Metadata

      The metadata received from the stream.

    Returns void | Tracks

    Optional tracks to use for initializing the stream.

  • Event fired when streaming starts

    Returns void

  • Event fired when streaming stops

    Parameters

    • Optional error: PlayerError

      error description when playback stopped improperly

    Returns void

  • Fire on a track change

    Parameters

    • audioTrack: number
    • videoTrack: number

    Returns void

  • Event fire when video data are appended to media source, basically here to debug MSE ingestion

    Parameters

    • data: Uint8Array

    Returns void