Introduction
Application scenarios
Advanced Picture-in-Picture (PIP) is an upgraded version of the basic PIP, mainly used for encrypted video PIP, offline playback PIP, and seamless switching from foreground to PIP scenes. It optimizes the implementation and logic, and achieves a true "instant switch" effect without long waiting times. Advantages of Advanced PIP:
Encrypted video PIP: integrated with the existing player for encrypted playback, realizing PIP playback based on encrypted templates without the need to switch player types.
Offline playback PIP: supports local video PIP playback, including ordinary videos, encrypted videos, etc.
"Instant switch" effect: no need to click the PIP button to switch, just go to the background and PIP will start immediately, achieving a true "instant switch".
Requirements
System version: iOS ≥ 14.0, iPad ≥ 9.0 .
Hardware devices: iPhone 8 and above.
SDK version: 11.4 or above.
Integration Steps
Upgrade SDK version and configure resources
1. Upgrade SDK version:
Advanced Picture-in-Picture requires the use of the SDK. Before using the advanced Picture-in-Picture version, the SDK version needs to be upgraded to version 11.3 or above for the advanced version, or version 11.4 or above for the basic version, otherwise it cannot be used. At the same time, the basic and advanced versions of Picture-in-Picture can coexist with compatibility and no functional conflicts. If you want to upgrade the SDK version, please refer to the SDK integration guide. 2. Introduce bundle resources
Because the SDK needs to use resources from TXVodPlayer.bundle, the bundle file needs to be downloaded and introduced into the project before compilation. Please do not modify the bundle or the names of the resources used inside, as doing so may cause seamless switching of picture-in-picture to fail. 3. Activate the premium version license for the player
After obtaining the License information, before calling the relevant interface of the SDK, initialize the License through the following interface. It is recommended to make the following settings in - [AppDelegate application:didFinishLaunchingWithOptions:]:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString * const licenceURL = @"<your license Url>";
NSString * const licenceKey = @"<your license key>";
[TXLiveBase setLicenceURL:licenceURL key:licenceKey];
NSLog(@"SDK Version = %@", [TXLiveBase getSDKVersionStr]);
}
Quick access to picture-in-picture function
1. Permission granted
Picture-in-picture (PictureInPicture) has been launched in iOS 9, but it was only available on the iPad before. To use picture-in-picture, the iPhone needs to be updated to iOS 14. Currently, Tencent Cloud Player can support in-app and out-of-app picture-in-picture capabilities, which greatly meets the needs of users. You need to enable background mode before use. The steps are: Select the corresponding Target > Signing & Capabilities > Background Modes in XCode and check "Audio, AirPlay, and Picture in Picture".
2. Set configuration options
In order to use the automatic picture-in-picture function, you need to turn on the automatic picture-in-picture button in the settings. The specific path is to select on iPhone or iPad: Settings > General > Picture-in-Picture > Automatically turn on Picture-in-Picture, select to turn it on.
3. Set proxy
In order to facilitate monitoring of the picture-in-picture status, vodDelegate needs to be set to implement the picture-in-picture related callbacks in TXVodPlayListener. You can perform related business operations based on various status and error messages in the callback, such as continuing to play, pausing or exiting picture-in-picture, etc.
- (void)onPlayer:(TXVodPlayer *)player pictureInPictureStateDidChange:(TX_VOD_PLAYER_PIP_STATE)pipState withParam:(NSDictionary *)param;
- (void)onPlayer:(TXVodPlayer *)player pictureInPictureErrorDidOccur:(TX_VOD_PLAYER_PIP_ERROR_TYPE)errorType withParam:(NSDictionary *)param;
4. Code example using picture-in-picture capability
Note:
To use the automatic picture-in-picture function, make sure the player is in the playing state. If the player is paused or stopped, the automatic picture-in-picture function cannot be used.
The isSupportSeamlessPictureInPicture interface can only be used after the application loads the advanced version License. At the same time, this interface can only determine whether the device itself supports automatic switching of picture-in-picture. Due to system limitations, it cannot determine the user's setting permission for automatic picture-in-picture, and needs to be guided by itself.
Before playing, set whether to allow "automatic switching of picture-in-picture function".
[TXVodPlayer setPictureInPictureSeamlessEnabled:YES];
if (![TXVodPlayer isSupportPictureInPicture]) {
return;
}
[_vodPlayer enterPictureInPicture];
if ([self.vodplayer isSupportSeamlessPictureInPicture]) {
} else {
[self.vodplayer pause];
}
[_vodPlayer exitPictureInPicture];
この記事はお役に立ちましたか?