All Products
Search
Document Center

ApsaraVideo Live:Implement RTS stream pulling on Android

Last Updated:Feb 28, 2026

Integrate the ApsaraVideo Player SDK into your Android app to pull live streams over Real-Time Streaming (RTS) with ultra-low latency.

Before you begin

Before you begin, ensure that you have:

  • An RTS streaming URL that uses the artc:// protocol

  • ApsaraVideo Player SDK V5.4.5.0 or later. For download links, see SDK download

RTS limitations

Keep these RTS-specific limitations in mind:

  • No pause support. Calling pause on a live RTS stream is not supported. Call stop to end playback, then call prepare to resume.

  • No seeking. Seeking (dragging) is not supported.

Integrate the SDK

Add the ApsaraVideo Player SDK and RTS dependencies through Maven.

  1. Add the Maven repository to the build.gradle file in the project root directory.

    // Maven repository for Alibaba Cloud SDKs (ApsaraVideo Player)
    maven { url 'http://maven.aliyun.com/nexus/content/repositories/releases' }
  2. Add the following dependencies to the app/build.gradle file.

    def player_sdk_version = "x.x.x" // We recommend using the latest version.
    def rts_sdk_version = "7.12.0" // Independent version number, currently the latest version.
    
    // Player main library
    implementation "com.aliyun.sdk.android:AliyunPlayer:$player_sdk_version-full"
    
    // RTS bridge component (AlivcArtc). The version number must match the player version exactly.
    // Must be integrated together with the RTS component.
    implementation "com.aliyun.sdk.android:AlivcArtc:$player_sdk_version"
    
    // RTS component
    implementation "com.aliyun.rts.android:RtsSDK:$rts_sdk_version"
Note

The RTS bridge component (AlivcArtc) version must match the player version exactly. Integrate it together with the RTS component. For FAQs, see Android Player FAQ.

Implement RTS playback

Call ApsaraVideo Player SDK methods to play an RTS stream. For other player capabilities, see Advanced features and API reference.

Note

The following code samples are simplified. For complete code, see the RTS Real-Time Streaming playback module in the API-Example project.

Step 1: Load the RTS library

Add the static initializer to your Activity:

static {
    System.loadLibrary("RtsSDK");
}

Step 2: Create a player

Create an AliPlayer instance using the AliPlayerFactory class.

// Create a player instance
AliPlayer mAliPlayer = AliPlayerFactory.createAliPlayer(context);
// Optional: Set a trace ID for single-point tracing
// Use a unique identifier for the user or device, such as a user ID, IMEI, or IDFA.
mAliPlayer.setTraceId("traceId");
Note

The player supports Playback Quality Monitoring, Single-Point Troubleshooting, and Video Playback Statistics. All three features rely on instrumentation log reporting. The setTraceId parameter controls which features are available:

setTraceId valueLog reportingQuality monitoringSingle-point tracingPlayback statistics
Not set (default)EnabledAvailableNot availableAvailable
Custom value (e.g., user ID)EnabledAvailableAvailableAvailable
DisableAnalyticsDisabledNot availableNot availableNot available

Step 3: Set the display view

The player supports three view types: AliDisplayView (recommended), SurfaceView, and TextureView.

Option A: AliDisplayView (recommended)

Declare the view in the XML layout:

<!-- Player rendering view -->
<com.aliyun.player.videoview.AliDisplayView
    android:id="@+id/ali_display_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center" />

Bind the view to the player:

AliDisplayView mAliDisplayView = findViewById(R.id.display_view);
// Set the playback view type using setPreferDisplayView()
mAliDisplayView.setPreferDisplayView(AliDisplayView.DisplayViewType.SurfaceView);
mAliPlayer.setDisplayView(mAliDisplayView);

Option B: SurfaceView

Declare the view in the XML layout:

<!-- Player rendering view -->
<SurfaceView
    android:id="@+id/surface_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center" />

Bind the surface to the player:

SurfaceView mSurfaceView = findViewById(R.id.surface_view);
mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
    @Override
    public void surfaceCreated(@NonNull SurfaceHolder holder) {
        mAliPlayer.setSurface(holder.getSurface());
    }

    @Override
    public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
        mAliPlayer.surfaceChanged();
    }

    @Override
    public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
        mAliPlayer.setSurface(null)
    }
});

Option C: TextureView

Declare the view in the XML layout:

<!-- Player rendering view -->
<TextureView
    android:id="@+id/texture_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center" />

Bind the surface to the player:

