|
|
## 1.SDK集成
|
|
|
|
|
|
### 1.1 方法1:Cocoapods导入
|
|
|
|
|
|
执行 `pod search 'CCVodSDK'`
|
|
|
|
|
|
Podfile 文件中增加如下代码:
|
|
|
`pod 'CCVodSDK'`
|
|
|
|
|
|
执行`pod install` 即可。
|
|
|
|
|
|
如果没有安装cocoapods,请执行 `sudo gem install cocoapods`命令,安装cocoapods。
|
|
|
|
|
|
如果搜索不到,请执行下述命令清除搜索列表缓存 `rm ~/Library/Caches/CocoaPods/search_index.json`,之后再调用search命令搜索。
|
|
|
|
|
|
### 1.2 方法2:手动导入SDK
|
|
|
|
|
|
下载iOS_SDK_Demo,将项目中的SDK(或外级目录下的include文件夹导入项目),选择`Copy items if needed`,Finish,导入即可。
|
|
|
|
|
|
SDK依赖的系统库如下
|
|
|
- Foundation.framework
|
|
|
- UIKit.framework
|
|
|
- OpenGLES.framework
|
|
|
- CoreMotion.framework
|
|
|
- CoreVideo.framework
|
|
|
- AVFoundation.framework
|
|
|
- Security.framework
|
|
|
- ImageIO.framework
|
|
|
- AudioToolbox.framework
|
|
|
- MobileCoreServices.framework
|
|
|
- CoreMedia.framework
|
|
|
|
|
|
## 2.SDK demo项目结构
|
|
|
|
|
|
名称|描述
|
|
|
---|:--:
|
|
|
Demo|iOS_SDK_Demo源码
|
|
|
doc|iOS点播SDK开发指南及离线API
|
|
|
include|SDK开放的头文件及静态库,同demo中的SDK文件夹
|
|
|
|
|
|
以下是iOS_SDK_Demo中,主要的目录结构及说明:
|
|
|
|
|
|
> Demo
|
|
|
|
|
|
>> DWAppDelegate.h/m
|
|
|
|
|
|
>> DWConfigurationManager.h/m (Demo app的一些全局配置设置)
|
|
|
|
|
|
>> SDK (iOS点播SDK)
|
|
|
|
|
|
>>> DWSDK.h (SDK头文件)
|
|
|
|
|
|
>>> DWPlayInfo.h (负责获取音视频对象数据)
|
|
|
|
|
|
>>> DWVodVideoModel.h (音视频model)
|
|
|
|
|
|
>>> DWVodAdInfoModel.h (广告model)
|
|
|
|
|
|
>>> DWPlayerView.h (继承自UIView,负责媒体播放,此类并不带播放相关UI,播放控制需自己实现)
|
|
|
|
|
|
>>> DWPlayerSkinView.h (带播放控制的PlayerView)
|
|
|
|
|
|
>>> DWDownloadSessionManager.h (下载管理中心,音视频下载功能通过此类来实现)
|
|
|
|
|
|
>>> DWDownloadModel.h (下载model)
|
|
|
|
|
|
>>> DWBatchDownloadUtility.h (批量下载功能,可以通过videos,批量来获取视频的下载链接)
|
|
|
|
|
|
>>> DWUploader.h (视频上传器)
|
|
|
|
|
|
>>> DWVideoCompressController.h (媒体选择页面,可以设置一些媒体压缩格式)
|
|
|
|
|
|
>>> ... (其他相关类,请详见demo)
|
|
|
|
|
|
>> Classes (Demo app 项目的主要类)
|
|
|
|
|
|
>>> DWMainViewController.h/m (首页)
|
|
|
|
|
|
>>> DWVodPlayViewController.h/m (在线视频播放页)
|
|
|
|
|
|
>>> DWVodPlayerSkinViewController.h/m (视频播放页,SDK中自带皮肤的播放控制页面)
|
|
|
|
|
|
>>> DWDownloadManagerViewController.h/m (下载管理页)
|
|
|
|
|
|
>>> DWLocalPlayViewController.h/m (本地视频播放页面)
|
|
|
|
|
|
>>> DWUploadViewController.h/m (上传管理页面)
|
|
|
|
|
|
>>> DWUploadInfoSetupViewController.h/m (上传设置页面)
|
|
|
|
|
|
>>> DWMemberViewController.h/m (app相关配置页面)
|
|
|
|
|
|
>>> DWNetworkMonitorViewController.h/m (网络检测页面)
|
|
|
|
|
|
>>> Base (demo app基类文件夹)
|
|
|
|
|
|
>>>> DWNavigationViewController.h/m
|
|
|
|
|
|
>>>> DWBaseViewController.h/m
|
|
|
|
|
|
>>> Model(demo app Model文件夹)
|
|
|
|
|
|
>>>> DWVodModel (demo中,媒体对象model)
|
|
|
|
|
|
>>>> DWTableChooseModel
|
|
|
|
|
|
>>>> DWUploadModel
|
|
|
|
|
|
>>>> CustomDirectorFactory
|
|
|
|
|
|
>>> View (demo app View文件夹,包含点播demo主要的功能。具体内部类比较繁多,这里就不一一列举了,详见demo)
|
|
|
|
|
|
>>>> Main
|
|
|
|
|
|
>>>> Player (视频播放相关的view)
|
|
|
|
|
|
>>>> VideoMark (视频打点)
|
|
|
|
|
|
>>>> Question (视频问答)
|
|
|
|
|
|
>>>> SubTitle (视频字幕)
|
|
|
|
|
|
>>>> Authorize (授权验证)
|
|
|
|
|
|
>>>> Gif(GIF录制)
|
|
|
|
|
|
>>>> Visitor(访客信息收集器)
|
|
|
|
|
|
>>>> Ad (广告)
|
|
|
|
|
|
>>>> Download (下载)
|
|
|
|
|
|
>>>> Upload (上传)
|
|
|
|
|
|
>>>> Others (其余使用到的类)
|
|
|
|
|
|
>>>> ... (额外的其他功能,这里就不一一列举了)
|
|
|
|
|
|
>> Plugins (工具类)
|
|
|
|
|
|
>>> Tools (Demo中使用的一些通用方法)
|
|
|
|
|
|
>>> Reachability (网络状态检测)
|
|
|
|
|
|
>>> SDWebImage
|
|
|
|
|
|
>>> SDCycleScrollView
|
|
|
|
|
|
>>> MJExtension
|
|
|
|
|
|
>>> Masonry
|
|
|
|
|
|
>>> MBProgressHUD
|
|
|
|
|
|
>> Images (图片资源)
|
|
|
|
|
|
## 3.快速集成
|
|
|
注:快速集成主要提供的是视频播放、下载、上传功能等核心功能的使用方式。
|
|
|
|
|
|
### 3.1 视频播放功能
|
|
|
|
|
|
#### 3.1.1 在合适的位置设置AudioSession
|
|
|
|
|
|
```
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
|
{
|
|
|
//设置全局AVAudioSession
|
|
|
NSError *categoryError = nil;
|
|
|
BOOL success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&categoryError];
|
|
|
if (!success)
|
|
|
{
|
|
|
NSLog(@"Error setting audio session category: %@", categoryError);
|
|
|
}
|
|
|
NSError *activeError = nil;
|
|
|
success = [[AVAudioSession sharedInstance] setActive:YES error:&activeError];
|
|
|
if (!success)
|
|
|
{
|
|
|
NSLog(@"Error setting audio session active: %@", activeError);
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
#### 3.1.2 通过CC账号UserID、APIKey、VideoId,来获取DWVodVideoModel对象。无CC账号?[点击注册](https://admin.bokecc.com/login.bo)
|
|
|
|
|
|
```
|
|
|
DWPlayInfo * playInfo = [[DWPlayInfo alloc]initWithUserId:@"账号ID" andVideoId:@"视频ID" key:@"APIKey" hlsSupport:@"1"];
|
|
|
playInfo.timeoutSeconds = 30;
|
|
|
playInfo.mediatype = @"1";
|
|
|
playInfo.verificationCode = @"授权验证码,没有此功能不需要设置";
|
|
|
playInfo.finishBlock = ^(DWVodVideoModel *vodVideo) {
|
|
|
//成功回调
|
|
|
NSLog(@"%@",vodVideo);
|
|
|
};
|
|
|
playInfo.errorBlock = ^(NSError *error) {
|
|
|
//失败回调
|
|
|
};
|
|
|
[playInfo start];
|
|
|
|
|
|
```
|
|
|
|
|
|
#### 3.1.3 创建DWPlayerView(默认播放器)/DWPlayerSkinView(带皮肤的播放器)对象添加到视图中,待获取到DWVodVideoModel对象后传入,即可播放在线视频
|
|
|
|
|
|
```
|
|
|
//创建默认播放器对象
|
|
|
self.playerView = [[DWPlayerView alloc]init];
|
|
|
[self addSubview:self.playerView];
|
|
|
|
|
|
//或者创建带皮肤的播放器对象
|
|
|
self.playerSkinView = [[DWPlayerSkinView alloc]initSkinView];
|
|
|
[self addSubview: self.playerSkinView];
|
|
|
|
|
|
//等待DWPlayInfo获取到DWVodVideoModel对象
|
|
|
playInfo.finishBlock = ^(DWVodVideoModel *vodVideo) {
|
|
|
//成功回调
|
|
|
//NSLog(@"%@",vodVideo);
|
|
|
[self.playerView playVodViedo:videoModel withCustomId:nil];
|
|
|
[self.playerView play];
|
|
|
|
|
|
//或者
|
|
|
//[self.playerSkinView playVodViedo:vodVideo];
|
|
|
};
|
|
|
...
|
|
|
|
|
|
```
|
|
|
|
|
|
### 3.2 下载功能
|
|
|
|
|
|
#### 3.2.1 在合适的位置调用configureBackroundSession方法
|
|
|
|
|
|
```
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
|
{
|
|
|
//后台下载设置
|
|
|
[[DWDownloadSessionManager manager] configureBackroundSession];
|
|
|
}
|
|
|
```
|
|
|
|
|
|
#### 3.2.2 通过CC账号UserID、APIKey、VideoId,来获取DWVodVideoModel对象
|
|
|
|
|
|
```
|
|
|
//获取方式与视频获取方式一样,只不过hlsSupport参数要传@"0"
|
|
|
DWPlayInfo * playInfo = [[DWPlayInfo alloc]initWithUserId:@"账号ID" andVideoId:@"视频ID" key:@"APIKey" hlsSupport:@"0"];
|
|
|
...
|
|
|
|
|
|
```
|
|
|
|
|
|
#### 3.2.3 获取DWDownloadSessionManager单例对象,创建DWDownloadModel对象,通过调用startWithDownloadModel:方法即可开始下载
|
|
|
|
|
|
```
|
|
|
//等待DWPlayInfo获取到DWVodVideoModel对象
|
|
|
playInfo.finishBlock = ^(DWVodVideoModel *vodVideo) {
|
|
|
//成功回调
|
|
|
|
|
|
//得到需要下载的清晰度model,数据
|
|
|
//这里根据自身业务逻辑进行调整,这里下载的第一个视频
|
|
|
DWVideoQualityModel * qualityModel = [videoModel.qualities firstObject];
|
|
|
|
|
|
DWDownloadSessionManager * manager = [DWDownloadSessionManager manager];
|
|
|
//验证当前任务是否已经在下载队列中
|
|
|
if ([manager checkLocalResourceWithVideoId:videoModel.videoId WithQuality:qualityModel.quality]) {
|
|
|
return;
|
|
|
}
|
|
|
//没有此任务,创建DWDownloadModel对象,开始下载
|
|
|
DWDownloadModel * model = [DWDownloadSessionManager createDownloadModel:videoModel Quality:qualityModel.quality AndOthersInfo:nil];
|
|
|
if (!model) {
|
|
|
//DownloadModel创建失败,请检查参数
|
|
|
return;
|
|
|
}
|
|
|
[manager startWithDownloadModel:model];
|
|
|
};
|
|
|
|
|
|
```
|
|
|
|
|
|
### 3.3 上传功能
|
|
|
|
|
|
#### 3.3.1 初始化DWUploader对象,调用start方法,即可上传视频
|
|
|
|
|
|
```
|
|
|
//videoTitle不得为空 videoPath音视频文件路径
|
|
|
DWUploader *uploader = [[DWUploader alloc] initWithuserId:@"账号ID"
|
|
|
andKey:@"APIKey"
|
|
|
uploadVideoTitle:@"视频标题"
|
|
|
videoDescription:@"视频描述"
|
|
|
videoTag:@"视频tag"
|
|
|
videoPath:@"视频本地路径"
|
|
|
notifyURL:@"回调地址"];
|
|
|
//开始上传
|
|
|
[uploader start];
|
|
|
``` |