This topic provides answers to some commonly asked questions about ApsaraVideo Player SDK for iOS. We recommend that you use the latest version of ApsaraVideo Player SDK for iOS. For information about how to download the latest version of the SDK, see SDK overview and download.
I use Xcode14 to package and submit an app to the App Store, but an error is returned during the review. How do I fix this?
Bitcode error
Problem description: After an app is packaged and submitted to the App Store by using Xcode 14, a bitcode-related error is returned during the review. Example:
ITMS-90482: Invalid Executable - The executable 'xxx.app/Frameworks/alivcffmpeg.framework/alivcffmpeg' contains bitcode.
Solution: Use xcrun bitcode_strip to remove bitcode from your framework. In the following sample code, ${framework_path} indicates the binary file path of the framework.
xcrun bitcode_strip ${framework_path} -r -o ${framework_path}
cURL error
Problem description: After an app is packaged and submitted to the App Store by using Xcode 14, a cURL error is returned during the review. Example:
ITMS-90338: Non-public API usage - The app references non-public symbols in Frameworks/AliyunPlayer.framework/AliyunPlayer: _curl_multi_poll, _curl_multi_wakeup. If method names in your source code match the private Apple APIs listed above, altering your method names will help prevent this app from being flagged in future submissions. In addition, note that one or more of the above APIs may be located in a static library that was included with your app. If so, they must be removed. For further information, visit the Technical Support Information at http://developer.apple.com/support/technical/
Solution:
If you integrate only ApsaraVideo Player SDK for iOS into your project, we recommend that you update the SDK to V5.4.9.2 or later.
If you integrate ApsaraVideo Player SDK for iOS and the short video SDK into your project, we recommend that you update ApsaraVideo Player SDK to V5.4.9.2 or later, AlivcFFmpeg (QuCore-ThirdParty) to V4.3.6, and the short video SDK to V3.26 or later.
Non-public selector error
Problem description: After an app is packaged and submitted to the App Store by using Xcode 14, an error related to non-public selectors is returned during the review. The following figure shows a sample error.
Solution: This error is a validation bug in Xcode 14. In most cases, a project can be published after the project is built regardless of whether this error is returned. If your project cannot be published, we recommend that you use Xcode 13 to publish your project.
Plug-in error
Problem description: After an app is packaged and submitted to the App Store by using Xcode 14, the following errors about mpf_filter.framework for frame insertion and vfi_filter.framework for post-processing after image sharpening are returned.
Solution:
If you do not need to use the plug-ins that are listed in the error message, we recommend that you delete the plug-ins from your project. This reduces the size of the package, and does not compromise the performance of the player.
If your project relies on these plug-ins, remove the
"_"
from the value of the"Bundle identifier"
key-value pair in the Info.plist file. This file can be found in the directory where the framework is stored. Then, re-compile and build your project.Update ApsaraVideo Player SDK to V5.5.2.0 or later. In ApsaraVideo Player SDK V5.5.2.0 or later, the issue related to plug-in names has been fixed.
What do I do if the "Xcode Error PhaseScriptExecution failed with a nonzero exit code" error message appears when I run the demo for ApsaraVideo Player SDK for iOS?
Perform the following steps to troubleshoot the error:
1. Go to the project directory.
2. Execute pod deintegrate
.
3. Execute pod install
.
Can I debug apps on the Xcode simulator after I integrate ApsaraVideo Player SDK on iOS devices?
ApsaraVideo Player SDK for iOS
We recommend that you use a real iPhone for debugging. Only ApsaraVideo Player SDK for iOS V5.4.7.1 and later can be debugged on the iOS simulator. However, you cannot debug apps on the iOS simulator for Mac machines equipped with the M1 chip.
ApsaraVideo Player SDK for Flutter
We recommend that you use a real iPhone for debugging. If an error similar to the one shown in the following figure occurs when you use Xcode 14 to compile apps on the iOS simulator, comment out
setFilterConfig:
,updateFilterConfig:
, andsetFilterInvalid:
, and the code that is used to call these operations in ApsaraVideo Player SDK for Flutter.
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: 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: For ApsaraVideo Player SDK V5.5.4.0 or later, if you want to play an HLS stream whose playback URL contains authentication parameters, configure AVPConfig.enableStrictAuthMode
to specify the authentication mode. By default, AVPConfig.enableStrictAuthMode is set to false. Valid values:
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.
What do I do if ApsaraVideo Player for iOS does not work as expected due to audio preemption?
Problem description: You have integrated ApsaraVideo Player SDK for iOS and other audio players into your project. When you use ApsaraVideo Player SDK to play videos, silence and freezing occur.
Cause: The audio control object AVAudioSession
in iOS is a singleton. If you do not set AVAudioSession of all audio players to the same value, audio preemption may occur. As a result, you cannot use ApsaraVideo Player SDK for iOS to play videos.
Solution: Set AVAudioSession
of all audio players to the same value in your project. For example, set the audio session of your application to the playback mode and allow audio mixing with other applications. You can also set the audio session of your application to PlayAndRecord
if you want to record and play videos at the same time. If errors occur when you perform the operation, the error messages are stored in the err
variable.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&err];
Then, configure a custom delegate for AVAudioSession
in ApsaraVideo Player SDK for iOS. This circumvents the preset AVAudioSession
logic and prevents audio preemption. Sample configurations:
Configure the delegate.
[AliPlayer setAudioSessionDelegate:self];
Configure listeners for the delegate.
return TRUE
indicates that no presetAVAudioSession
logic is configured in the SDK.#pragma mark CicadaAudioSessionDelegate - (BOOL)setActive:(BOOL)active error:(NSError **)outError { return YES; } - (BOOL)setCategory:(NSString *)category withOptions:(AVAudioSessionCategoryOptions)options error:(NSError **)outError { return YES; } - (BOOL)setCategory:(AVAudioSessionCategory)category mode:(AVAudioSessionMode)mode routeSharingPolicy:(AVAudioSessionRouteSharingPolicy)policy options:(AVAudioSessionCategoryOptions)options error:(NSError **)outError { return YES; }
What do I do if the stack that points to ApsaraVideo Player SDK for iOS crashes?
If the stack that points to ApsaraVideo Player SDK for iOS crashes, you can use one of the following methods to resolve the issue:
Update ApsaraVideo Player SDK for iOS to the latest version. ApsaraVideo Player SDK for iOS keeps updating to improve stability. For more information about how to obtain the latest version of ApsaraVideo Player SDK, see SDK overview and download.
If the problem persists after you update the SDK to the latest version, we recommend that you provide all the crash information to Alibaba Cloud technical support for troubleshooting. For more information about how to contact technical support, see Contact technical support.
Does ApsaraVideo Player SDK for iOS support the play-and-cache feature?
No. You can enable local caching in ApsaraVideo Player SDK for iOS to download video files to the local machine during playback. Then you can use ApsaraVideo Player SDK for iOS to play the downloaded video files. You cannot use ApsaraVideo Player SDK to play files that are being downloaded.
Can I use ApsaraVideo Player SDK for iOS to obtain the buffering progress of a video?
Yes. ApsaraVideo Player SDK for iOS allows you to obtain the buffering speed, real-time rendering frame rate, audio and video bitrates, and downlink bitrate. For more information, see Obtain playback information.
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:
AVPConfig *config = [self.player getConfig];
config.positionTimerIntervalMs = 100; // Change the callback interval. Unit: milliseconds.
[self.player setConfig:config];
/**
@brief: The callback for the current playback position.
@param player: The pointer for the player.
@param position: The current playback position.
*/
- (void)onCurrentPositionUpdate:(AliPlayer*)player position:(int64_t)position {
// The current playback position.
long currentPosition = position;
}
How do I obtain the height and width of a video?
You can use one of the following methods to obtain the height and width of a video:
Method 1: Call the prepare method in the AliPlayer instance. After the AVPEventPrepareDone event is complete, obtain the height and width of the AliPlayer instance.
-(void)onPlayerEvent:(AliPlayer*)player eventType:(AVPEventType)eventType { if (eventType == AVPEventPrepareDone) { NSLog(@"Width:%d,Height:%d", player.width, player.height); } }
Method 2: Listen to the event that is triggered when the video size is changed.
- (void)onVideoSizeChanged:(AliPlayer*)player width:(int)width height:(int)height rotation:(int)rotation { NSLog(@"Width:%d,Height:%d", width, height); }
Method 3: Configure callbacks to obtain the track information. You can obtain the width and height of the video from AVPTrackInfo in the returned array.
NoteThis method depends heavily on network quality because requests are sent over the Internet to obtain data. We recommend that you use Method 1 or Method 2 to obtain the width and height of a video.
- (void)onTrackReady:(AliPlayer*)player info:(NSArray<AVPTrackInfo*>*)info { for (int i=0; i<info.count; i++) { AVPTrackInfo *trackInfo = info[i]; NSLog(@"Width:%d,Height:%d", trackInfo.videoWidth, trackInfo.videoHeight); } }
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.
If a crash stack name prefixed with
AliyunPlayer
exists, the crash occurs on ApsaraVideo Player SDK.Update ApsaraVideo Player SDK to the latest version and check whether the issue is fixed.
If the issue persists, contact Alibaba Cloud technical support. Prepare 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 an application is initialized or crashes during video preloading when I use ApsaraVideo Player V5.4.6.0?
We recommend that you update your ApsaraVideo Player SDK to V5.4.7.1 or later. You can also use the patched version pod 5.4.6.0-25587639
to improve the stability of ApsaraVideo Player V5.4.6.0.
FAQ about video playback
How do I implement full-screen playback?
ApsaraVideo Player SDK for iOS does not provide APIs to implement full-screen playback. Full-screen playback must be implemented through the iOS system. Demo for ApsaraVideo Player SDK for iOS V5.5.0.0 or later provides a method to allow you to enable full-screen playback in iOS 16.0 or later.
Sample code:
After you call the method that enables full-screen playback in the iOS system, you must modify the view size of the Aliplayer instance based on the screen size.
UIInterfaceOrientation orientation = UIInterfaceOrientationLandscapeLeft; // Rotate the view to enable full-screen playback.
......
// The following sample code applies to iOS 16.0 or later.
if (@available(iOS 16.0, *)) {
@try {
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *ws = (UIWindowScene *)array[0];
Class GeometryPreferences = NSClassFromString(@"UIWindowSceneGeometryPreferencesIOS");
id geometryPreferences = [[GeometryPreferences alloc]init];
UIInterfaceOrientationMask orientationMask = UIInterfaceOrientationMaskLandscapeRight;
if (orientation == UIInterfaceOrientationPortrait) {
orientationMask = UIInterfaceOrientationMaskPortrait;
}
[geometryPreferences setValue:@(orientationMask) forKey:@"interfaceOrientations"];
SEL sel_method = NSSelectorFromString(@"requestGeometryUpdateWithPreferences:errorHandler:");
void (^ErrorBlock)(NSError *err) = ^(NSError *err){
NSLog(@"Rotation error:%@", [err debugDescription]);
};
if ([ws respondsToSelector:sel_method]) {
(((void (*)(id, SEL,id,id))[ws methodForSelector:sel_method])(ws, sel_method,geometryPreferences,ErrorBlock));
}
} @catch (NSException *exception) {
NSLog(@"Rotation error:%@", exception.reason);
} @finally {
}
} else { // The following sample code applies to iOS versions earlier than 16.0.
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
[invocation setArgument:&Orientation atIndex:2];
invocation invoke];
}
[[UIApplication sharedApplication]setStatusBarOrientation:orientation animated:YES];
}
What do I do if black bars are displayed during video playback?
Perform the following steps to troubleshoot the issue:
Check if black bars appear on your video source.
Call the following operations to change the scaling mode of the player:
/* AVP_SCALINGMODE_SCALEASPECTFILL: crops the video to fit the view based on the aspect ratio of the video. AVP_SCALINGMODE_SCALEASPECTFIT: scales in the video based on the aspect ratio of the video. Black bars are displayed in the view. AVP_SCALINGMODE_SCALETOFILL: stretches the video to fill in the view. Image distortion may occur. */ self.player.scalingMode = AVP_SCALINGMODE_SCALETOFILL;
If the issue persists after you change the scaling mode, call
self.player.playerView
and specify theframe
parameter to customize the width and height of the view.
What do I do if only the audio is being played but no video image is displayed and log[AFVTBDecoder] :IOS8VT: throw frame
is reported in the log?
Perform the following steps to troubleshoot the issue:
Play the video in another player and check whether the video contains only audio.
If the video can be played in another player and the aspect ratio of the video is different from that of the video source, use software decoding:
player.enableHardwareDecoder = NO
What do I do if only the audio is being played but no video image is displayed after I click on the notification to open the player?
Solution: Remove UIApplicationStateActive == [[UIApplication sharedApplication] applicationState]
.
- (AliPlayer *)aliPlayer{
if (!_aliPlayer && UIApplicationStateActive == [[UIApplication sharedApplication] applicationState]) {
_aliPlayer = [[AliPlayer alloc] init];
_aliPlayer.scalingMode = AVP_SCALINGMODE_SCALEASPECTFIT;
_aliPlayer.rate = 1;
_aliPlayer.delegate = self;
_aliPlayer.playerView = self.playerView;
}
return _aliPlayer;
}
What do I do if the -5,IO error (Input/Output (I/O))
error message is returned when I play live streams?
We recommend that you use the default values for startBufferDuration
, highBufferDuration
, and maxBufferDuration
in AVPConfig. Check whether you have configured custom buffer and latency settings. For more information, see Control the buffer and latency.
What do I do if the Deactivating an audio session that has running I/O.
or All I/O should be stopped or paused prior to deactivating the audio session.
error message is reported in the log when I resume playback of a paused video?
Problem description: After I pause a video and switch to another playback view where audio is played, the video playback fails when I switch back. In addition, the Deactivating an audio session that has running I/O.
or All I/O should be stopped or paused prior to deactivating the audio session.
error message is reported in the log.
Solution: Check whether a conflict exists in the configurations of AudioSession. For example, the sound track is still occupied when you exit the page where audio is played. This may be because the audio is not disabled in time.
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.
What do I do if I cannot play videos in background?
Problem description: ApsaraVideo Player SDK for iOS cannot play videos in the background after you press the Home button, even if you use the demo.
Solution:
Enable the background data collection feature in Xcode. The following figure shows an example.
If you have specified methods for listening to foreground and background events, comment out the pause and start methods.
// Add a method to listen to the event that the app enters the background. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnterBackground) name: UIApplicationWillResignActiveNotification object:nil]; // Call this method when the app is switched to the foreground from the background. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name: UIApplicationDidBecomeActiveNotification object:nil]; // Comment out the pause method. - (void)applicationEnterBackground { // [self.player pause]; } // Comment out the start method. - (void)applicationDidBecomeActive { // [self.player start]; }
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 the 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.
[self.player seekToTime:1000 seekMode:AVP_SEEKMODE_INACCURATE];
// Switch to the accurate seeking mode.
[self.player seekToTime:1000 seekMode:AVP_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 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.
[self.player setMaxAccurateSeekDelta:100];
What do I do if caching fails when I use the play-and-cache feature?
Obtain the cause of the caching failure in the onPlayerEvent callback. The following sample code provides an example on how to configure the onPlayerEvent callback:
/**
@brief: The callback for player events.
@param player: The pointer for the player.
@param eventWithString: The type of the player event.
@param description: The description of the player event.
@see AVPEventType
*/
-(void)onPlayerEvent:(AliPlayer*)player eventWithString:(AVPEventWithString)eventWithString description:(NSString *)description {
if (eventWithString == EVENT_PLAYER_CACHE_SUCCESS) { // Caching during playback succeeded.
} else if (eventWithString == EVENT_PLAYER_CACHE_ERROR) { // Caching during playback failed.
NSString *errorMsg = description;
}
}
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 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 preloading and local caching features. For more information, see Advanced features.
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 app. 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 following sample code provides an example on how to obtain media source data:
// Configure the rendering callback.
self.player.renderingDelegate = self;
// Listen to the rendering callback.
- (BOOL)onRenderingFrame:(CicadaFrameInfo*) frameInfo {
if (frameInfo.frameType == Cicada_FrameType_Video) { // The underlying video data.
} else if (frameInfo.frameType == Cicada_FrameType_Audio) { // The underlying audio data.
}
return NO;
}
What are the rules for automatic bitrate switching?
After you call [self.player selectTrack:SELECT_AVPTRACK_TYPE_VIDEO_AUTO]
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?
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 and receive notifications when retry events occur. Sample code:
AVPConfig *config = [self.player getConfig];
config.networkRetryCount = 0; // The number of retries. In this example, this parameter is set to 0.
[self.player setConfig:config];
/**
@brief: The callback for player events.
@param player: The pointer for the player.
@param eventWithString: The type of the player event.
@param description: The description of the player event.
@see AVPEventType
*/
-(void)onPlayerEvent:(AliPlayer*)player eventWithString:(AVPEventWithString)eventWithString description:(NSString *)description {
if (eventWithString == EVENT_PLAYER_NETWORK_RETRY) { // The network connection fails. Try again.
// Configure the retry logic.
}
}
What do I do if an error message indicating that the protocol is not supported is returned when I play RTS streams?
Perform the following steps to troubleshoot the issue:
Check whether the AliPlayerSDK_iOS, AliPlayerSDK_iOS_ARTC, and RtsSDK dependencies are added.
You must add AliPlayerSDK_iOS, AliPlayerSDK_iOS_ARTC, and RtsSDK dependencies before you can use ApsaraVideo Player to play Real-Time Streaming (RTS) streams. For more information, see Native RTS SDK for iOS.
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.
Check whether the versions of AliPlayerSDK_iOS and AliPlayerSDK_iOS_ARTC are the same. You must use the same version for AliPlayerSDK_iOS and AliPlayerSDK_iOS_ARTC.
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 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:
/**
Specifies whether a thumbnail is configured for the track. No thumbnail is displayed if you do not configure a thumbnail.
*/
@property (nonatomic,assign)BOOL trackHasThumbnai;
/**
Create a custom view that displays thumbnails.
*/
@property (nonatomic,strong)UIImageView *thumbnaiView;
/**
@brief: The callback for obtaining the track information.
@param player: The pointer for the player.
@param info: The array of track information. For more information, see AVPTrackInfo.
*/
- (void)onTrackReady:(AliPlayer*)player info:(NSArray<AVPTrackInfo*>*)info {
AVPMediaInfo* mediaInfo = [player getMediaInfo];
if ((nil != mediaInfo.thumbnails) && (0 < [mediaInfo.thumbnails count])) {
[self.player setThumbnailUrl:[mediaInfo.thumbnails objectAtIndex:0].URL];
self.trackHasThumbnai = YES;
}else {
self.trackHasThumbnai = NO;
}
}
/**
The callback for changing the playback position on the progress bar.
@param playerView playerView
@param value: The playback position.
*/
- (void)AVPPlayerView:(AVPPlayerView *)playerView progressSliderValueChanged:(CGFloat)value {
if (self.trackHasThumbnai) {
[self.player getThumbnail:self.player.duration*value];
}
}
/**
@brief: The callback that is returned when the thumbnail is obtained.
@param positionMs: The specified thumbnail position.
@param fromPos: The playback position from which the thumbnail is used.
@param toPos: The playback position at which the thumbnail is no longer used.
@param image: The pointer for the thumbnail image. NSImage is used for macOS and UIImage is used for iOS.
*/
- (void)onGetThumbnailSuc:(int64_t)positionMs fromPos:(int64_t)fromPos toPos:(int64_t)toPos image:(id)image {
self.thumbnaiView.hidden = NO;
[self.thumbnaiView setImage:(UIImage *)image];
}
/**
@brief: The callback that is returned when the thumbnail fails to be obtained.
@param positionMs: The specified thumbnail position.
*/
- (void)onGetThumbnailFailed:(int64_t)positionMs {
self.thumbnaiView.hidden = YES;
}
Note: If you use URL-based playback, the system does not automatically display the thumbnail because MediaInfo callback is not supported in onTrackReady. We recommend that you specify a thumbnail URL.
/**
Specifies whether a thumbnail is configured for the track. No thumbnail is displayed if you do not configure a thumbnail.
*/
@property (nonatomic,assign)BOOL trackHasThumbnai;
/**
Create a custom view that displays thumbnails.
*/
@property (nonatomic,strong)UIImageView *thumbnaiView;
/**
onPrepare
*/
- (void)onPlayerStatusChanged:(AliPlayer*)player oldStatus:(AVPStatus)oldStatus newStatus:(AVPStatus)newStatus {
if(newStatus == AVPStatusPrepared){
[self.player setThumbnailUrl:[URL];// Specify a thumbnail URL. You can obtain the thumbnail URL in the ApsaraVideo VOD console or by calling API operations.
self.trackHasThumbnai = YES;
}
}
/**
The callback for changing the playback position on the progress bar.
@param playerView playerView
@param value: The playback position.
*/
- (void)AVPPlayerView:(AVPPlayerView *)playerView progressSliderValueChanged:(CGFloat)value {
if (self.trackHasThumbnai) {
[self.player getThumbnail:self.player.duration*value];
}
}
/**
@brief: The callback that is returned when the thumbnail is obtained.
@param positionMs: The specified thumbnail position.
@param fromPos: The playback position from which the thumbnail is used.
@param toPos: The playback position at which the thumbnail is no longer used.
@param image: The pointer for the thumbnail image. NSImage is used for macOS and UIImage is used for iOS.
*/
- (void)onGetThumbnailSuc:(int64_t)positionMs fromPos:(int64_t)fromPos toPos:(int64_t)toPos image:(id)image {
self.thumbnaiView.hidden = NO;
[self.thumbnaiView setImage:(UIImage *)image];
}
/**
@brief: The callback that is returned when the thumbnail fails to be obtained.
@param positionMs: The specified thumbnail position.
*/
- (void)onGetThumbnailFailed:(int64_t)positionMs {
self.thumbnaiView.hidden = YES;
}
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.
AVPVidStsSource *stsSource = [[AVPVidStsSource alloc] init];
stsSource.vid = @"<vid>";
stsSource.accessKeyId = @"<accessKeyId>";
stsSource.securityToken = @"<securityToken>";
stsSource.accessKeySecret = @"<accessKeySecret>";
stsSource.quality = @""; // The resolution in which you want to play videos. Valid values: FD, LD, SD, HD, 2K, 4K, and OD.
stsSource.forceQuality = NO; // Specifies whether to forcibly use the specified resolution to play videos. NO: ApsaraVideo Player SDK uses the first resolution that is available in the preceding order for video playback. Yes: ApsaraVideo Player SDK forcibly uses the specified resolution to play videos. If a video in the specified resolution is not available, the video is not played.
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 a watermark to be displayed on the downloaded video 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.
What do I do if videos cannot be played in landscape mode?
ApsaraVideo Player SDK for iOS does not provide a method to enable video playback in landscape mode. You must call API operations in the iOS system and specify the frame
parameter in aliplayer.playerView
based on your business requirements to enable the landscape mode.
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:
Use one of the following methods to obtain the error log.
We recommend that you set the log level to
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.
For more information, see Troubleshoot playback errors.