The ApsaraVideo Player SDK for iOS supports playing standard live streams in formats such as RTMP, FLV, and HLS.
For more information about features, API reference, and FAQ, see iOS player.
Procedure
Step 1: Integrate the SDK
For more information, see Integrate ApsaraVideo Player SDK for iOS.
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.
AVPUrlSource *urlSource = [[AVPUrlSource alloc] urlWithString:url]; // Required. The playback URL. This can be a streaming URL from a third-party service or from ApsaraVideo Live. [self.player setUrlSource: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
To switch the definition, call the
switchStreammethod and pass the URL of the stream with the new definition.[self.player switchStream:newUrl];Definition switching notifications
The player returns callbacks when a definition switch succeeds or fails.
// Callback for a successful switch. - (void)onStreamSwitchedSuccess:(AliPlayer*)player URL:(NSString*)URL; // Callback for a failed switch. - (void)onStreamSwitchedFail:(AliPlayer*)player URL:(NSString*)URL errorModel:(AVPErrorModel *)errorModel;