Real-Time Streaming (RTS) is a value-added feature of ApsaraVideo Live. The ApsaraVideo Player SDK uses RTS to deliver live streaming with millisecond-level latency for millions of concurrent users. This resolves the 3- to 6-second latency issue found in traditional live streaming. It provides an ultra-low latency, low-stuttering, and instant playback experience. This topic describes how to implement RTS playback.
For more information about features, API documentation, and the FAQ, see Android player.
RTS playback
The ApsaraVideo Player SDK for Android integrates the native RTS SDK to enable low-latency live streaming on native clients. For more information, see Implement RTS stream pulling on Android.
For a detailed code example, see the RTS ultra-low latency live playback (RtsLiveStream) module in API-Example. This Java-based sample project for the ApsaraVideo Player SDK for Android helps developers quickly learn how to integrate the core features of the SDK.
RTS resolution switching
This feature supports ApsaraVideo Live playback URLs and transcoded stream URLs. Both default and custom transcoding are supported. For more information about live stream transcoding, see Transcoding management. For more information about how to generate streaming URLs, see Generate streaming URLs.
Resolution switching is supported for live streams that use the RTS and HTTP-FLV protocols.
The group of pictures (GOP) size of the ingested stream must be 1 second or 2 seconds. A larger GOP size may cause playback to skip when you switch streams.
For the streaming domain, enable the Output RTMP timestamps during FLV playback and Output RTMP timestamps after upstream interruption options. For the transcoding configuration, enable the Source timestamp and Source keyframe options. Otherwise, stream switching may stutter or fail. To enable these options, submit a ticket.
If you switch to a stream URL that does not meet these requirements, the switch fails.
Switch resolutions
To switch resolutions, call the switchStream method and pass the URL for the new resolution.
// Start playback
aliPlayer.setUrlSource(oldUrl);
aliPlayer.prepare();
aliPlayer.start();
// Switch to another URL during playback
aliPlayer.switchStream(newUrl);Resolution switch notifications
The following callbacks are triggered when a resolution switch succeeds or fails.
aliPlayer.setOnStreamSwitchedListener(new IPlayer.OnStreamSwitchedListener() {
@Override
public void onSwitchedSuccess(String url) {
Log.i("SwitchStream", "switch success, url = " + url);
}
@Override
public void onSwitchedFail(String url, ErrorInfo errorInfo) {
Log.i("SwitchStream", "switch failed, url = " + url + ", error=" + errorInfo.getMsg());
}
});