switchSrc abstract method

Future<void> switchSrc({
  1. required String src,
  2. bool syncPts = true,
})

Switches the media resource being played.

You can call this method to switch the media resource to be played according to the current network status. For example: When the network is poor, the media resource to be played is switched to a media resource address with a lower bitrate. When the network is good, the media resource to be played is switched to a media resource address with a higher bitrate. After calling this method, if you receive the onPlayerEvent callback report the playerEventSwitchComplete event, the switching is successful. If the switching fails, the SDK will automatically retry 3 times. If it still fails, you will receive the onPlayerEvent callback reporting the playerEventSwitchError event indicating an error occurred during media resource switching. Ensure that you call this method after open. To ensure normal playback, pay attention to the following when calling this method: Do not call this method when playback is paused. Do not call the seek method during switching. Before switching the media resource, make sure that the playback position does not exceed the total duration of the media resource to be switched.

  • src The URL of the media resource.
  • syncPts Whether to synchronize the playback position (ms) before and after the switch: true : Synchronize the playback position before and after the switch. false : (Default) Do not synchronize the playback position before and after the switch.

Returns When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly.

Implementation

Future<void> switchSrc({required String src, bool syncPts = true});