VideoOS iOS SDK 开源地址:https://github.com/VideoOS/VideoOS-iOS-SDK
| 功能 | 对接要求 |
|---|---|
| 前期准备 | 必须对接 |
| 基础接口 | 必须对接 |
| 前后帖广告 | 可选对接 |
| 具体对接方法请参考下面详细集成流程。 |
有两种方式将VideoOS添加到你的工程:
- 使用CocoaPods
- 手动添加framework
CocoaPods 是 Objective-C 的依赖管理工具, 利用它可以让在项目中使用第三方库的过程变成简单和自动化。具体请参考 Get Started。
platform :ios, '8.0'
pod 'VideoOS'
如果你使用的是swift开发,请确保添加 use_frameworks!
platform :ios, '8.0'
use_frameworks!
- 将下载的SDK解压后导入您的工程中 (注:请务必在此步骤中选择“Create groups”单选按钮组, 因该SDK体积过大,不要勾选“Copy items if needed”。用这种方式仅引用该SDK,避免引起项目体积过大的问题)
- 设置项目的Framework Search Paths (注:由于我们采用了Reference的方式,所以此处必须在Framework Search Paths里面添加SDK在本机所在的路径,路径从Users开始),如图:
- 添加依赖库(Xcode 7 下
*.dylib库后缀名更改为*.tbd),请确保已添加以下 依赖库:
libz.tbd
libsqlite3.tbd
MediaPlayer.framework
WebKit.framework
ImageIO.framework
Security.framework
CoreMedia.framework
AVFoundation.framework
MobileCoreService.framework
Accelerate.framework
CoreTelephony.framework
SystemConfiguration.framework
AssetsLibrary.framework
Photos.framework
- 设置 Other Linker flags.
在 Other Linker Flags 中添加 –ObjC,如图(注意:如果项目中加载多个静态库有冲突,并使用了-force_load的,不能添加-ObjC,且相 应此库也需要加入force_load,对应路径需要指定到VideoPlsCytronSDK.framework/VideoPlsCytronSDK.h):
- 可能依赖的第三方库(具体视平台不同而不一致)
'AFNetworking'
'SDWebImage', '4.2.2' #如果用最新版本SDWebImage,请确认gif是否可以播放
在 AppDelegate.m 文件中导入 <VideoPlsInterfaceControllerSDK/VPIConfigSDK.h> ,并在 application:didFinishLaunchingWithOptions: 方法中初始化SDK,SaaS版本需要设置AppKey和AppSecret,开源版本不需要。
示例代码:
#import <VideoPlsInterfaceControllerSDK/VPIConfigSDK.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//other code
[VPIConfigSDK setAppKey:@"550ec7d2-6cb0-4f46-b2df-2a1505ec82d8" appSecret:@"d0bf7873f7fa42a6"];//SaaS版本需要设置AppKey和AppSecret,开源版本不需要
[VPIConfigSDK initSDK];
//other code
}-
根据需要接入的
SDK创建VPInterfaceControllerConfig,将SDK需要的信息配置在config中。- identifier 为点播视频url或直播房间号
- episode 为剧集名称,例如 陈情令
- title 为视频标题,例如 陈情令 第02集
- types 为视频类型(点播or直播),默认为点播(注:
VPInterfaceControllerTypeVideoOS表示点播,VPInterfaceControllerTypeLiveOS表示直播) - extendDict 分层投放的参数通过extendDict字段传递
注:identifier,episode,title为必填字段
分层投放的参数通过extendDict字段传递
所有参数采用key:array方式传递,key为分层的层级关键字,array里面为层级对应的具体值
一些常见的参数,推荐使用下面的命名方式
标题(title),例如 邪恶力量 第九季 第五集,[dict setObject:@[@"邪恶力量 第九季 第五集"] forKey:@"title"];
剧集(episode),例如 邪恶力量第九季,[dict setObject:@[@"邪恶力量第九季"] forKey:@"episode"];
剧集Id,例如 628916289,[dict setObject:@[@"628916289"] forKey:@"episodeId"];
地区/区域(area),例如 美剧,[dict setObject:@[@"美剧"] forKey:@"area"];
年份(year),例如 2019,[dict setObject:@[@"2019"] forKey:@"years"];
类型(type),例如 科幻,武侠,[dict setObject:@[@"科幻", @"武侠"] forKey:@"episodeId"];
其他扩展字段也可以通过extendDict字段传递
-
利用生成的
config初始化InterfaceController,interfaceController.view就是生成的互动层,将这个view添加到播放器层之上就可以了。根据接入的SDK的需求可能有一些特殊的接口,放在相应的文件中,如需要调用,将对应文件import就可以调用了,详细作用请看注释。
//配置信息
VPInterfaceControllerConfig *config = [[VPInterfaceControllerConfig alloc] init];
config.identifier = videoUrl; //or roomId
config.episode = @"episode"; //剧集名称
config.title = @"title"; //视频标题
config.types = VPInterfaceControllerTypeVideoOS; //or VPInterfaceControllerTypeLiveOS
//扩展信息
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
[dict setObject:@"lol" forKey:@"category"];
config.extendDict = dict;
//播放器size
CGSize screenSize = [UIScreen mainScreen].bounds.size;
VPIVideoPlayerSize *videoPlayerSize = [[VPIVideoPlayerSize alloc] init];
videoPlayerSize.portraitFullScreenWidth = screenSize.width < screenSize.height ? screenSize.width : screenSize.height;
videoPlayerSize.portraitFullScreenHeight = screenSize.width < screenSize.height ? screenSize.height : screenSize.width;
videoPlayerSize.portraitSmallScreenHeight = videoPlayerSize.portraitFullScreenWidth * 9.0/16.0;
videoPlayerSize.portraitSmallScreenOriginY = 0.0;
VPInterfaceController *interfaceController = [[VPInterfaceController alloc] initWithFrame:self.view.bounds config:config videoPlayerSize:videoPlayerSize];
interfaceController.delegate = self;
interfaceController.userDelegate = self;
interfaceController.videoPlayerDelegate = self;
[self.view addSubview:interfaceController.view];- 接着,设置当前互动层显示区域,代码如下所示
[interfaceController notifyVideoScreenChanged:type];互动层加载完成、视频加载完成,建议调用更新方法,旋转横竖屏之后必须调用更新方法
- 全部完成之后调用
start,开启互动层。 - 通过VPIVideoPlayerDelegate协议获取视频信息
- 获取互动层状态信息需要遵守
VPInterfaceStatusNotifyDelegate协议,详见注释 - 如需深度对接账号系统需要遵守
VPUPUserLoginInterface协议,详见注释 - 如退出播放页面或直播间,调用
stop方法
- VPIUserLoginInterface 和 VPIUserInfo, VPIUserInfo用来组装用户实例, VPIUserLoginInterface 用来获取关于用户数据的回调;
- (VPIUserInfo *)vp_getUserInfo通过平台方得到你们的userInfo- (void)vp_userLogined:(VPIUserInfo *) userInfo通过sdk的webView登陆后会给你们对应的用户信息
VPInterfaceStatusNotifyDelegate - (void)vp_interfaceActionNotify, 会回传互动层状态和需要的操作
- adID 为广告的唯一标识
- adName 为广告名
- eventType 为广告触发的事件,包括展示、点击、关闭等
- actionType 为对接方需要做的操作,包括打开外链,暂停视频,播放视频
- url 为外链地址
注:该接口必须实现
VPInterfaceStatusNotifyDelegate - (void)vp_interfaceScreenChangedNotify, 通知平台切换设备方向
- orientation 1为竖屏,2为横屏
注:该接口必须实现
创建一个VPIServiceConfig,设置前后帖、暂停广告的相关参数,通过- (void)startService:(VPIServiceType )type config:(VPIServiceConfig *)config方法启动相关服务,在serviceDelegate中可以收到执行结果的回调
//设置serviceDelegate
interfaceController.serviceDelegate = self;
...
//前贴广告
VPIServiceConfig *config = [[VPIServiceConfig alloc] init];
config.identifier = _interfaceController.config.identifier;
config.type = VPIServiceTypePreAdvertising;
config.duration = VPIVideoAdTimeType60Seconds;
[_interfaceController startService:VPIServiceTypePreAdvertising config:config];
...
//暂停广告
[_interfaceController pauseService:VPIServiceTypePostAdvertising]
//恢复暂停的广告
[_interfaceController resumeService:VPIServiceTypePostAdvertising]
...
//回调
//广告执行成功以后回调
- (void)vp_didCompleteForService:(VPIServiceType )type {
if (type == VPIServiceTypePostAdvertising || type == VPIServiceTypePreAdvertising) {
if (!_player.isPlaying) {
[_mediaControlView playButtonTapped:nil];
}
}
}
...
//广告执行失败以后回调
- (void)vp_didFailToCompleteForService:(VPIServiceType )type error:(NSError *)error {
if (type == VPIServiceTypePostAdvertising || type == VPIServiceTypePreAdvertising) {
if (!_player.isPlaying) {
[_mediaControlView playButtonTapped:nil];
}
}
}创建一个VPIServiceConfig,设置视联网模式的相关参数,包括视频的identifier,通过- (void)startService:(VPIServiceType )type config:(VPIServiceConfig *)config方法启动视联网模式,在serviceDelegate中可以收到执行结果的回调
//设置serviceDelegate
interfaceController.serviceDelegate = self;
...
//视联网模式
VPIServiceConfig *config = [[VPIServiceConfig alloc] init];
config.type = VPIServiceTypeVideoMode;
config.identifier = _interfaceController.config.identifier;
[_interfaceController startService:VPIServiceTypeVideoMode config:config];
...
//回调
//执行成功以后回调
- (void)vp_didCompleteForService:(VPIServiceType )type {
}
...
//执行失败以后回调
- (void)vp_didFailToCompleteForService:(VPIServiceType )type error:(NSError *)error {
}- VPInterfaceControllerConfig identifier参数为视频的标识(原url),可以用url作为参数 或 使用拼接 ID的方式来识别。
- 文档中的代码仅供参考,实际参数请根据项目自行配置。
- 互动层会向下层 view 发放点击手势,不用担心控制器界面会被阻挡手势。
- 请将互动层置于合适位置以防阻挡手势。
- 最佳位置为加载控制栏的下方,并且于手势层的上方,请不要将 cytronView 放 入包含手势操作的 View 中。
SDK目前支持系统为 ios8 以上。- 存在bundle包时请将bundle包放入资源文件中,使SDK能正常调用。
- SDWebImage不兼容问题,可以在Pods的工程中VideoOS Target中添加宏VPUPSDWebImage=1解决
请检查- (NSTimeInterval)videoPlayerCurrentTime是否对接正确,注意当前播放时间, 单位为秒, 包括小数
请检查- (VPIVideoPlayerSize *)videoPlayerSize是否对接正确,如果该方法对接正确,请检查页面横竖屏切换时,是否更新了VPInterfaceController方向- (void)notifyVideoScreenChanged:(VPIVideoPlayerOrientation)type
VideoOS所有的链接打开都由对接平台打开,通过- (void)vp_interfaceActionNotify:(NSDictionary *)actionDictionary方法传递给对接平台,VPIActionTypeOpenUrl表示需要对接平台打开链接
有,大部分的事件由- (void)vp_interfaceActionNotify:(NSDictionary *)actionDictionary方法传递给对接平台
/**
* 事件发送通知类型枚举
*/
typedef NS_ENUM(NSUInteger, VPIEventType) {
VPIEventTypePrepareShow = 1, //
VPIEventTypeShow, // 显示
VPIEventTypeClick, // 点击
VPIEventTypeClose, // 关闭
VPIEventTypeBack, // 中插返回
};
/**
* 事件处理通知类型枚举
*/
typedef NS_ENUM(NSUInteger, VPIActionType) {
VPIActionTypeNone = 0, //
VPIActionTypeOpenUrl, // 打开外链
VPIActionTypePauseVideo, // 暂停视频
VPIActionTypePlayVideo, // 播放视频
VPIActionTypeGetItem, // 获得物品
};
/**
* 事件监控通知
* @param actionDictionary 参数字典
* 对应
* Key: adID
* Value: string
*
* Key: adName
* Value: string
*
* Key: eventType
* Value: VPIEventType
*
* Key: actionType
* Value: VPIActionType
*
* Key: actionString
* Value: string
* 注:VPIActionTypeOpenUrl对应Url,VPIActionTypeGetItem对应ItemId
*/
- (void)vp_interfaceActionNotify:(NSDictionary *)actionDictionary;中插广告视频的返回按钮,通过VPIEventTypeBack通知对接平台,请按照视频的控制器的返回按钮相同的方法处理
中插广告开始播放,会返回VPIActionTypePauseVideo事件,需要暂停视频;
中插广告结束或被关闭,会返回VPIActionTypePlayVideo事件,需要重新播放视频;
打开中插外链,会返回VPIActionTypeOpenUrl事件,此时中插广告是暂停的,打开的外外链关闭以后,需要调用platformCloseActionWebView,继续播放中插广告。
-(void)notifyVideoScreenChanged:(VPIVideoPlayerOrientation)type 方法在切换屏幕前调用
(1)要确保_interfaceController = [[VPInterfaceController alloc] initWithFrame:self.view.bounds config:config videoPlayerSize:videoPlayerSize];中的 self.view 为全屏
(2)VPIVideoPlayerSize 要正确
(3)适配刘海屏顶部的44像素
修改VPLuaSDK.m中的host地址
注:现在VPLuaSDK.m中的host为SaaS版本的地址
修改VPLuaCommonInfo.m中的加密key
修改VPLuaCommonInfo为Platform中的VPUPCommonInfo


