switchSrc

Switches the currently playing media resource.

int switchSrc(String src, boolean syncPts);
You can call this method to switch the media resource URL 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 PLAYER_EVENT_SWITCH_COMPLETE event, the switch is successful. If the switch fails, the SDK will automatically retry 3 times. If it still fails, you will receive the onPlayerEvent callback reporting the PLAYER_EVENT_SWITCH_ERROR event, indicating an error occurred during the switch.
Note:
  • Make sure to call this method after calling open.
  • To ensure normal playback, note 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 media resources, ensure the playback position does not exceed the total duration of the media to be switched to.

Parameters

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

Return Values

  • 0: Success.
  • < 0: Failure.