Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Player

An interface describing the API of the media player.

Players are instantiated with the create function. The player communicates events asynchronously via Player.addEventListener.

Hierarchy

  • Player

Implemented by

Index

Methods

addEventListener

  • addEventListener<K>(name: K, fn: (payload: PlayerEventMap[K]) => void): void
  • Adds an event listener to the player. PlayerEventMap is a computed type which maps event names to their payloads.

    Remove listeners with Player.removeEventListener.

    Type parameters

    Parameters

    • name: K

      The name of the event. Available events include PlayerState events and PlayerEventType events.

    • fn: (payload: PlayerEventMap[K]) => void

      The handler function.

        • (payload: PlayerEventMap[K]): void
        • Parameters

          • payload: PlayerEventMap[K]

          Returns void

    Returns void

attachHTMLVideoElement

  • attachHTMLVideoElement(videoElement: HTMLVideoElement): void
  • Attaches a video element (tag) to be used for playback. This replaces any video element in use. This is optional; if it is not called, the Player creates and uses a video element.

    Parameters

    • videoElement: HTMLVideoElement

      The video element to attach.

    Returns void

delete

  • delete(): void
  • Removes the player instance and stops playback. After deletion, the player no longer emits events or responds to API calls.

    Returns void

getBufferDuration

  • getBufferDuration(): number
  • Gets the buffer length ahead of the current playback position.

    Returns number

    The duration, in seconds, from the playhead to the end of the buffer.

getBuffered

  • Gets the currently buffered range.

    Returns BufferRange

    The buffered range which the playhead is within.

getDisplayHeight

  • getDisplayHeight(): number
  • Gets the clientHeight of the underyling HTMLMediaElement.

    Returns number

    The clientHeight property of the active video element.

getDisplayWidth

  • getDisplayWidth(): number
  • Gets the clientWidth of the underyling HTMLMediaElement.

    Returns number

    The clientWidth property of the active video element.

getDuration

  • getDuration(): number
  • Gets the duration of the currently loaded media stream.

    Returns number

    The duration of the stream in seconds. When native video controls are enabled and the player is rendering via MediaSourceExtensions, the duration is 2^30 (1073741824). Otherwise, the duration is Infinity.

getHTMLVideoElement

  • getHTMLVideoElement(): HTMLVideoElement
  • Gets the video element in use.

    Returns HTMLVideoElement

    The video element in use.

getLiveLatency

  • getLiveLatency(): number
  • For a live stream, the latency to the source.

    Returns number

    the latency in seconds.

getPlaybackRate

  • getPlaybackRate(): number
  • Gets the playback rate.

    Returns number

    The playback of the rate of the player.

getPosition

  • getPosition(): number
  • Gets the playback position.

    Returns number

    The current position of the player, in seconds. When the player is rendering via MediaSourceExtensions, the starting position is 0. Otherwise, the starting position is relative to the current duration of the stream.

getQualities

  • Returns Quality[]

    Set of available Quality objects from the loaded source or empty if none are currently available. The qualities will be available after the PlayerState.READY state has been entered. This set contains the qualities that can be used with Player.setQuality. Note that this set will contain only qualities capable of being played on the current device and not all those present in the source stream.

getQuality

  • Gets the quality that the player is using.

    Returns Quality

    The current quality of the source.

getSessionId

  • getSessionId(): string | undefined
  • Gets the ID of the playback session.

    Returns string | undefined

    A unique identifier ID of the current play session, or undefined if the session is not yet known. The ID is known after the player enters the PlayerState.READY state. This session identifier can be shared with support or displayed in an user interface to help troubleshoot or diagnose playback issues with the currently playing stream.

getState

  • Gets the state of the player.

    Returns PlayerState

    The current state of the player.

getVersion

  • getVersion(): string
  • Gets the version of the player.

    Returns string

    The semantic version of the player.

getVolume

  • getVolume(): number
  • Gets the player's volume level.

    Returns number

    The volume level of the player, between 0.0f and 1.0f.

isAutoQualityMode

  • isAutoQualityMode(): boolean
  • Gets whether the Adaptive Bitrate (ABR) streaming algorithm is enabled. The maximum quality is controlled by Player.setAutoMaxQuality.

    Returns boolean

    True if ABR is enabled, false otherwise.

isAutoplay

  • isAutoplay(): boolean
  • Gets whether autoplay is enabled. Defaults to false.

    Returns boolean

    True if autoplay is enabled, false otherwise.

isLiveLowLatency

  • isLiveLowLatency(): boolean
  • Gets whether low-latency live streaming is enabled.

    Returns boolean

    True if low-latency streaming is enabled on both the server and the client, false otherwise.

isMuted

  • isMuted(): boolean
  • Gets whether the player is muted.

    Returns boolean

    True if the player is muted, false otherwise.

