MediaSource

Information and playback settings for the media file to be played.

export class MediaSource {

  url?: string;

  uri?: string;

  startPos?: number;

  autoPlay?: boolean;

  enableCache?: boolean;

  isAgoraSource?: boolean;

  isLiveSource?: boolean;
}

Properties

url
URL of the media resource to be played.
uri
URI (Uniform Resource Identifier) of the media file, used to identify the media file.
startPos
Start playback position in milliseconds. Default is 0.
autoPlay
Note: If you disable auto-play, call the play method after opening the media file to start playback.
Whether to enable auto-play after opening the media file:
  • true: (Default) Enable auto-play.
  • false: Disable auto-play.
enableCache
Note:
  • The SDK currently only supports caching for on-demand streams, not for on-demand streams transmitted via HLS.
  • Set a value for uri before enabling caching; otherwise, the player uses the media file's url as the cache index.
  • When real-time caching is enabled, the player preloads part of the media file to local storage. When you play the file again, the player loads data from the cache to save bandwidth. The statistics of the cached media file update every second after playback starts. See CacheStatistics.
Whether to enable real-time caching for this playback:
  • true: Enable real-time caching.
  • false: (Default) Disable real-time caching.
enableMultiAudioTrack
Whether to allow selecting different audio tracks for this playback:
  • true: Allow selecting different audio tracks.
  • false: (Default) Do not allow selecting different audio tracks.
If you need to set different audio tracks for local playback and publishing to remote, set this parameter to true and then call the selectMultiAudioTrack method to set the audio track.
isAgoraSource
Note: If the media resource you want to open is a live or on-demand stream distributed via Agora's CDN, pass the stream URL to url and set isAgoraSource to true. Otherwise, you do not need to set isAgoraSource.
Whether the opened media resource is a live or on-demand stream distributed via Agora's CDN:
  • true: The media resource is distributed via Agora's CDN.
  • false: (Default) The media resource is not distributed via Agora's CDN.
isLiveSource
Note: Only when the media resource is a live stream, setting isLiveSource to true can speed up the opening of the media resource.
Whether the opened media resource is a live stream:
  • true: Live stream.
  • false: (Default) Not a live stream.
If the media resource is a live stream, it is recommended to set this parameter to true to speed up the opening of the live stream.