This topic provides answers to some commonly asked questions about ApsaraVideo Player SDK for Android.

How do I obtain the current playback position?

By default, ApsaraVideo Player SDK returns a callback about the current playback position every 500 milliseconds. You can reduce the interval at which callbacks are returned to obtain playback positions more frequently. Sample code:
// Change the callback interval.
PlayerConfig config = mAliyunLivePlayer.getConfig();
config.mPositionTimerIntervalMs = 100; // The callback interval. Unit: milliseconds. 
mAliyunLivePlayer.setConfig(config);

mAliPlayer.setOnInfoListener(new IPlayer.OnInfoListener() {
        @Override
        public void onInfo(InfoBean infoBean) {
        if(infoBean.getCode() == InfoCode.CurrentPosition){
            // The current playback position.
            long currentPosition = infoBean.getExtraValue();
        }
    }
});

What do I do if a crash occurs when I create an ApsaraVideo player?

Perform the following steps to troubleshoot the issue:
  1. Check whether the CPU uses an x86 architecture.

    ApsaraVideo Player SDK supports only the arm64-v8a and armeabi-v7a architectures. The x86 architecture is not supported.

  2. Check whether both the .so files and Maven dependencies are added to the project.

    For example, if you integrate ApsaraVideo Player SDK by adding the Maven dependencies to the build.gradle file, and you add the dynamic frameworks for the SDK to the libs directory at the same time, a crash occurs.

    Solution: If both the Maven dependencies and dynamic frameworks are added to the project, we recommend that you delete the dynamic frameworks. If you must add dynamic frameworks to the project, make sure that the .so files are of the same SDK version. The following figure shows the dynamic frameworks for ApsaraVideo Player SDK.crash
  3. If you use a part package to integrate the SDK, make sure that the correct version of AlivcFFmpeg is added to your project.

    For more information, see AlivcFFmpeg dependencies.

What do I do if a crash occurs when ApsaraVideo Player is running?

Perform the following steps to troubleshoot the issue:
  1. Check whether the crash occurred on ApsaraVideo Player SDK.

    If a crash stack prefixed by AliyunPlayer exists, the crash occurred on ApsaraVideo Player SDK.

  2. Check whether the crash stack contains the CurlConnection2 information.
    If the crash stack contains the CurlConnection2 information, the crash may be caused by the HTTP/2 feature. We recommend that you use the following method to disable the HTTP/2 feature to improve player stability.
    AliPlayerGlobalSettings.setUseHttp2(false);
  3. If the problem persists, How do I contact Alibaba Cloud technical support?. Include the files about all threads and crash logs and describe the crash scenario when you contact technical support.

What do I do if black bars are displayed during video playback?

Perform the following steps to troubleshoot the issue:
  1. Check if black bars appear on your video source.
  2. Call the following operations to change the scaling mode of the player.
    /*
    SCALE_ASPECT_FILL: crops the video to fit the view based on the aspect ratio of the video. 
    SCALE_ASPECT_FIT: scales in the video based on the aspect ratio of the video. Black bars are displayed in the view. 
    SCALE_TO_FILL: stretches the video to fill in the view. The aspect ratio of the video is not maintained. 
    */
    mAliPlayer.setScaleMode();
  3. If the issue persists after you change the scaling mode, call SurfaceView or TextureView at the application layer to change the view size.

What do I do if the audio is being played but no video image is displayed?

Perform the following steps to troubleshoot the issue:
  1. Play the video in another player and check whether the video contains only audio.
  2. Check whether the view is configured correctly. For example, this problem may occur if the view is not configured or placed outside the playback window. For more information about how to configure the view, see step 4 in Create a player.

What do I do if an error that indicates the .so files of ApsaraVideo Player SDK are not found occurs during player initialization or playback?

Perform the following steps to troubleshoot the issue:
  1. Check whether the CPU architecture meets the requirements.

    ApsaraVideo Player SDK supports only the arm64-v8a and armeabi-v7a architectures.

  2. Check whether the version of Apsaravideo Player SDK is outdated.

    If the version of ApsaraVideo Player SDK that you use is 5.4.6.0-full or earlier, we recommend that you upgrade the SDK to 5.4.6.0-full-15467853 or later. For more information about the versions of ApsaraVideo Player SDK, see Release notes for ApsaraVideo Player SDK for Android.

What do I do if an error occurs when I use AliListPlayer to play HLS (M3U8) videos?

If you use ApsaraVideo Player SDK V5.4.5.0 or earlier, you cannot use AliListPlayer to play HLS (M3U8) videos. If you use ApsaraVideo Player SDK V5.4.5.0 or later, you must enable local caching to play HLS (M3U8) videos. Use the following method to enable local caching:
AliPlayerGlobalSettings.enableLocalCache()

FAQ about the seeking feature

What do I do if the progress handle skips from the seeking position?

