IMediaPlayerSourceObserver

Provides callbacks for media players.

onAudioVolumeIndication

Reports the volume of the media player.

onAudioVolumeIndication?(volume: number): void;

The SDK triggers this callback every 200 milliseconds to report the current volume of the media player.

Parameters

volume
The volume of the media player. The value ranges from 0 to 255.

onMetaData

Occurs when the media metadata is received.

onMetaData?(data: Uint8Array, length: number): void;

The callback occurs when the player receives the media metadata and reports the detailed information of the media metadata.

Parameters

data
The detailed data of the media metadata.
length
The data length (bytes).

onPlayBufferUpdated

Reports the playback duration that the buffered data can support.

  onPlayBufferUpdated?(playCachedBuffer: number): void;
When playing online media resources, the SDK triggers this callback every two seconds to report the playback duration that the currently buffered data can support.
  • When the playback duration supported by the buffered data is less than the threshold (0 by default), the SDK returns PlayerEventBufferLow.
  • When the playback duration supported by the buffered data is greater than the threshold (0 by default), the SDK returns PlayerEventBufferRecover.

Parameters

playCachedBuffer
The playback duration (ms) that the buffered data can support.

onPlayerEvent

Reports the player events.

  onPlayerEvent?(
    eventCode: MediaPlayerEvent,
    elapsedTime: number,
    message: string
  ): void;
  • After calling the seek method, the SDK triggers the callback to report the results of the seek operation.

Parameters

eventCode
The player events. See MediaPlayerEvent.
elapsedTime
The time (ms) when the event occurs.
message
Information about the event.

onPlayerInfoUpdated

Occurs when information related to the media player changes.

  onPlayerInfoUpdated?(info: PlayerUpdatedInfo): void;

When the information about the media player changes, the SDK triggers this callback. You can use this callback for troubleshooting.

Parameters

info
Information related to the media player. See PlayerUpdatedInfo.

onPlayerSourceStateChanged

Reports the changes of playback state.

  onPlayerSourceStateChanged?(
    state: MediaPlayerState,
    ec: MediaPlayerError
  ): void;

When the state of the media player changes, the SDK triggers this callback to report the current playback state.

Parameters

state
The playback state. See MediaPlayerState.
ec
The error code. See MediaPlayerError.

onPlayerSrcInfoChanged

Occurs when the video bitrate of the media resource changes.

  onPlayerSrcInfoChanged?(from: SrcInfo, to: SrcInfo): void;

Parameters

from
Information about the video bitrate of the media resource being played. See SrcInfo.
to
Information about the changed video bitrate of media resource being played. See SrcInfo.

onPositionChanged

Reports current playback progress.

  onPositionChanged?(positionMs: number): void;

When playing media files, the SDK triggers this callback every two second to report current playback progress.

Parameters

position
The playback position (ms) of media files.

onPreloadEvent

Reports the events of preloaded media resources.

  onPreloadEvent?(src: string, event: PlayerPreloadEvent): void;

Parameters

src
The URL of the media resource.
event
Events that occur when media resources are preloaded. See PlayerPreloadEvent.