MediaPlayerSourceObserver

Provides callbacks for the media player.

onAudioVolumeIndication

Callback for media player audio volume indication.

final void Function(int volume)? onAudioVolumeIndication;

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

Parameters

volume
Current volume of the media player, ranging from [0,255].

onMetaData

Reports retrieved media metadata.

final void Function(Uint8List data, int length)? onMetaData;

After parsing the media metadata, the SDK triggers this callback to report the type and content of the metadata.

Parameters

data
The actual data in a user-defined format.
length
The length of the data in bytes.

onPlayBufferUpdated

Reports the playable duration of buffered data.

final void Function(int playCachedBuffer)? onPlayBufferUpdated;
While playing online media resources, the SDK triggers this callback every second to report the duration that the current buffered data can support.
  • If the buffered duration is less than the threshold (default is 0), playerEventBufferLow (6) is returned.
  • If the buffered duration is greater than the threshold (default is 0), playerEventBufferRecover (7) is returned.

Parameters

playCachedBuffer
The duration (in milliseconds) that the current buffered data can support playback.

onPlayerCacheStats

Reports information about the media resources currently in cache.

final void Function(CacheStatistics stats)? onPlayerCacheStats;

After calling the openWithMediaSource method and setting the enableCache member to true, the SDK triggers this callback once per second after the media file is opened to report statistics of the currently cached media files.

Parameters

stats
Information about the media resources in cache. See CacheStatistics.

onPlayerEvent

Reports player events.

final void Function(
          MediaPlayerEvent eventCode, int elapsedTime, String message)?
      onPlayerEvent;
  • After calling seek to locate playback, the SDK triggers this callback to report the result of the seek operation.

Parameters

eventCode
Player event. See MediaPlayerEvent.
elapsedTime
The time when the event occurred (in milliseconds).
message
Information about the event.

onPlayerInfoUpdated

Callback when media player-related information changes.

final void Function(PlayerUpdatedInfo info)? onPlayerInfoUpdated;

When media player-related information changes, the SDK triggers this callback. You can use it for issue diagnosis and troubleshooting.

Parameters

info
Media player-related information. See PlayerUpdatedInfo.

onPlayerPlaybackStats

Reports information about the currently playing media resource.

final void Function(PlayerPlaybackStats stats)? onPlayerPlaybackStats;

After the media resource starts playing, the SDK triggers this callback once per second to report information about the media resource.

Parameters

stats
Information about the media resource. See PlayerPlaybackStats.

onPlayerSourceStateChanged

Reports changes in player state.

final void Function(MediaPlayerState state, MediaPlayerReason reason)?
    onPlayerSourceStateChanged;

When the player state changes, the SDK triggers this callback to report the new playback state.

Parameters

state
The new playback state. See MediaPlayerState.
reason
The reason for the player state change. See MediaPlayerReason.

onPlayerSrcInfoChanged

Callback for changes in video bitrate of media resource.

final void Function(SrcInfo from, SrcInfo to)? onPlayerSrcInfoChanged;

Parameters

from
Information about the video bitrate before the change during media playback. See SrcInfo.
to
Information about the video bitrate after the change during media playback. See SrcInfo.

onPositionChanged

Reports the current playback position of the media resource.

final void Function(int position)? onPositionChanged;

While playing media files, the SDK automatically triggers this callback every second to report the current playback position.

Parameters

positionMs
Current playback position in milliseconds.
timestampMs
NTP timestamp of the current playback position in milliseconds.

onPreloadEvent

Reports events during media resource preloading.

final void Function(String src, PlayerPreloadEvent event)? onPreloadEvent;

Parameters

src
Path of the media resource.
event
Event that occurred during media resource preloading. See PlayerPreloadEvent.