Cause: The inaccurate seeking mode is used in the player. In this case, video playback starts from the keyframe nearest to the position that you seek to.

Solution: Switch to the accurate seeking mode.

How do I switch between accurate and inaccurate seeking modes?

The following sample code provides an example on how to switch the seeking mode:
// Switch to the inaccurate seeking mode. 
mAliPlayer.seekTo(1000);
mAliPlayer.seekTo(1000, IPlayer.SeekMode.Inaccurate);
// Switch to the accurate seeking mode. 
mAliPlayer.seekTo(1000,IPlayer.SeekMode.Accurate);

What do I do if the progress handle skips from the seeking position when the accurate seeking mode is used?

Cause: Accurate seeking takes more time to complete than inaccurate seeking. When you seek to a playback position where the interval between the specified position and the nearest keyframe is longer than the maximum interval allowed for the accurate seeking mode, ApsaraVideo Player SDK automatically uses the inaccurate seeking mode for the seeking operation.

Solution: Call the setMaxAccurateSeekDelta operation to increase the maximum interval between the seeking position and the nearest keyframe allowed for the accurate seeking mode. This way, the seeking accuracy is improved but the response time is longer. We recommend that you set the maximum interval based on your business requirements. Sample code:
// Unit: milliseconds. 
mAliPlayer.setMaxAccurateSeekDelta(1000);

What do I do if caching fails when I use the play-and-cache feature?

Obtain the cause of the caching failure in the onInfo callback. The following sample code provides an example on how to configure the onInfo callback:
mAliPlayer.setOnInfoListener(new IPlayer.OnInfoListener() {
        @Override
        public void onInfo(InfoBean infoBean) {
        if(infoBean.getCode() == InfoCode.CacheSuccess){
            // Caching during playback succeeded.
        }else if(infoBean.getCode() == InfoCode.CacheError){
            // Caching during playback failed.
            String error = infoBean.getExtraMsg();
        }
    }
});
The following items list the common causes for caching failures:
  • The size and duration specified in CacheConfig do not match those of the video.
  • The position where you stop or seek to during playback is outside the buffer.
Note Preloading and local caching features are added to ApsaraVideo Player SDK V5.4.4.0. These features provide the same capabilities as the play-and-cache feature. We recommend that you use the preloading and local caching features. For more information, see Advanced features.

How do I obtain media source data?

The media source data can be returned only when you use software decoding and play unencrypted videos. Sample code:
// Switch to software decoding. 
mAliPlayer.enableHardwareDecoder(false);
IPlayer.RenderFrameCallbackConfig renderFrameCallbackConfig = new IPlayer.RenderFrameCallbackConfig();
// Specifies whether to return only the address of the underlying video data. Default value: true. 
renderFrameCallbackConfig.mVideoDataAddr = false;
// Specifies whether to return only the address of the underlying audio data. Default value: false. 
renderFrameCallbackConfig.mAudioDataAddr = false;
mAliPlayer.setRenderFrameCallbackConfig(renderFrameCallbackConfig);

mAliPlayer.setOnRenderFrameCallback(new IPlayer.OnRenderFrameCallback() {
    @Override
    public boolean onRenderFrame(FrameInfo frameInfo) {
        return false;
    }
});

What are the rules for automatic bitrate switching?

After you call mAliPlayer.selectTrack(TrackInfo.AUTO_SELECT_INDEX) to enable the automatic bitrate switching feature, ApsaraVideo Player SDK monitors the network speed. The bitrate of the video is switched between higher and lower bitrates based on the 10-second average network speed. If the 10-second average network speed does not fulfill the conditions, the video bitrate is not switched.
  • If the 10-second average network speed meets the conditions for a lower bitrate, the video is switched to a lower bitrate after the playback for cached content is complete.
  • If the 10-second average network speed meets the conditions for a higher bitrate, the video is immediately switched to a higher bitrate.

How do I customize the retry logic?

By default, ApsaraVideo Player SDK tries to reconnect the network twice within 15 seconds before an Error callback is fired.

You can customize the retry logic to receive notifications when retry events occur. Then, you can configure the retry logic. Sample code:
PlayerConfig config = mAliPlayer.getConfig();
// 1. The number of retries. This parameter is set to 0 in the example. 
config.mNetworkRetryCount = 0;
mAliPlayer.setConfig(config);

mAliPlayer.setOnInfoListener(new IPlayer.OnInfoListener() {
    @Override
    public void onInfo(InfoBean infoBean) {
        // 2. Listen to the retry event. 
       if(infoBean.getCode() == InfoCode.NetworkRetry){
            // Configure the retry logic. 
        }
    }
});

What do I do if an error message that indicates the protocol is not supported is returned when I play RTS streams?

