All Products
Search
Document Center

ApsaraVideo Live:Implement RTS stream pulling on iOS

Last Updated:Jan 14, 2026

This topic describes how to use the ApsaraVideo Player SDK for iOS to implement RTS.

Prerequisites

CocoaPods is installed in your environment.

Integrate the SDK

Add the ApsaraVideo Player SDK as a dependency using CocoaPods.

  1. Open a terminal window.

  2. Navigate to your project directory and create a Podfile.

    pod init

  3. Edit the Podfile to add the required dependencies.

    player_sdk_version = 'x.x.x' # Use the latest version.
    rts_sdk_version = '7.11.0' # Independent version number. This is the latest version.
    
    # ApsaraVideo Player SDK 
    pod 'AliPlayerSDK_iOS' , player_sdk_version
    # The bridge layer (AlivcArtc) between the player and the RTS component. The version number must be the same as the player's version number. This must be integrated with the RTS component.
    pod 'AliPlayerSDK_iOS_ARTC' , player_sdk_version
    # RTS component
    pod 'RtsSDK' , rts_sdk_version 
    Important
    • The version number of the bridge layer (AlivcArtc) must match the version number of the player. You must integrate this bridge layer, which connects the player to the RTS component.

    • For more information about player versions, see SDK download. ApsaraVideo Player V7.11.0 or later is recommended. The minimum supported version is V5.4.5.0.

    • For more information about common issues, see FAQ about ApsaraVideo Player for iOS.

  4. Install the SDK. After you run the command, an .xcworkspace file is generated. The presence of this file indicates that the SDK is integrated.

    pod install

Use the ApsaraVideo Player SDK API

You can call the ApsaraVideo Player SDK API to implement the RTS feature. For more information about the features of the ApsaraVideo Player SDK, see Advanced features and API reference.

Note
  • The following code is an example. For more information, see the RTS playback module in the API-Example project. The API-Example project is an Objective-C demo for the ApsaraVideo Player SDK for iOS that helps developers quickly learn how to integrate the core features of the SDK.

  • When you use ApsaraVideo Player for RTS stream pulling, do not call pause to pause the live stream. Instead, call stop to stop the playback and then call prepare to restart it.

  • The seek (drag) operation is not supported.

