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 playback position every 500 milliseconds. You can reduce the interval at which callbacks are returned to obtain playback positions more frequently. Sample code:
//Modify 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:
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.
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 libraries for the SDK to the libs directory at the same time, a crash occurs.
Solution: If both the Maven dependencies and dynamic libraries are added to the project, we recommend that you delete the dynamic libraries. If you must add dynamic libraries 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 libraries related to ApsaraVideo Player SDK:
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 about the version dependencies of AlivcFFmpeg, see AlivcFFmpeg version dependencies.
What do I do if a crash occurs when ApsaraVideo Player is running?
Perform the following steps to troubleshoot the issue:
Check whether the crash occurs on ApsaraVideo Player SDK.
Check whether the crash stack contains the
AliyunPlayer
prefix. If yes, the issue occurs on ApsaraVideo Player SDK.Update ApsaraVideo Player SDK to the latest version and check whether the issue is fixed.
If the issue persists, prepare the crash files (including all threads), crash logs, and crash scenarios, 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:
Check whether black bars appear on your video source.
Call the following operations to change the scaling mode of the player:
/* SCALE_ASPECT_FILL: scales the image to fill the view while maintaining the aspect ratio. The image may be cropped as a result. 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 image to fill the view. This does not preserve the aspect ratio, and may cause the image to be distorted. */ mAliPlayer.setScaleMode();
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:
Play the video in another player and check whether the video contains only audio.
Check whether the view is configured correctly. For example, this issue 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 "Invalid argument" is returned when I play a local video that I have read permissions on?
Check the name and absolute path of the file to ensure that the path does not contain Chinese characters and spaces.
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 10 (Android Q) and later introduce the partitioned storage feature. You must add android:requestLegacyExternalStorage="true"
to the application tag in AndroidManifest.xml
to use the storage permissions of your Android device.
What do I do if the error message "Redirect to a url" is occasionally returned during video playback?
This error may occur because the video source is hijacked. We recommend that you enable the HTTPDNS feature of the player to resolve this issue. For more information, see Configure HTTPDNS on Android.
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: Troubleshoot the stream.
What do I do if an error indicating that the .so files of ApsaraVideo Player SDK are not found occurs during player initialization or playback?
Perform the following steps to troubleshoot the issue:
Check whether the CPU architecture meets the requirements.
ApsaraVideo Player SDK supports only the arm64-v8a and armeabi-v7a architectures.
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 latest and historical versions of ApsaraVideo Player SDK, see ApsaraVideo Player SDK for Android.
What do I do if an error occurs when I use AliListPlayer to play HLS (M3U8) videos?
ApsaraVideo Player SDK V5.4.5.0 and earlier do not support the playback of HTTP Live Streaming (HLS) (M3U8) videos by using AliListPlayer
. ApsaraVideo Player SDK V5.4.5.0 and later support the playback of HLS (M3U8) videos, but you must enable local caching. For more information about how to enable local caching, see 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 cannot. You must save the video to your mobile device and play the video in the absolute path.
I have enabled local caching and attempt to play HLS streams. The playback fails and HTTP status code 403 is returned. How do I fix this?
Problem description: When local caching is enabled, playback of HTTP Live Streaming (HLS) video streams based on the VidAuth method fails and HTTP status code 403 is returned.
Cause: If you enable local caching for a video and stop the playback before the video is completely cached, the authentication information 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: For ApsaraVideo Player SDK V5.5.4.0 and later, if the video playback URL contains authentication parameters and the playback protocol is HLS, you can set the PlayerConfig.mEnableStrictAuthMode
field to select an authentication mode. The default value is false.
false: caches the authentication information. If a video is not completely cached, the player sends a URL signing request by using the cached authentication information when you play the uncached video content. If the validity period of the signed URL is short, playback errors occur.
true: performs authentication and does not cache video content. URL signing is required for every playback. No network connections lead to playback failures.
Does ApsaraVideo Player SDK for Android support the play-and-cache feature?
No, it does not. 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, you can. ApsaraVideo Player SDK for Android allows you to obtain the buffering progress, real-time rendering frame rate, audio and video bitrate, and network downlink bitrate. For more information, see Obtain 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.
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:
//Inaccurate seeking.
mAliPlayer.seekTo(1000);
mAliPlayer.seekTo(1000, IPlayer.SeekMode.Inaccurate);
//Accurate seeking.
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 set 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.
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 local caching feature. For more information, see Advanced features.
Can I specify an internal cache directory when I use the local caching feature?
Yes, you can. 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?
Caching is a download operation. If secure download is enabled, make sure that the encryption verification file matches the application information. You must download the encryption verification file that is generated in Offline download and save the file to ApsaraVideo Player SDK. For more information, see Video download. Otherwise, caching or download fails.
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();
// Specify whether to return only the address of the underlying video data. Default value: true.
renderFrameCallbackConfig.mVideoDataAddr = false;
// Specify 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 obtain the width and height of a video by using one of the following methods:
After the prepare method is called in the AliPlayer instance, run the following sample code to obtain the width and height of the video:
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) { } });
Call the setOnTrack operation to obtain the width and height of the video:
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(); } } } });
How do I obtain the pixels of each frame in a video by using the player?
Android player: You can listen to the OnRenderFrameCallback
callback to obtain the pixels.
player.setOnRenderFrameCallback(frameInfo -> {
if (frameInfo.frameType == FrameInfo.FrameType_video) {
// The video data
} else {
// The audio data
}
return false;
});
What are the rules for automatic bitrate switching?
When automatic bitrate switching is enabled, for example, when you call the mAliPlayer.selectTrack(TrackInfo.AUTO_SELECT_INDEX)
operation, ApsaraVideo Player SDK calculates the current network speed. If the 10-second average network speed meets the requirements for a different bitrate, the video is switched to that bitrate. 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?
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 and receive notifications when retry events occur. Sample code:
PlayerConfig config = mAliPlayer.getConfig();
// 1. Specify 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:
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 about how to integrate the dependencies, see Integration of ApsaraVideo Player SDK and Native RTS SDK.
Check whether the versions of RTS SDK and ApsaraVideo Player SDK match.
The versions of RTS SDK and ApsaraVideo Player SDK must match. For more information about the version dependencies, see Pull RTS streams on Android.
Check whether the versions of AliyunPlayer and AlivcArtc are the same. You must use the same version for AliyunPlayer and AlivcArtc.
You must manually load the RTS SDK after you integrate it.
load RtsSDK:System.loadLibrary("RtsSDK");
Optional: If the error persists after you perform the preceding steps, configure
android:extractNativeLibs="true"
in the AndroidManifest.xml file or in theandroid{}
closure of 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, make sure that a thumbnail is configured for the video. This means that the video has sprite snapshots. You can create a snapshot template of the sprite type in the ApsaraVideo VOD console. Then, you can use a workflow to process the video based on the sprite snapshot template to generate sprite snapshot data. For more information, see Video snapshot. 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();
}
});
Note: If you use URLs for video playback, the player may fail to obtain the ThumbnailList parameter. We recommend that you specify the URL of the thumbnail.
mAliPlayer.setOnPreparedListener(new IPlayer.OnPreparedListener() {
@Override
public void onPrepared() {
// 1. Create the ThumbnailHelper class.
ThumbnailHelper mThumbnailHelper = new ThumbnailHelper(URL);
// 2. Configure a listener.
mThumbnailHelper.setOnPrepareListener(new ThumbnailHelper.OnPrepareListener() {
@Override
public void onPrepareSuccess() {
// 4. 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) {
// 5. Obtain the thumbnail bitmap at a specified playback position.
Bitmap thumbnailBitmap = thumbnailBitmapInfo.getThumbnailBitmap();
}
@Override
public void onThumbnailGetFail(long positionMs, String errorMsg) {}
});
// 3. Load the thumbnail.
mThumbnailHelper.prepare();
}
});
FAQ about video resolution
Which resolution is used for video playback if a video is transcoded to multiple resolutions?
Default resolution order for video playback: FD, LD, SD, HD, 2K, 4K, and OD. For more information about the definitions of resolutions, see Resolution: Definition. 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?
Sample code:
//Take the VidSts playback method as an example
VidSts vidSts = new VidSts();
// For information about the code used to set 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?
In such a case, ApsaraVideo Player SDK plays the latest transcoded stream.
How do I configure a watermark to be displayed on the downloaded video but hidden during video playback?
Create transcoding jobs with or without watermarking configured to transcode the video into multiple resolutions. Play the video without a watermark and download the video with a watermark.
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:
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.Provide the generated log to Alibaba Cloud technical support for troubleshooting.