MediaSource

Used to configure the media file to be played and the playback scenario.

struct MediaSource {
  const char* url;
  const char* uri;
  int64_t startPos;
  bool autoPlay;
  bool enableCache;
  bool enableMultiAudioTrack;
  Optional<bool> isAgoraSource;
  Optional<bool> isLiveSource;
  IMediaPlayerCustomDataProvider* provider;
};

Properties

url
URL of the media file to be played.
Note: If opening a regular media resource, pass url. If opening a custom media resource, pass provider. Agora recommends not passing both parameters in a single call, otherwise the call may fail.
uri
URI (Uniform Resource Identifier) of the media file.
startPos
Start position of playback (in milliseconds). Default is 0.
autoPlay
Note: If auto play is disabled, you need to call the play method after opening the media file.
Whether to automatically play after opening the media file:
  • true: (default) Automatically play.
  • false: Do not automatically play.
enableCache
Note: Agora only supports caching of on-demand audio and video streams that are not transmitted via HLS protocol. To enable caching, pass uri; otherwise, caching is based on the media file's url. Once enabled, the media player will cache part of the media file locally during playback, allowing playback even without a network connection. Cache statistics are updated every second after playback. See CacheStatistics.
Whether to enable caching when playing media files:
  • true: Enable caching.
  • false: (default) Do not enable caching.
enableMultiAudioTrack
Note: If you need to set different audio tracks for local playback and publishing to the channel, set this parameter to true, then call the selectMultiAudioTrack method to select the track.
Whether to allow selecting different audio tracks when playing the media file:
  • true: Allow selecting different audio tracks.
  • false: (default) Do not allow selecting different audio tracks.
isAgoraSource
Note: If you need to open a live stream or on-demand video distributed via Agora's ultra-low latency live streaming service, pass the media resource URL to url and set isAgoraSource to true; otherwise, you do not need to set this parameter.
Whether the media resource to be opened is a live stream or on-demand video distributed via Agora's ultra-low latency live streaming service:
  • true: The media resource is distributed via Agora's ultra-low latency live streaming service.
  • false: (default) The media resource is not distributed via Agora's ultra-low latency live streaming service.
isLiveSource
Note: If the media resource to be opened is a live stream, Agora recommends setting this parameter to true to speed up live stream loading. If the media resource is not a live stream but isLiveSource is set to true, loading speed will not be improved.
Whether the media resource to be opened is a live stream:
  • true: The media resource is a live stream.
  • false: (default) The media resource is not a live stream.
provider
Callback for custom media resource files. See IMediaPlayerCustomDataProvider.
Note: If opening a custom media resource, pass provider. If opening a regular media resource, pass url. Agora recommends not passing both url and provider in a single call, otherwise the call may fail.