Create a player

  1. Create a player.

    Create an AliPlayer instance.

    // Create a player instance.
    AliPlayer mAliPlayer = [[AliPlayer alloc] init];
    
    // Create a view container for the playback video and set the rendering view for the player.
    UIView playerView = [[UIView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:playerView];
    mAliPlayer.playerView = playerView;
    
    [mAliPlayer setTraceID:traceId];
    Note

    Player features, such as Playback quality monitoring (which lets you view data about the player's overall playback quality), Single-point tracing (which lets you locate specific users or devices, analyze their playback behavior, and quickly identify issues such as abnormal playback), and Video playback statistics, rely on the instrumentation log reporting feature.

    When you create a player, the available features vary based on the setTraceID parameter setting:

    • If you do not pass the setTraceID parameter (default): The instrumentation log reporting feature is enabled. You can use the playback quality monitoring and video playback statistics features, but you cannot use the single-point tracing feature.

    • If you pass a traceId to the setTraceID parameter: You must define the value of traceId. The traceId must be a unique identifier for a user or device, such as a user ID from your application, an International Mobile Equipment Identity (IMEI), or an identifier for advertisers (IDFA). After you pass the traceId, the instrumentation log reporting feature is enabled. You can then use the playback quality monitoring, single-point tracing, and video playback statistics features.

    • If you set the setTraceID parameter to DisableAnalytics: The instrumentation log reporting feature is disabled. You cannot use the playback quality monitoring, single-point tracing, or video playback statistics features.

  2. Set the playback source.

    The player supports four types of playback sources: VidSts, VidAuth, VidMps, and UrlSource. To play a video from a URL, use UrlSource. To use the RTS service, you must set the URL protocol to artc://.

    AVPUrlSource *urlSource = [[AVPUrlSource alloc] 
    urlWithString:"artc://<streaming URL>"]; 
    [mAliPlayer setUrlSource:urlSource];
    Note

    For more information about how to set a playback source, see Basic features.

  3. Configure playback parameters.

    You can configure playback parameters to improve the performance of RTS.

    Note

    ApsaraVideo Player SDK V6.3.0 and later support automatic optimal configuration for low-latency playback. If the playback URL starts with "artc://" and you have not manually modified the MaxDelayTime, HighBufferDuration, or StartBufferDuration values of AVPConfig, the SDK automatically sets these parameters to 1000, 10, and 10, respectively.

    To customize these parameters, see the following example:

    //1. Get and modify the configuration.
    AVPConfig *config = mAliPlayer.getConfig;
    
    if ([playUrl hasPrefix:@"artc://"]) {
        // The maximum latency is 1 second.
        [config setMaxDelayTime:1000];
        // The buffer duration for playback startup.
        [config setStartBufferDuration:10];
        // The buffer duration for stuttering recovery.
        [config setHighBufferDuration:10];
    } else {
        // Use the default configuration for config or customize it.
    }
    
    //2. Apply the configuration.
    [mAliPlayer setConfig:config];
  4. Start the playback.

    // Prepare for playback.
    [mAliPlayer prepare];
    // After prepare is called, synchronously call the start operation. Playback starts automatically after the onPrepared callback is complete.
    [mAliPlayer start];

Control playback

The ApsaraVideo Player SDK for iOS supports common operations, such as starting playback and seeking to a specified time.

  1. Start playback

You can start video playback using the start API. The following code is an example:

 [mAliPlayer start];
  1. Stop playback

You can stop video playback using the stop API. The following code is an example:

[mAliPlayer stop];
  1. Destroy the player

You can destroy the player instance synchronously or asynchronously. The following code is an example:

// Synchronous destroy. The stop API is automatically called internally.
[mAliPlayer destroy];
// Asynchronous destroy. The stop API is automatically called internally.
[mAliPlayer destroyAsync];
Note

When you call the synchronous destroy API, the system returns a response only after the player resources are completely released. If a fast interface response is required, use the asynchronous destroy API and note the following points:

  1. Do not perform any other operations on the player object during the asynchronous destroy process.

  2. Do not manually stop the player before calling the asynchronous destroy API because the process already includes an asynchronous stop procedure.

Accessibility

  1. Enable or disable logs

    // Enable logs.
    [mAliPlayer setEnableLog:YES];
    [mAliPlayer setLogCallbackInfo:LOG_LEVEL_TRACE callbackBlock:nil];
    
    // Disable logs.
    [mAliPlayer setEnableLog:NO];
    [mAliPlayer setLogCallbackInfo:LOG_LEVEL_NONE callbackBlock:nil];
  2. Live stream fallback

    Note
    • Playback failure fallback applies only to timeout scenarios. If a fallback solution is configured, the system performs a fallback playback when a timeout occurs. Otherwise, the onError callback of the player is triggered. Exceptions such as 404 errors, 403 errors, or streamer disconnections do not trigger a fallback.

    • Automatic RTS fallback uses the same domain name to fall back from RTS to FLV. If your RTS and FLV domain names are different, configure a custom RTS fallback solution to specify the target FLV domain name.

    1. Automatic RTS fallback (enabled by default)

      When you play a video from an RTS URL, if custom RTS fallback is not configured and RTS stream pulling fails, the system automatically falls back to the default FLV URL that corresponds to the RTS URL for playback. The following code is an example:

      // 1: enabled. 0: disabled. By default, this feature is enabled.
      [AliPlayerGlobalSettings setOption:ALLOW_PRE_RENDER valueInt:1];
    2. Custom RTS fallback

      When you play a video from an RTS URL, you can set a fallback URL, such as an HLS or FLV URL. If RTS stream pulling fails, the system automatically falls back to this URL for playback.

      // Set the fallback source downgradeUrl.
      AVPUrlSource *urlSource = [[AVPUrlSource alloc] urlWithString:downgradeUrl];
      // Optional. Configure other items for config.
      AVPConfig *config = [mAliPlayer getConfig];
      // Set the fallback URL.
      [mAliPlayer enableDowngrade:urlSource config:config];
  3. Obtain the TraceID

    Each low-latency playback has a traceId that can be used for troubleshooting. You can obtain the traceId through the player's event callback.

    // Listen for the onPlayerEvent callback of the player and parse the DemuxerTraceID message.
    - (void)onPlayerEvent:(AliPlayer*)mAliPlayer eventWithString:(AVPEventWithString)eventWithString description:(NSString *)description {
        switch (eventWithString) {
            case EVENT_PLAYER_DEMUXER_TRACE_ID:
                {
                    NSString *traceId = description;
                }
                    break;
                default:
                    break;
        }
    }