The Alibaba Cloud Player SDK for Android supports standard live stream playback in formats such as RTMP, FLV, and HLS. This topic describes how to implement standard live stream playback.
For more information about features, API documentation, and FAQ, see Player for Android.
Procedure
Step 1: Integrate the SDK
To integrate the SDK, see Integrate the Player SDK for Android.
Step 2: Implement live stream playback
Get started.
To implement basic playback, see Quick Start for Player for Android.
Set the live stream source.
The Player SDK for Android supports two live stream playback methods: UrlSource playback and encrypted playback.
Live stream playback using UrlSource
To play a live stream using the UrlSource method, set the player's 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 ApsaraVideo Live streaming URLs in the console using the URL generator. For more information, see URL generator.
UrlSource urlSource = new UrlSource(); urlSource.setUri("Playback URL");// The playback URL. This can be a third-party streaming URL or a streaming URL from ApsaraVideo Live. aliPlayer.setDataSource(urlSource);Live stream playback with DRM encryption
For more information about live stream playback with DRM encryption, see How to play encrypted videos.
Set multiple definitions.
NoteThis feature supports playback URLs from ApsaraVideo Live or transcoded stream URLs. Default and custom transcoding are supported. For more information about live stream transcoding, see Transcoding management. For information about how to obtain URLs, see Generate ingest URLs and streaming URLs.
Switching between different definitions is supported for live streams that use the Alibaba Real-Time Communication (ARTC) or FLV protocol.
Set the group of pictures (GOP) size for stream ingest to 1 s or 2 s. A larger size may cause jumps when you switch streams.
For the playback domain name, enable the following options: Output RTMP timestamps during FLV playback and Output RTMP timestamps after the upstream is disconnected. For the transcoding configuration, enable the following options: Timestamps follow the source and Keyframes follow the source. Otherwise, stream switching will stutter or fail. To enable these options, submit a ticket.
Switching to a stream URL that does not meet the preceding requirements will fail.
Switch definitions
You can 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()); } });