Perform the following steps to troubleshoot the issue:
  1. Check whether the AliyunPlayer, AlivcArtc, and RTS dependencies are added.

    You must add AliyunPlayer, AlivcArtc, and RTS dependencies before you use ApsaraVideo Player to play RTC streams. For more information, see Native RTS SDK for Android.

  2. Check whether the versions of the RTS SDK and ApsaraVideo Player SDK match.

    You must use a version of ApsaraVideo Player SDK that is supported by the RTS SDK. For more information, see Download SDKs.

  3. Check whether the versions of AliyunPlayer and AlivcArtc are the same. You must use the same version for AliyunPlayer and AlivcArtc.
  4. You must manually load the RTS SDK after you integrate it.
    load RtsSDK:System.loadLibrary("RtsSDK");

How do I use the thumbnail feature?

Before you use the thumbnail feature in ApsaraVideo Player SDK, perform the following operations to generate a thumbnail for the video. Go to the ApsaraVideo VOD console, create a snapshot template, and select Image Sprite as the Snapshot Type. Create a workflow to process the video based on the snapshot template. Then, the sprite snapshot is created for the video. For more information, see Video snapshots. The following sample code provides an example on how to use the thumbnail feature in ApsaraVideo Player SDK:

mAliPlayer.setOnPreparedListener(new IPlayer.OnPreparedListener() {
    @Override
    public void onPrepared() {
        // 1. Obtain the URL of the thumbnail. 
        List<Thumbnail> thumbnailList = mAliPlayer.getMediaInfo().getThumbnailList();
        // 2. Create the ThumbnailHelper class. 
        ThumbnailHelper mThumbnailHelper = new ThumbnailHelper(thumbnailList.get(0).mURL);
        // 3. Configure the listener. 
        mThumbnailHelper.setOnPrepareListener(new ThumbnailHelper.OnPrepareListener() {
            @Override
            public void onPrepareSuccess() {
                // 5. After the thumbnail is loaded, you can request to obtain the thumbnail at a specified playback position. 
                mThumbnailHelper.requestBitmapAtPosition(1000);

            }
            @Override
            public void onPrepareFail() {}
        });

        mThumbnailHelper.setOnThumbnailGetListener(new ThumbnailHelper.OnThumbnailGetListener() {
            @Override
            public void onThumbnailGetSuccess(long positionMs, ThumbnailBitmapInfo thumbnailBitmapInfo) {
                // 6. Obtain the thumbnail bitmap at a specified playback position. 
                Bitmap thumbnailBitmap = thumbnailBitmapInfo.getThumbnailBitmap();
            }
            @Override
            public void onThumbnailGetFail(long positionMs, String errorMsg) {}
        });

        // 4. Load the thumbnail. 
        mThumbnailHelper.prepare();
    }
});

FAQ about video resolution

Which resolution is used for video playback if a video is transcoded to multiple resolutions?

By default, resolutions are used in the following order: FD, LD, SD, HD, 2K, 4K, OD. For more information about video resolutions, see Parameters for media assets. ApsaraVideo Player SDK uses the first resolution that is available in the preceding order for video playback.

How do I configure a default resolution for video playback?

The following sample code provides an example on how to configure a default resolution:
// Video playback based on VidSts is used in this example.
VidSts vidSts = new VidSts();
// For information about the code used for setting parameters such as vid, AccessKeyId, AccessKeySecret, and token, see the documentation about creating an ApsaraVideo player. 
/*
    Parameter 1: The resolution in which you want to play videos. Valid values: FD, LD, SD, HD, 2K, 4K, and OD. 
    Parameter 2: Specifies whether to forcibly use the specified resolution to play videos. false: ApsaraVideo Player SDK uses the first resolution that is available in the preceding order for video playback. true: Videos are forcibly played in the specified resolution. If a video in the specified resolution is not available, the video is not played. 
*/
vidSts.setQuality("",false);

Which stream is played when multiple streams in the same resolution are available?

ApsaraVideo Player SDK plays the latest transcoded stream when multiple streams in the same resolution are available.

How do I configure watermarks to be displayed on the downloaded videos but hidden during video playback?

Create transcoding jobs to transcode the video to multiple resolutions. Configure watermarking for the video in a resolution and use this resolution for video playback. Use other resolutions for video download.

How do I contact Alibaba Cloud technical support?

If the problem persists, Submit a ticket to contact Alibaba Cloud technical support. Include the error log when you submit a ticket to facilitate troubleshooting. Perform the following steps to obtain the error log:
  1. Enable the log feature.
    Logger.getInstance(context).enableConsoleLog(true);
    Logger.getInstance(context).setLogLevel(Logger.LogLevel.AF_LOG_LEVEL_TRACE);
  2. Obtain the error log.
    1. An error occurs.
    2. Run the adb command to generate the error log.
      adb logcat -d > logcat.log
    3. Provide the logcat.log file to Alibaba Cloud technical support for troubleshooting.