All Products
Search
Document Center

ApsaraVideo Live:Standard streaming playback

Last Updated:Aug 13, 2025

The Alibaba Cloud Player SDK for iOS supports standard live stream playback in formats such as RTMP, FLV, and HLS. This topic describes how to implement this feature.

Important

For more information about features, API documentation, and FAQ, see Player for iOS.

Procedure

Step 1: Integrate the SDK

For more information, see Integrate the Player SDK for iOS.

Step 2: Implement live stream playback

  1. Get started.

    For more information about how to implement basic playback, see Getting Started with Player for iOS.

  2. Set the live stream source.

    The Player SDK for iOS supports two playback methods for live streams: playback from a URL source and encrypted playback.

    Live stream playback from a URL source

    To play a live stream from a URL, set the source property of the player to the streaming URL. The streaming URL can be from a third-party service or from ApsaraVideo Live.

    You can use the URL generator in the ApsaraVideo Live console to generate a streaming URL. For more information, see 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];

    DRM-encrypted live stream playback

    For more information about DRM-encrypted live stream playback, see Play encrypted videos.

  3. Set multiple definitions.

    Note
    • This feature supports playback URLs from ApsaraVideo Live or 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 obtain URLs, see Generate ingest and streaming URLs.

    • Resolution switching is supported for live streams that use the Alibaba Real-Time Communication (ARTC) protocol or the FLV protocol.

    • The group of pictures (GOP) size for stream ingest must be set to 1 s or 2 s. A larger GOP size may cause playback to jump when you switch streams.

    • For the playback domain name, you must enable the following options: Output RTMP timestamp for FLV playback and Output RTMP timestamp after upstream is disconnected. For the transcoding configuration, you must enable the following options: Timestamp follows source and Keyframe follows source. If these options are not enabled, 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 will fail.

    Switch definitions

    To switch the definition, call the switchStream method and pass the URL of the stream with the new definition.

    [self.player switchStream:newUrl];

    Definition switching notifications

    Callbacks are provided for successful and failed definition switching.

    // 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;