swift调用保利威视SDK(polyv-ios-vod-sdk)
一、xcode11 新建swift5 项目
参考Xcode11新建低版本iOS,swift项目流程及问题
二、接入 SDK
在项目目录下执行
$ pod init
在 Podfile 中指定:
pod 'PolyvVodSDK'
pod 'PLVVodDanmu'
pod 'PLVSubtitle'
pod 'FDStackView'
pod 'Masonry'
pod 'YYWebImage'
在项目目录终端下执行:
$ pod install
三、将播放器空间和皮肤等资源引入到项目
- 复制PolyvOpenSourceModule文件夹到你的项目
- 复制PLVNetworkUtil.h和PLVNetworkUtil.m文件到新项目
四、新建OC文件和桥接文件,点播初始化
点播初始化:
在OC文件中添加方法 polyvInit
PLVDemo.h文件中添加
-(void)polyvInit;
PLVDemo.m文件中添加
/**
初始化保利威视
*/
-(void)polyvInit{
NSError *error = nil;
PLVVodSettings *settings = [PLVVodSettings settingsWithConfigString:@"yQRmgnzPyCUYDx6weXRATIN8gkp7BYGAl3ATjE/jHZunrULx8CoKa1WGMjfHftVChhIQlCA9bFeDDX+ThiuBHLjsNRjotqxhiz97ZjYaCQH/MhUrbEURv58317PwPuGEf3rbLVPOa4c9jliBcO+22A==" key:@"VXtlHmwfS2oYm0CZ" iv:@"2u9gDPKdX6GyQJKU" error:&error];
// 读取并替换设置项。出于安全考虑,不建议从 plist 读取加密串,直接在代码中写入加密串更为安全。
{
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
BOOL enableUserVodKey = [user boolForKey:PLVApplySettingKey];
if (enableUserVodKey) {
NSString *userVodKey = [user stringForKey:PLVVodKeySettingKey];
userVodKey = [userVodKey stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (userVodKey.length) {
settings = [PLVVodSettings settingsWithConfigString:userVodKey error:&error];
}
}
}
NSLog(@"settings: %@", settings);
if (error) {
NSLog(@"account settings error: %@", error);
}
}
在ViewController中添加代码
let plv = PLVDemo()
plv.polyvInit()
五、视频播放
PLVDemo.h文件中添加
- (PLVVodSkinPlayerController *)play;
PLVDemo.m文件中添加
- (PLVVodSkinPlayerController *)play{
// 初始化播放器
PLVVodSkinPlayerController *player = [[PLVVodSkinPlayerController alloc] initWithNibName:nil bundle:nil];
self.player = player;
__weak typeof(self) weakSelf = self;
[PLVVodVideo requestVideoWithVid:@"e97dbe3e64c247499b55f213a4470052_e" completion:^(PLVVodVideo *video, NSError *error) {
if (!video.available) return;
weakSelf.player.video = video;
}];
return player;
}
在ViewController中添加代码
let playController = plv.play()
let playerPlaceholder = UIView()
playerPlaceholder.frame = CGRect(x: 0, y: 100, width: UIScreen.main.bounds.width, height: 200)
self.view.addSubview(playerPlaceholder)
playController .addPlayer(onPlaceholderView: playerPlaceholder, rootViewController: self)
六、GitHub地址:
https://github.com/xugj-gits/swift_polyv_demo.git
七、效果图