All Products
Search
Document Center

ApsaraVideo VOD:FAQ about ApsaraVideo Player SDK for Android

Last Updated:Apr 01, 2024

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. For more information about how to integrate ApsaraVideo Player SDK and obtain dynamic libraries, see Quick integration. 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 name prefixed with AliyunPlayer exists, the crash occurred on ApsaraVideo Player SDK.

  2. Update ApsaraVideo Player SDK to the latest version and check whether the issue is fixed.

  3. If the problem persists, contact Alibaba Cloud technical support. Include the files about all threads and crash logs and describe the crash scenario when you contact technical support. For more information, see How do I obtain the error log?

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 the error message "Permission denied" is returned when I play a local video that I have read permissions on?

Android has introduced the scoped storage feature since Android 10 (Android Q). Therefore, you must add the android:requestLegacyExternalStorage="true" attribute to the application element in the AndroidManifest.xml file before you can use the storage permissions on your Android device.

What do I do if a black notification bar appears on the top of a notched display when a video is played in full-screen mode?

You can enable the immersive status bar to solve the problem.

What do I do if MOV videos fail to be played?

ApsaraVideo Player SDK for Android supports the playback of MOV videos. If an MOV video fails to be played, check whether the mdat atom of the source video is placed ahead of the moov atom. The mdat atom contains the media data and the moov atom acts as the index of media data. If the mdat atom of the source video is placed ahead of the moov atom, transcode the source video to place the moov atom ahead of the moov atom. For more information, see Step 2: Check the media stream.

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 update 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. For more information, see Configure local caching.

Can I use ApsaraVideo VOD Player SDK for Android to play videos in the assets or raw folder of an Android project?

No. You must save the video to your mobile device and play the video in the absolute path.

I enabled local caching and attempted to play HLS streams. The playback fails and HTTP status code 403 is returned. How do I fix this?

Problem description: Playback of HTTP Live Streaming (HLS) video streams based on the VidAuth method fails and HTTP status code 403 is returned after local caching is enabled.

Cause: If you enable local caching for a video and stop the playback before the video is completely cached, the authentication information that is used in the previous playback is still used when you resume the playback. In this case, the authentication fails and HTTP status code 403 is returned.

Solution: We recommend that you disable local caching.

Does ApsaraVideo Player SDK for Android support the play-and-cache feature?

No. You can enable local caching in ApsaraVideo Player SDK for Android to download video files to the local machine during playback. Then you can use ApsaraVideo Player SDK for Android to play the downloaded video files. You cannot use ApsaraVideo Player SDK to play local files.

Can I use ApsaraVideo Player SDK for Android to obtain the buffering progress of a video?

Yes. ApsaraVideo Player SDK for Android allows you to obtain the buffering speed, real-time rendering frame rate, audio and video bitrates, and downlink bitrate. For more information, see Obtain the playback information.

Why do exceptions occur when I play HDR videos?

ApsaraVideo VOD Player SDK for Android does not support High Dynamic Range (HDR) videos for which rotation parameters are configured. Therefore, exceptions may occur if you play HDR videos for which rotation parameters are configured.

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 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 too long, ApsaraVideo Player SDK automatically uses the inaccurate seeking mode for the seek 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);

FAQ about caching

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 of 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.

Can I specify an internal cache directory when I use the local caching feature?

Yes. You can replace the external storage directory of your Android device with an internal storage directory. Make sure that you have permissions to access the internal storage directory.

What do I do if the error message "encrypt check fail" is returned during video caching?

If you have enabled secure download, check whether the security file for encryption verification matches the application. You must download the security file and store it in the directory in which ApsaraVideo SDK is stored. Otherwise, caching or download may fail. For more information, see Configure download settings and Configure video download.

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;
    }
});

How do I obtain the video width and height?

You can use one of the following methods to obtain the height and width of a video:

  • Call the prepare method in the AliPlayer instance. After the AVPEventPrepareDone event is complete, obtain the height and width of AliPlayer. Sample code:

    mAliyunPlayer.setOnPreparedListener(new IPlayer.OnPreparedListener() {
        @Override
        public void onPrepared() {
              mAliyunPlayer.getVideoWidth();
                  mAliyunPlayer.getVideoHeight();
        }
    });
  • Listen for the callback that is triggered when the video size is changed:

    mAliyunPlayer.setOnVideoSizeChangedListener(new IPlayer.OnVideoSizeChangedListener() {
        @Override
        public void onVideoSizeChanged(int width, int height) {
    
        }
    });
  • Configure callbacks to obtain the track information:

    mAliyunPlayer.setOnTrackReadyListener(new IPlayer.OnTrackReadyListener() {
        @Override
        public void onTrackReady(MediaInfo mediaInfo) {
        List<TrackInfo> trackInfos = mediaInfo.getTrackInfos();
            for (TrackInfo trackInfo : trackInfos) {
            if(trackInfo.getType() == TrackInfo.Type.TYPE_VIDEO){
            trackInfo.getVideoWidth();
            trackInfo.getVideoHeight();
            }
        }
        }
    });

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.

To use the automatic bitrate switching feature, you must transcode a video to an adaptive stream by using the ApsaraVideo VOD console and specify a player to play the adaptive stream. The following sample code provides a VidAuth-based example:

VidAuth vidAuth = new VidAuth();
List<Definition> list = new ArrayList<>();
list.add(Definition.DEFINITION_AUTO);
vidAuth.setDefinition(list);

How do I customize the retry logic?

When network connection times out after 15 seconds, ApsaraVideo Player SDK tries to reconnect the network. By default, two retries are performed 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");
  5. Optional. If the error persists, set android:extractNativeLibs="true" in the AndroidManifest.xml file or android{} in the app/build.gradle file. Sample code:

    packagingOptions {
        jniLibs {
        useLegacyPackaging true
        }
    }

How do I use the thumbnail feature?

Before you use the thumbnail feature in ApsaraVideo Player SDK for Android, 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 obtain the error log?

When you contact Alibaba Cloud technical support, provide the error log to facilitate troubleshooting. Perform the following steps to obtain the error log:

  1. Obtain the error log.

    We recommend that you set the log level to AF_LOG_LEVEL_TRACE before you obtain the error log. For more information, see Obtain SDK logs.

  2. Provide the generated logs to Alibaba Cloud technical support for troubleshooting.