switchSrc abstract method

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

Switches the media resource.

You can call this method to switch the bitrate of the media resource being played based on the current network conditions. For example: When the network is poor, switch to a lower bitrate media resource. When the network is good, switch to a higher bitrate media resource. After calling this method, if you receive the onPlayerEvent callback reporting the playerEventSwitchComplete event, the media resource has been switched successfully. If the switch fails, the SDK retries 3 times. If it still fails, you receive the onPlayerEvent callback reporting the playerEventSwitchError event, indicating an error occurred during the switch. Make sure to call this method after open. To ensure normal playback, note the following when calling this method: Do not call this method while playback is paused. Do not call seek during bitrate switching. Ensure the playback position before switching does not exceed the total duration of the media resource to be switched.

  • src Network path of the media resource.
  • syncPts Whether to synchronize the start playback position before and after switching: true : Synchronize. false : (Default) Do not synchronize.

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. See Error Codes for details and resolution suggestions.

Implementation

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