The ApsaraVideo Player SDK for Android supports playing standard live streams in formats such as RTMP, FLV, and HLS.
For more information about features, API reference, and FAQ, see ApsaraVideo Player SDK for Android.
Procedure
Step 1: Integrate the SDK
To integrate the SDK, see Integrate ApsaraVideo Player SDK for Android.
Step 2: Implement live stream playback
Get started.
To implement basic playback features, see Getting Started.
Set the live stream source.
The SDK supports two live stream playback methods: UrlSource and encrypted playback.
UrlSource
To play a live stream using the UrlSource method, set the setUrl property to the streaming URL. The URL can be a third-party streaming URL or a streaming URL from ApsaraVideo Live.
You can generate streaming URLs in the ApsaraVideo Live console using the URL generator.
UrlSource urlSource = new UrlSource(); urlSource.setUri("Playback URL");// The streaming URL. It can be a third-party streaming URL or a streaming URL from ApsaraVideo Live. aliPlayer.setDataSource(urlSource);Encrypted playback
For more information about live stream playback with DRM encryption, see Play an encrypted video.
Set multiple definitions.
NoteThis feature supports ApsaraVideo Live streaming URLs for original quality or transcoded streams. Default and custom transcoding are supported. For more information, see Use cases.
This feature is supported for live streams that use the ApsaraVideo Real-Time Communication (ARTC) or FLV protocol.
Set the group of pictures (GOP) size for stream ingest to 1s or 2s. A larger size may cause jumps when you switch streams.
For the streaming domain, enable Output RTMP timestamps during FLV playback and Output RTMP timestamps after upstream disconnection. In the transcoding configuration, enable Inherit timestamps from source and Inherit keyframes from source. Otherwise, stream switching may stutter or fail. To enable these options, submit a ticket.
Switching to a streaming URL that does not meet the preceding requirements will fail.
Switch definitions
Call the
switchStreammethod to switch the definition. Pass the URL that corresponds to the new definition.aliPlayer.switchStream(newUrl);Definition switching notifications
The player returns callbacks when a definition 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()); } });