switchSrc
Switches the currently playing media resource.
virtual int switchSrc(const char* src, bool syncPts = true) = 0;
You can call this method to switch the media resource being played based on the current network condition. 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.
PLAYER_EVENT_SWITCH_COMPLETE event, the switch is successful. If the switch fails, the SDK automatically retries three times. If it still fails, the onPlayerEvent callback reports the PLAYER_EVENT_SWITCH_ERROR event, indicating failure.Note:
- Make sure to call this method after calling the open method.
- To ensure normal playback, pay attention to the following when calling this method:
- Do not call this method while playback is paused;
- Do not call the seek method during the switching process;
- Before switching, ensure that the current playback position does not exceed the total duration of the target media resource.
Parameters
- src
- The 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 switching.
- false: (Default) Do not synchronize the playback position before and after switching.
Return Values
- 0: Success.
- < 0: Failure.