isPaused

  • isPaused(): boolean
  • Gets whether the player is paused.

    Returns boolean

    True if the player is paused, otherwise false. This flag reflects pauses initiated by the user, autoplay failure, and error handling.

load

  • load(path: string, mediaType?: string): void
  • Loads the specified stream and prepares the player for playback. On success, the player state changes to PlayerState.READY. On failure, this invokes the PlayerEventType.ERROR listener.

    Parameters

    • path: string

      The URL of the stream to load.

    • Optional mediaType: string

      Media type of the content if known; for example, 'video/mp4' or 'application/x-mpegURL'. If not provided, the type is inferred from the path.

    Returns void

pause

  • pause(): void
  • Pauses playback of the current stream or fails if no stream is loaded. On failure invokes the onError listener method.

    If you resume the stream with play, the position may be different than where it paused, depending on the type of media being played.

    Returns void

play

  • play(): void
  • Starts or resumes playback of the stream, if no stream is loaded indicates intent to play and the player will automatically play on a subsequent load call. On success, depending on the type of stream, the player state changes to PlayerState.BUFFERING and then PlayerState.PLAYING, or just PlayerState.PLAYING. On failure, this invokes the PlayerEventType.ERROR listener. This does not need to be called if autoplay is enabled.

    Returns void

removeEventListener

  • removeEventListener<K>(name: K, fn: (payload: PlayerEventMap[K]) => void): void
  • Removes an event listener from the player. PlayerEventMap is a computed type which maps event names to their payloads.

    Type parameters

    Parameters

    • name: K

      The name of the event. Available events include PlayerState events and PlayerEventType events.

    • fn: (payload: PlayerEventMap[K]) => void

      The handler function.

        • (payload: PlayerEventMap[K]): void
        • Parameters

          • payload: PlayerEventMap[K]

          Returns void

    Returns void

seekTo

  • seekTo(time: number): void
  • Seeks to a specified time in the stream and begins playing at that position if play() was called. If no stream is loaded the seek will be be deferred until load is called. On success, depending on the type of stream, the player state changes to PlayerState.BUFFERING and then PlayerState.PLAYING, or just PlayerState.PLAYING. On failure, this invokes the PlayerEventType.ERROR listener.

    Parameters

    • time: number

      The position to seek to, in seconds.

    Returns void

setAutoMaxQuality

  • setAutoMaxQuality(quality: Quality): void
  • Sets the maximum quality the player is allowed to auto-switch up to (if ABR is enabled). This allows you to control resource usage. The Quality you provide here is applied to the current stream. If you load a new stream, call this again after PlayerState.READY.

    Parameters

    • quality: Quality

      The maximum quality to use for ABR.

    Returns void

setAutoQualityMode

  • setAutoQualityMode(enable: boolean): void
  • Enables or disables the Adaptive Bitrate (ABR) streaming algorithm. Note the maximum quality is controlled by Player.setAutoMaxQuality. The player chooses the quality to play based on current network and device conditions. By default, the player starts in this mode. This mode is implicitly disabled by a call to Player.setQuality.

    Parameters

    • enable: boolean

      True to enable ABR, false to disable.

    Returns void

setAutoplay

  • setAutoplay(enabled: boolean): void
  • Enables or disables playback autoplay. Defaults to false.

    Parameters

    • enabled: boolean

      True to enable autoplay, false otherwise.

    Returns void

setLiveLowLatencyEnabled

  • setLiveLowLatencyEnabled(enable: boolean): void
  • Enables low-latency playback for live streams configured to support it. Changing this value during playback restarts the stream.

    Parameters

    • enable: boolean

      True to enable, false to disable. Default: true.

    Returns void

setLogLevel

  • Sets the log level for the player.

    Parameters

    Returns void

setMuted

  • setMuted(mute: boolean): void
  • Mutes or unmutes the player.

    Parameters

    • mute: boolean

      True to mute the player, false to unmute.

    Returns void

setPlaybackRate

  • setPlaybackRate(rate: number): void
  • Sets the stream playback rate.

    Parameters

    • rate: number

      Playback rate to set. Valid values: in the range [0.25, 2.0].

    Returns void

setQuality

  • setQuality(quality: Quality, adaptive?: boolean): void
  • Sets the quality the player should use for playback. This call disables adaptive bitrate (ABR) streaming.

    Parameters

    • quality: Quality

      A valid quality entry from Player.getQualities.

    • Optional adaptive: boolean

      True for an adaptive quality change; that is, to change quality smoothly at the end of the current buffer. False to change quality immediately.

    Returns void

setVolume

  • setVolume(volume: number): void
  • Sets the playback volume of the audio track, for the current stream or the next stream that is loaded.

    Parameters

    • volume: number

      The volume to be set. Valid values: in the range 0.0f to 1.0f.

    Returns void

Generated using TypeDoc