Polyv Help Center

Help Center

2 Quick Integration

Updated: 2024-02-22 09:30:25

This document is technical documentation, requiring readers to have basic iOS development skills and to configure Apple's development environment with Apple's official IDE: Xcode 10.0 or above.

2.1 Compatible Devices

Starting from VOD SDK version 2.20.1, iOS devices running iOS 11.0 and above are supported. VOD SDK versions below 2.20.1 support iOS devices running iOS 8.0 and above.

2.2 Integrating the SDK

Use CocoaPods to integrate the VOD SDK and Upload SDK into your Xcode project. First, create a new Podfile in your project and specify the following in the Podfile:

source 'https://github.com/CocoaPods/Specs.git' 
platform :ios, '11.0'  

target 'TargetName' do 
pod 'PolyvVodSDK' 
end

Then, execute the following command:

$ pod install

2.3 Open Source Components

The VOD project provides a series of open source components, offering developers more optional features such as video danmaku, player skins, Q&A functionality, etc.

The open source components are located in the PolyvOpenSourceModule folder within the demo project. To use the features provided by the open source components, you need to add the entire folder to your project. Then, add the following content to the Podfile mentioned above:

pod 'PLVVodDanmu' 
pod 'PLVSubtitle'
pod 'PLVMasonry'

The open source components use UIStackView, but iOS 8 does not support UIStackView. If you need to support iOS 8, add the following third-party library to the Podfile:

pod 'FDStackView'

2.4 VOD Initialization

Visit the Polyv Video Cloud Platform to obtain account information.

Use PLVVodSettings for initialization. For quick integration, you can use the following method for initialization (not recommended for production environments):

/**  使用加密串配置账号  
 @param configString 加密串  
 @param error 解密、配置过程的错误  
 @return 新的 PLVVodSettings 静态对象  
 */ 
 + (instancetype)settingsWithConfigString:(NSString *)configString error:(NSError **)error;

A more secure initialization method is described in detail in 3. Initialization section [3.2 SDK Configuration].

2.5 Video Playback

PLVVodSkinPlayerController is a player with a default skin provided by the open source components, inheriting from PLVVodPlayerViewController in the VOD SDK. First, create a PLVVodSkinPlayerController object on the page, along with a UIView object to hold the player. Code example:

#import “PLVVodSkinPlayerController.h”  

@interface UIViewController () 

@property (nonatomic, strong) PLVVodSkinPlayerController *player; 
@property (nonatomic, weak) UIView *playerPlaceholder; 

@end  

@implementation UIViewController  

- (void)viewDidLoad {
    [super viewDidLoad];      

    PLVVodSkinPlayerController *player = [[PLVVodSkinPlayerController alloc] init]; 
    [player addPlayerOnPlaceholderView:self.playerPlaceholder 
    rootViewController:self]; 
    self.player = player; 
}  

@end

The player player can automatically implement auto-layout and half-screen/full-screen switching within playerPlaceholder.

The VOD SDK encapsulates video data in the class PLVVodVideo, and passes video data to the player through the PLVVodVideo object. PLVVodVideo contains data such as video ID, video title, video duration, etc. Code example:

self.player.video = video; // video 为 PLVVodVideo 对象 
[self.player play]; // 开始播放 
[self.player pause]; // 暂停播放

2.6 Video Download

The VOD SDK manages downloads through PLVVodDownloadManager. The download video method declaration is as follows:

/**  使用后台设置的默认画质添加至下载队列  
@param video PLVVodVideo 视频对象  
@return 下载信息  
*/ 
- (PLVVodDownloadInfo *)downloadVideo:(PLVVodVideo *)video;

The class PLVVodDownloadInfo encapsulates video download information, including download status, download speed, download progress, etc. After adding a video to the download queue, you can start the download using the method -startDownload and stop the download using the method -stopDownload. Code example:

[[PLVVodDownloadManager sharedManager] downloadVideo:video]; // 将视频 video 添加到下载队列 
[[PLVVodDownloadManager sharedManager] startDownload]; // 开始下载
[[PLVVodDownloadManager sharedManager] stopDownload]; // 停止下载

PLVVodDownloadManager uses blocks to monitor video downloads. Code example:

PLVVodDownloadManager *downloadManager = [PLVVodDownloadManager sharedManager];
 
downloadManager.downloadCompleteBlock = ^(PLVVodDownloadInfo *info) {
    NSLog(@"video vid %@ download success", info.vid);
};
downloadManager.stateDidChangeBlock = ^(PLVVodDownloadInfo *info) {
    NSLog(@"video vid %@ state change to %zd", info.vid, info.state);
};
downloadManager.downloadErrorHandler = ^(PLVVodVideo *video, NSError *error) {
    NSLog(@"video vid %@ download error: %@", video.vid, error);
};
downloadManager.completeBlock = ^{
    NSLog(@"all video download success");
};
联系客服,在线咨询