TextureView mTextureView = findViewById(R.id.texture_view);
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
    @Override
    public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surface, int width, int height) {
        mAliPlayer.setSurface(new Surface(surface));
    }

    @Override
    public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {
        mAliPlayer.surfaceChanged();
    }

    @Override
    public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
        mAliPlayer.setSurface(null);
        return true;
    }

    @Override
    public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {

    }
});

Step 4: Set the playback source

The player supports four playback source types: VidSts, VidAuth, VidMps, and UrlSource. For RTS playback, use UrlSource with an artc:// URL.

UrlSource urlSource = new UrlSource();
urlSource.setUri("artc://<Streaming URL>");
mAliPlayer.setDataSource(urlSource);

For details on other playback source types, see Basic Features.

Step 5: Configure low-latency parameters

ApsaraVideo Player SDK V6.3.0 and later automatically applies optimal low-latency settings when the playback URL starts with artc:// and mMaxDelayTime, mHighBufferDuration, and mStartBufferDuration in PlayerConfig have not been manually modified. The automatic values are:

ParameterValueDescription
mMaxDelayTime1000 msMaximum delay
mStartBufferDuration10 msBuffer duration for playback startup
mHighBufferDuration10 msBuffer duration for stuttering recovery

To override these defaults, configure them manually:

// 1. Get and modify the configurations
PlayerConfig config = mAliPlayer.getConfig();
if (playUrl.startWith("artc://")) {
    // Maximum delay: 1000 milliseconds
    config.mMaxDelayTime = 1000;
    // Buffer duration for playback startup: 10 milliseconds
    config.mStartBufferDuration = 10;
    // Buffer duration for stuttering recovery: 10 milliseconds
    config.mHighBufferDuration = 10;
} else {
    // Use default configurations or customize to other configurations
}

// 2. Apply the configurations
mAliPlayer.setConfig(config);

Step 6: Start playback

// Prepare for playback
mAliPlayer.prepare();
// Start playback
mAliPlayer.start();

Control playback

Start

mAliPlayer.start();

Stop

mAliPlayer.stop();

Destroy the player

Destroy the player instance using synchronous or asynchronous destruction.

// Synchronous destruction. The system automatically calls the stop interface.
mAliPlayer.release();
// Asynchronous destruction. The system automatically calls the stop interface.
mAliPlayer.releaseAsync();
Note

The synchronous release() method blocks until all player resources are freed. For faster UI response, use releaseAsync() instead. When using asynchronous destruction:

  1. Do not perform any other operations on the player object during destruction.

  2. Calling stop before releaseAsync() is unnecessary because the process internally includes an asynchronous stop flow.

RTS degradation

When RTS stream pulling fails due to a timeout, the player can automatically degrade to an alternative protocol. Degradation applies only to timeout scenarios. Errors such as 404, 403, or streamer disconnection trigger the onError callback instead.

Note

Automatic degradation uses the same domain name for RTS-to-FLV switching. If your RTS and FLV domain names differ, configure custom degradation to specify the target FLV domain.

Automatic degradation (enabled by default)

When RTS stream pulling fails and no custom degradation is configured, the player automatically degrades to the default FLV address derived from the RTS URL.

// 1 means enabled, 0 means disabled. Enabled by default.
AliPlayerGlobalSettings.setOption(AliPlayerGlobalSettings.ALLOW_RTS_DEGRADE, 1);

Custom degradation

Specify a degradation URL (such as an HLS or FLV address) when RTS stream pulling fails.

PlayerConfig config = mAliPlayer.getConfig();
// Optional: Configure other items in config
UrlSource urlSource = new UrlSource();
urlSource.setUri(downgradeUrl);
// Set the degradation URL
mAliPlayer.enableDowngrade(urlSource, config);

Retrieve the TraceID

Each RTS playback session generates a TraceID for troubleshooting. Retrieve it through the player event callback:

// Listen for the player's onInfo callback and parse the DemuxerTraceID message
mAliPlayer.setOnInfoListener(infoBean -> {
    if (infoBean.getCode() == InfoCode.DemuxerTraceID) {
        String traceId = infoBean.getExtraMsg();
    }
});

Logging

Enable or disable console logging for debugging.

// Enable logging
Logger.getInstance(context).enableConsoleLog(true);
Logger.getInstance(context).setLogLevel(Logger.LogLevel.AF_LOG_LEVEL_TRACE);
// Disable logging
Logger.getInstance(context).enableConsoleLog(false);
Logger.getInstance(context).setLogLevel(Logger.LogLevel.AF_LOG_LEVEL_NONE);