|
|
|
## 1.播放功能
|
|
|
|
|
|
|
|
### 1.1 DWVodVideoModel数据模型的使用
|
|
|
|
DWVodVideoModel类是SDK中媒体的数据模型,无论是播放、下载都需要通过DWPlayInfo对象来获取到此对象。获取方式详见2.集成指南。
|
|
|
|
|
|
|
|
以下是具体DWVodVideoModel中,包含的字段及含义:
|
|
|
|
```
|
|
|
|
///视频 id
|
|
|
|
@property (nonatomic, strong, readonly) NSString * videoId;
|
|
|
|
|
|
|
|
///视频标题
|
|
|
|
@property (nonatomic, strong, readonly) NSString * title;
|
|
|
|
|
|
|
|
///视频状态 为0代表可用,否则代表不可用。
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger status;
|
|
|
|
|
|
|
|
///视频状态描述 若视频不可用,具体描述原因
|
|
|
|
@property (nonatomic, strong, readonly) NSString * statusInfo;
|
|
|
|
|
|
|
|
///默认清晰度
|
|
|
|
@property (nonatomic, strong, readonly) NSString * defaultquality;
|
|
|
|
|
|
|
|
///分享URL
|
|
|
|
@property (nonatomic, strong, readonly) NSString * shareurl;
|
|
|
|
|
|
|
|
///视频清晰度
|
|
|
|
@property (nonatomic, strong, readonly) NSArray <DWVideoQualityModel *> * videoQualities;
|
|
|
|
|
|
|
|
///音频清晰度
|
|
|
|
@property (nonatomic, strong, readonly) NSArray <DWVideoQualityModel *> * radioQualities;
|
|
|
|
|
|
|
|
///授权验证信息字典
|
|
|
|
@property (nonatomic, strong, readonly) DWVideoAuthorizeModel * authorize;
|
|
|
|
|
|
|
|
///是否原片播放
|
|
|
|
@property (nonatomic, assign, readonly) BOOL isRealTime;
|
|
|
|
|
|
|
|
///是否支持VR 1表示播放VR视频,0表示普通
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger vrmode;
|
|
|
|
|
|
|
|
///视频打点数据
|
|
|
|
@property (nonatomic, strong, readonly) NSArray <DWVideoMarkModel *> * videomarks;
|
|
|
|
|
|
|
|
///视频问答数据
|
|
|
|
@property (nonatomic, strong, readonly) NSArray <DWVideoQuestionModel *> * questions;
|
|
|
|
|
|
|
|
//字幕
|
|
|
|
///取值含义 -1 无字幕 ,0:subtitle, 1:subtitle2, 2:双语
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger defaultSubtitle;
|
|
|
|
///字幕1
|
|
|
|
@property (nonatomic, strong, readonly) DWVideoSubtitleModel * subtitle;
|
|
|
|
///字幕2
|
|
|
|
@property (nonatomic, strong, readonly) DWVideoSubtitleModel * subtitle2;
|
|
|
|
|
|
|
|
//访客信息收集
|
|
|
|
@property (nonatomic, strong, readonly) DWVideoVisitorModel * visitor;
|
|
|
|
|
|
|
|
@property (nonatomic, assign, readonly)int reason;
|
|
|
|
|
|
|
|
@property (nonatomic, strong, readonly)NSDate * responseTime;
|
|
|
|
|
|
|
|
@property (nonatomic, strong, readonly)NSDate * startTime;
|
|
|
|
|
|
|
|
///cc账号id
|
|
|
|
@property (nonatomic, strong, readonly) NSString * CCUserId;
|
|
|
|
|
|
|
|
///cc账号key
|
|
|
|
@property (nonatomic, strong, readonly) NSString * CCApiKey;
|
|
|
|
|
|
|
|
///是否支持hls
|
|
|
|
@property (nonatomic, assign, readonly) BOOL hlsSupport;
|
|
|
|
|
|
|
|
///UPID
|
|
|
|
@property (nonatomic, strong, readonly) NSString * UPID;
|
|
|
|
|
|
|
|
///token
|
|
|
|
@property (nonatomic, strong, readonly) NSString * token;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.2 播放功能集成
|
|
|
|
### 1.2.1 播放功能的快速集成,请详见2.集成指南
|
|
|
|
|
|
|
|
### 1.2.2 DWPlayerView的使用
|
|
|
|
DWPlayerView是SDK的播放视图,可以通过创建此对象,添加到需要显示的视图上,并传入数据对象即可播放。
|
|
|
|
|
|
|
|
DWPlayerView包含的属性及方法如下:
|
|
|
|
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
播放属性
|
|
|
|
*/
|
|
|
|
@property(nonatomic,strong,readonly)AVPlayer *player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
代理
|
|
|
|
*/
|
|
|
|
@property(nonatomic,weak)id<DWVideoPlayerDelegate> delegate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
AVPlayerLayer的videoGravity属性设置
|
|
|
|
AVLayerVideoGravityResize, // 非均匀模式。两个维度完全填充至整个视图区域
|
|
|
|
AVLayerVideoGravityResizeAspect, // 等比例填充,直到一个维度到达区域边界
|
|
|
|
AVLayerVideoGravityResizeAspectFill, // 等比例填充,直到填充满整个视图区域,其中一个维度的部分区域会被裁剪
|
|
|
|
*/
|
|
|
|
@property(nonatomic,copy)NSString *videoGravity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
//是否正在播放
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)BOOL playing;
|
|
|
|
|
|
|
|
/**
|
|
|
|
是否循环播放 默认为NO
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)BOOL looping;
|
|
|
|
|
|
|
|
/**
|
|
|
|
是否静音 默认为NO
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)BOOL muted;
|
|
|
|
|
|
|
|
/**
|
|
|
|
视频加载超时时间 默认30s
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)CGFloat timeOutLoad;
|
|
|
|
|
|
|
|
/**
|
|
|
|
缓存超时时间 默认30s
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)CGFloat timeOutBuffer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
缓冲模式 默认DWPlayerViewLoadStyleDefault
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)DWPlayerViewLoadStyle loadStyle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
是否是备用线路
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)BOOL isSpar;
|
|
|
|
|
|
|
|
/**
|
|
|
|
当前正在播放的媒体清晰度model,非在线视频返回nil。注意,在调用playVodViedo:withCustomId:方法后才可获取到此属性
|
|
|
|
*/
|
|
|
|
@property (nonatomic,strong,readonly) DWVideoQualityModel * qualityModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
返回当前播放的离线model,在线视频返回nil。注意,在调用playLocalVideo:方法后才可获取到此属性。
|
|
|
|
*/
|
|
|
|
@property (nonatomic,strong,readonly) DWDownloadModel * downloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
单例
|
|
|
|
|
|
|
|
@return 单例对象
|
|
|
|
*/
|
|
|
|
+ (instancetype)sharedInstance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
初始化播放对象
|
|
|
|
@return DWPlayerView
|
|
|
|
*/
|
|
|
|
-(instancetype)init;
|
|
|
|
|
|
|
|
/**
|
|
|
|
初始化播放对象
|
|
|
|
@param frame
|
|
|
|
@return DWPlayerView
|
|
|
|
*/
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
播放网络视频 , 播放默认清晰度,对于在线媒体,必须要执行此方法,否则会导致数据统计缺失
|
|
|
|
@param videoModel 视频model
|
|
|
|
@param customId 用户自定义参数 有自定义统计参数需求/流量统计的客户必须传值,没有此需求的客户请传nil
|
|
|
|
*/
|
|
|
|
-(void)playVodViedo:(DWVodVideoModel *)videoModel withCustomId:(NSString *)customId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
播放本地视频
|
|
|
|
@param downloadModel 下载model
|
|
|
|
*/
|
|
|
|
-(void)playLocalVideo:(DWDownloadModel *)downloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
切换清晰度方法
|
|
|
|
@param qualitiyModel 清晰度model
|
|
|
|
@param customId 用户自定义参数 有自定义统计参数需求/流量统计的客户必须传值,没有此需求的客户请传nil
|
|
|
|
*/
|
|
|
|
-(void)switchQuality:(DWVideoQualityModel *)qualitiyModel withCustomId:(NSString *)customId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
切换备用线路 切换当前清晰度下的备用线路
|
|
|
|
*/
|
|
|
|
-(void)switchSparPlayLine;
|
|
|
|
|
|
|
|
/**
|
|
|
|
设置是否允许后台播放,目前只支持音频后台播放
|
|
|
|
@param play 是否允许后台播放
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (void)setPlayInBackground:(BOOL)play;
|
|
|
|
|
|
|
|
/**
|
|
|
|
切换倍速
|
|
|
|
@param rate 速率
|
|
|
|
*/
|
|
|
|
- (void)setPlayerRate:(float)rate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
重复播放当前媒体
|
|
|
|
*/
|
|
|
|
- (void)repeatPlay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
播放
|
|
|
|
*/
|
|
|
|
- (void)play;
|
|
|
|
|
|
|
|
/**
|
|
|
|
暂停
|
|
|
|
*/
|
|
|
|
- (void)pause;
|
|
|
|
|
|
|
|
/**
|
|
|
|
拖到XX秒播放视频,在AVPlayerItemStatusReadyToPlay即状态处于可播放后 才会有效果
|
|
|
|
@param time 跳转时间
|
|
|
|
*/
|
|
|
|
- (void)scrub:(float)time;
|
|
|
|
|
|
|
|
/**
|
|
|
|
精确拖拽到XX秒播放视频,在AVPlayerItemStatusReadyToPlay即状态处于可播放后 才会有效果
|
|
|
|
@param time 跳转时间
|
|
|
|
@param completion 跳转完成回调
|
|
|
|
*/
|
|
|
|
-(void)scrubPrecise:(float)time CompletionHandler:(void(^)(BOOL finished))completion;
|
|
|
|
|
|
|
|
/**
|
|
|
|
记录播放位置的方法(只为记忆播放功能使用 其它地方请调用scrub / scrubPrecise方法),在AVPlayerItemStatusReadyToPlay即状态处于可播放后 才会有效果
|
|
|
|
@param time 跳转时间
|
|
|
|
*/
|
|
|
|
- (void)oldTimeScrub:(float)time;
|
|
|
|
|
|
|
|
/**
|
|
|
|
设置音量
|
|
|
|
@param volume 音量
|
|
|
|
*/
|
|
|
|
- (void)setVolume:(float)volume;
|
|
|
|
|
|
|
|
/**
|
|
|
|
加大音量
|
|
|
|
*/
|
|
|
|
- (void)fadeInVolume;
|
|
|
|
|
|
|
|
/**
|
|
|
|
减小音量
|
|
|
|
*/
|
|
|
|
- (void)fadeOutVolume;
|
|
|
|
|
|
|
|
/**
|
|
|
|
关闭|释放播放资源
|
|
|
|
*/
|
|
|
|
- (void)resetPlayer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
停止视频播放统计 播放页面关闭时务必调用removeTimer方法
|
|
|
|
注意:播放页面关闭时 如需释放资源 调用方式如下{
|
|
|
|
[playerView removeTimer];
|
|
|
|
[playerView resetPlayer];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
如无需释放播放资源 调用方式如下{
|
|
|
|
[playerView removeTimer];
|
|
|
|
[playerView pause];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
- (void)removeTimer;
|
|
|
|
|
|
|
|
// AirPlay技术 外部播放设置
|
|
|
|
/**
|
|
|
|
支持AirPlay外部播放 默认支持
|
|
|
|
*/
|
|
|
|
- (void)enableAirplay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
不支持AirPlay外部播放
|
|
|
|
*/
|
|
|
|
- (void)disableAirplay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
检测是否支持支持AirPlay外部播放
|
|
|
|
|
|
|
|
@return BOOL
|
|
|
|
*/
|
|
|
|
- (BOOL)isAirplayEnabled;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
获取可播放的持续时间
|
|
|
|
@return 可播放的持续时间
|
|
|
|
*/
|
|
|
|
- (NSTimeInterval )playableDuration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
获取当前player播放的URL 可用于截图
|
|
|
|
@return 当前播放URL
|
|
|
|
*/
|
|
|
|
-(NSURL *)urlOfCurrentlyPlayingInPlayer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
获取用来做GIF功能的URL 加密调用
|
|
|
|
@return URL
|
|
|
|
*/
|
|
|
|
- (NSURL *)drmGIFURL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
获取用来做GIF功能的URL 非加密调用
|
|
|
|
@return URL
|
|
|
|
*/
|
|
|
|
- (NSURL *)unDrmGIFURL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
问答统计 有此需求的客户调用 一个问题只发送一次
|
|
|
|
@param videoId 视频ID
|
|
|
|
@param questionId 问题ID
|
|
|
|
@param answerId 用户选择的选项ID,以逗号分隔多个选项ID。
|
|
|
|
如1345是单选 2067,3092,4789是多选
|
|
|
|
@param status YES正确 NO错误
|
|
|
|
*/
|
|
|
|
- (void)reportQuestionWithVideoId:(NSString *)videoId questionId:(NSString *)questionId answerId:(NSString *)answerId status:(BOOL )status;
|
|
|
|
|
|
|
|
/**
|
|
|
|
访客信息统计上报 有此需求的客户调用
|
|
|
|
|
|
|
|
@param visitorId 访客信息收集器ID 必填
|
|
|
|
@param videoId 视频ID 必填
|
|
|
|
@param userId CC账号ID 必填
|
|
|
|
@param message 上报信息 必填 具体格式详见demo
|
|
|
|
*/
|
|
|
|
-(void)reportVisitorCollectWithVisitorId:(NSString *)visitorId VideoId:(NSString *)videoId UserId:(NSString *)userId AndMessage:(NSString *)message;
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
### 1.2.3 DWPlayerViewDelegate的使用
|
|
|
|
DWPlayerViewDelegate是DWPlayerView的代理方法,包含了一系列的播放回调,用户可根据自己的功能需求来调用。
|
|
|
|
|
|
|
|
DWPlayerViewDelegate方法及含义如下:
|
|
|
|
```
|
|
|
|
//所有的代理方法均已回到主线程 可直接刷新UI
|
|
|
|
//可播放
|
|
|
|
- (void)videoPlayerIsReadyToPlayVideo:(DWPlayerView *)playerView;
|
|
|
|
|
|
|
|
//播放完毕
|
|
|
|
- (void)videoPlayerDidReachEnd:(DWPlayerView *)playerView;
|
|
|
|
|
|
|
|
//播放中 time:当前播放时间
|
|
|
|
- (void)videoPlayer:(DWPlayerView *)playerView timeDidChange:(float)time;
|
|
|
|
|
|
|
|
//duration 当前缓冲的长度
|
|
|
|
- (void)videoPlayer:(DWPlayerView *)playerView loadedTimeRangeDidChange:(float)duration;
|
|
|
|
|
|
|
|
//没数据 即播放卡顿
|
|
|
|
- (void)videoPlayerPlaybackBufferEmpty:(DWPlayerView *)playerView;
|
|
|
|
|
|
|
|
//有数据 能够继续播放
|
|
|
|
- (void)videoPlayerPlaybackLikelyToKeepUp:(DWPlayerView *)playerView;
|
|
|
|
|
|
|
|
//加载超时/scrub超时
|
|
|
|
- (void)videoPlayer:(DWPlayerView *)playerView receivedTimeOut:(DWPlayerViewTimeOut )timeOut;
|
|
|
|
|
|
|
|
//加载失败
|
|
|
|
- (void)videoPlayer:(DWPlayerView *)playerView didFailWithError:(NSError *)error;
|
|
|
|
```
|
|
|
|
|
|
|
|
### 1.2.4 DWPlayerSkinView的使用
|
|
|
|
为了方便用户快速集成我们的SDK,SDK中提供了一套带皮肤的播放器。若此播放器不满足需求,用户可使用DWPlayerView,来高度定制化自己的播放页面。
|
|
|
|
|
|
|
|
DWPlayerSkinView包含的属性及方法如下:
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
delegate
|
|
|
|
*/
|
|
|
|
@property(nonatomic,weak) id<DWPlayerSkinViewDelegate> delegate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
当期视频标题
|
|
|
|
*/
|
|
|
|
@property(nonatomic,strong)NSString * title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
在线视频model
|
|
|
|
*/
|
|
|
|
@property(nonatomic,strong,readonly)DWVodVideoModel * videoModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
离线视频model
|
|
|
|
*/
|
|
|
|
@property(nonatomic,strong,readonly)DWDownloadModel * downloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
DWPlayerView 对象
|
|
|
|
*/
|
|
|
|
@property(nonatomic,strong,readonly)DWPlayerView * player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
用户自定义参数 有自定义统计参数需求/流量统计的客户必须传值
|
|
|
|
没有此需求的客户请传nil
|
|
|
|
在不需要统计的地方均传nil 譬如广告视频
|
|
|
|
*/
|
|
|
|
@property(nonatomic,copy)NSString * customId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
AVLayerVideoGravityResize, // 非均匀模式。两个维度完全填充至整个视图区域
|
|
|
|
AVLayerVideoGravityResizeAspect, // 等比例填充,直到一个维度到达区域边界
|
|
|
|
AVLayerVideoGravityResizeAspectFill, // 等比例填充,直到填充满整个视图区域,其中一个维度的部分区域会被裁剪
|
|
|
|
*/
|
|
|
|
@property(nonatomic,strong)NSString * videoGravity;
|
|
|
|
|
|
|
|
/**
|
|
|
|
宽高比 默认是4:3
|
|
|
|
若需改变view的大小,请设置此属性,不要直接设置frame
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)CGFloat screenScale;
|
|
|
|
|
|
|
|
/**
|
|
|
|
是否在播放中 YES 正在播放,NO 暂停播放
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)BOOL isPlaying;
|
|
|
|
|
|
|
|
/**
|
|
|
|
当前是否全屏 YES 全屏,NO 非全屏
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)BOOL isFull;
|
|
|
|
|
|
|
|
/**
|
|
|
|
当前播放倍速 默认 1
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)CGFloat speed;
|
|
|
|
|
|
|
|
/**
|
|
|
|
当期播放媒体是否是视频 YES 视频,NO 音频
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)BOOL isPlayVideo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
媒体总时长 收到videoPlayerSkinReadyToPlay回调以后 生效
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)NSTimeInterval totalDuration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
当前播放时间
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)NSTimeInterval currentDuration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
当前缓冲时间 只对在线视频有效,离线视频为0
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign,readonly)NSTimeInterval bufferDuration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
媒体播放的起始位置
|
|
|
|
如果设置此值 收到videoPlayerSkinReadyToPlay回调以后,会自动跳转到当前进度,包括切换清晰度时,也会拖拽到此。 默认为0
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)NSTimeInterval scrubPosition;
|
|
|
|
|
|
|
|
/**
|
|
|
|
是否允许自动旋转 默认YES ,若设置NO,屏幕旋转时,将不会改变view的大小
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)BOOL allowAutoRotate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
播放器默认横竖屏状态设置
|
|
|
|
仅在自动旋转功能关闭的情况下生效 会强制转换屏幕,需跟allowAutoRotate搭配使用。 默认YES,竖屏模式
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)BOOL isPortraitModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
初始化方法,请调用此方法,不要调用init,initWithFrame等初始化方法
|
|
|
|
@return DWPlayerSkinView对象
|
|
|
|
*/
|
|
|
|
-(instancetype)initSkinView;
|
|
|
|
|
|
|
|
/**
|
|
|
|
设置播放网络视频数据,并开始播放
|
|
|
|
@param videoModel DWVodVideoModel对象
|
|
|
|
*/
|
|
|
|
-(void)playVodViedo:(DWVodVideoModel *)videoModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
设置播放本地视频,并开始播放
|
|
|
|
@param downloadModel DWDownloadModel对象
|
|
|
|
*/
|
|
|
|
-(void)playLocalVideo:(DWDownloadModel *)downloadModel;
|
|
|
|
```
|
|
|
|
注意:DWPlayerSkinView对象暂不支持修改frame的操作,view的大小完全根据传入的screenScale属性来决定的。
|
|
|
|
|
|
|
|
### 1.2.5 DWPlayerSkinViewDelegate的使用
|
|
|
|
DWPlayerSkinViewDelegate是DWPlayerSkinView的代理方法,包含了一些事件回调及播放状态回调。
|
|
|
|
|
|
|
|
DWPlayerSkinViewDelegate方法及含义如下:
|
|
|
|
```
|
|
|
|
//所有的代理方法均已回到主线程 可直接刷新UI
|
|
|
|
//准备播放
|
|
|
|
-(void)videoPlayerSkinReadyToPlay:(DWPlayerSkinView *)playerSkinView;
|
|
|
|
|
|
|
|
//当前播放时长回调
|
|
|
|
-(void)videoPlayerSkin:(DWPlayerSkinView *)playerSkinView timeDidChange:(NSTimeInterval)time;
|
|
|
|
|
|
|
|
//媒体播放完毕回调
|
|
|
|
-(void)videoPlayerSkinEndToPlay:(DWPlayerSkinView *)playerSkinView;
|
|
|
|
|
|
|
|
//开始/暂停事件触发回调
|
|
|
|
-(void)videoPlayerSkin:(DWPlayerSkinView *)playerSkinView PlayOrPauseAction:(BOOL)isPlay;
|
|
|
|
|
|
|
|
//全屏/非全屏旋转回调
|
|
|
|
-(void)videoPlayerSkin:(DWPlayerSkinView *)playerSkinView FullScreenAction:(BOOL)isScreen;
|
|
|
|
|
|
|
|
//后退按钮回调 注意:若backPortrait为YES,会清空播放器。
|
|
|
|
-(void)videoPlayerSkin:(DWPlayerSkinView *)playerSkinView ReturnBackAction:(BOOL)backPortrait;
|
|
|
|
|
|
|
|
//倍速切换回调
|
|
|
|
-(void)videoPlayerSkin:(DWPlayerSkinView *)playerSkinView SpeedSwitchAction:(CGFloat)speed;
|
|
|
|
|
|
|
|
//下载事件回调 ,返回当前播放清晰度model
|
|
|
|
-(void)videoPlayerSkin:(DWPlayerSkinView *)playerSkinView DownloadAction:(DWVideoQualityModel *)qualityModel;
|
|
|
|
|
|
|
|
//错误/警告信息回调
|
|
|
|
-(void)videoPlayerSkin:(DWPlayerSkinView *)playerSkinView didFailWithError:(NSError *)error;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.3 统计功能
|
|
|
|
|
|
|
|
### 1.3.1 默认统计功能
|
|
|
|
此功能已在SDK内部实现,用户无需在做额外的设置即可在后台看到视频相关的统计数据。
|
|
|
|
|
|
|
|
### 1.3.2 自定义参数统计功能
|
|
|
|
若有自定义统计参数需求/流量统计的需求的客户,需自行进行如下设置。
|
|
|
|
|
|
|
|
下面是使用DWPlayerView / DWPlayerSkinView 播放器的具体使用方式:
|
|
|
|
|
|
|
|
对于使用DWPlayerView对象的用户,在设置播放数据或切换播放数据时,请传入customId即可。
|
|
|
|
```
|
|
|
|
[self.playerView playVodViedo:videoModel withCustomId:@"传入需要分类的customId"];
|
|
|
|
或者
|
|
|
|
[self.playerView switchQuality:qualityModel withCustomId:@"传入需要分类的customId"];
|
|
|
|
```
|
|
|
|
|
|
|
|
对于使用DWPlayerSkinView对象的用户,在调用playVodViedo:方法前,设置customId属性即可。例:
|
|
|
|
```
|
|
|
|
self.playerSkinView.customId = @"传入需要分类的customId";
|
|
|
|
...
|
|
|
|
[self.playerSkinView playVodViedo:播放对象];
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.4 视频打点功能
|
|
|
|
视频打点数据为DWVodVideoModel对象的<DWVideoMarkModel *>videomarks数组。
|
|
|
|
|
|
|
|
DWVideoMarkModel数据及含义如下:
|
|
|
|
```
|
|
|
|
///打点描述内容
|
|
|
|
@property (nonatomic, strong, readonly)NSString * markdesc;
|
|
|
|
|
|
|
|
///打点时间
|
|
|
|
@property (nonatomic, assign, readonly)NSInteger marktime;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.5 视频问答
|
|
|
|
视频问答数据为DWVodVideoModel对象的<DWVideoQuestionModel *>questions数组。
|
|
|
|
|
|
|
|
DWVideoQuestionModel数据及含义如下:
|
|
|
|
```
|
|
|
|
///问答id
|
|
|
|
@property (nonatomic, strong, readonly)NSString * questionId;
|
|
|
|
|
|
|
|
///问答题目描述
|
|
|
|
@property (nonatomic, strong, readonly)NSString * content;
|
|
|
|
|
|
|
|
///问答出现时间
|
|
|
|
@property (nonatomic, assign, readonly)NSInteger showTime;
|
|
|
|
|
|
|
|
///答案解释
|
|
|
|
@property (nonatomic, strong, readonly)NSString * explainInfo;
|
|
|
|
|
|
|
|
///是否允许跳过
|
|
|
|
@property (nonatomic, assign, readonly)BOOL jump;
|
|
|
|
|
|
|
|
///答错退回时间 -1表示不回退
|
|
|
|
@property (nonatomic, assign, readonly)NSInteger backSecond;
|
|
|
|
|
|
|
|
///选项列表
|
|
|
|
@property (nonatomic, strong, readonly)NSArray <DWVideoQuestionAnswerModel *> * answers;
|
|
|
|
|
|
|
|
///是否多选
|
|
|
|
@property (nonatomic, assign, readonly) BOOL multipleSelect;
|
|
|
|
|
|
|
|
///是否显示问答
|
|
|
|
@property (nonatomic, assign) BOOL isShow;
|
|
|
|
|
|
|
|
|
|
|
|
///视频问题选项数据模型DWVideoQuestionAnswerModel
|
|
|
|
///选项id
|
|
|
|
@property (nonatomic, strong, readonly)NSString * answerId;
|
|
|
|
|
|
|
|
///选项内容描述
|
|
|
|
@property (nonatomic, strong, readonly)NSString * content;
|
|
|
|
|
|
|
|
///是否是正确答案
|
|
|
|
@property (nonatomic, assign, readonly)BOOL isRight;
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.6 视频字幕
|
|
|
|
视频字幕相关的数据包含三个,DWVodVideoModel对象的defaultSubtitle、subtitle、subtitle2。
|
|
|
|
|
|
|
|
具体数据及含义如下:
|
|
|
|
|
|
|
|
```
|
|
|
|
///取值含义 -1 无字幕 ,0:subtitle, 1:subtitle2, 2:双语字幕
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger defaultSubtitle;
|
|
|
|
///字幕1
|
|
|
|
@property (nonatomic, strong, readonly) DWVideoSubtitleModel * subtitle;
|
|
|
|
///字幕2
|
|
|
|
@property (nonatomic, strong, readonly) DWVideoSubtitleModel * subtitle2;
|
|
|
|
|
|
|
|
//DWVideoSubtitleModel对象
|
|
|
|
|
|
|
|
///字幕文件地址
|
|
|
|
@property (nonatomic, strong, readonly)NSString * url;
|
|
|
|
|
|
|
|
///字幕字体
|
|
|
|
@property (nonatomic, strong, readonly)NSString * font;
|
|
|
|
|
|
|
|
///字幕字体大小
|
|
|
|
@property (nonatomic, assign, readonly)CGFloat size;
|
|
|
|
|
|
|
|
///字幕字体色值 eg:0xFFFFFF
|
|
|
|
@property (nonatomic, strong, readonly)NSString * color;
|
|
|
|
|
|
|
|
///阴影色值 eg:0x000000
|
|
|
|
@property (nonatomic, strong, readonly)NSString * surroundColor;
|
|
|
|
|
|
|
|
///字幕距离底部的偏移量 百分比
|
|
|
|
@property (nonatomic, assign, readonly)CGFloat bottom;
|
|
|
|
|
|
|
|
///编码格式 utf-8 / gbk
|
|
|
|
@property (nonatomic, strong, readonly)NSString * code;
|
|
|
|
|
|
|
|
///字幕名称
|
|
|
|
@property (nonatomic, strong, readonly)NSString * subtitleName;
|
|
|
|
|
|
|
|
///双语字幕中的位置 1:上, 2:下 单字幕时sort=0
|
|
|
|
@property (nonatomic, assign, readonly)NSInteger sort;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.7 授权验证功能
|
|
|
|
授权验证数据为DWVodVideoModel对象的authorize。
|
|
|
|
|
|
|
|
DWVideoAuthorizeModel数据及含义如下:
|
|
|
|
```
|
|
|
|
///是否允许完整播放 NO:不允许完整播放 YES:允许完整播放
|
|
|
|
@property (nonatomic, assign, readonly)BOOL enable;
|
|
|
|
|
|
|
|
///视频试看时间,单位:秒
|
|
|
|
@property (nonatomic, assign, readonly)NSInteger freetime;
|
|
|
|
|
|
|
|
///提示内容
|
|
|
|
@property (nonatomic, strong, readonly)NSString * message;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.8 广告功能
|
|
|
|
用户可以通过DWAdInfo,来获取后台投放的广告,实现广告的播放功能。
|
|
|
|
|
|
|
|
### 1.8.1 通过DWAdInfo,获取后台投放的广告信息
|
|
|
|
通过账号ID、视频ID、广告类型(现在支持片头广告、暂停广告两种类型),来获取DWVodAdInfoModel广告模型数据。
|
|
|
|
```
|
|
|
|
DWAdInfo * adInfo = [[DWAdInfo alloc]initWithUserId:@"账号ID" andVideoId:@"视频ID" type:@"广告类型,详见demo"];
|
|
|
|
[adInfo start];
|
|
|
|
adInfo.finishBlock = ^(DWVodAdInfoModel *adInfo) {
|
|
|
|
//广告获取成功回调
|
|
|
|
};
|
|
|
|
adInfo.errorBlock = ^(NSError *error) {
|
|
|
|
//广告获取失败回调
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
### 1.8.2 DWVodAdInfoModel广告模型数据
|
|
|
|
DWVodAdInfoModel属性及含义如下:
|
|
|
|
```
|
|
|
|
///广告信息获取情况 0:获取成功 非0:获取失败
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger result;
|
|
|
|
|
|
|
|
///广告类型 1 片头广告 2 暂停广告
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger type;
|
|
|
|
|
|
|
|
///广告ID
|
|
|
|
@property (nonatomic, strong, readonly) NSString * adId;
|
|
|
|
|
|
|
|
///广告展示时长
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger time;
|
|
|
|
|
|
|
|
///是否响应点击
|
|
|
|
@property (nonatomic, assign, readonly) BOOL canClick;
|
|
|
|
|
|
|
|
///是否出现跳过广告按钮
|
|
|
|
@property (nonatomic, assign, readonly) BOOL canSkip;
|
|
|
|
|
|
|
|
///跳过时间,单位秒,经过若干秒后显示跳过按钮,0代表立即显示跳过按钮
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger skipTime;
|
|
|
|
|
|
|
|
///广告信息
|
|
|
|
@property (nonatomic, strong, readonly) NSArray <DWVodAdMaterialModel *> * ads;
|
|
|
|
```
|
|
|
|
|
|
|
|
广告信息模型DWVodAdMaterialModel属性及含义如下:
|
|
|
|
```
|
|
|
|
///素材id
|
|
|
|
@property (nonatomic, strong, readonly) NSString * materialId;
|
|
|
|
|
|
|
|
///素材链接
|
|
|
|
@property (nonatomic, strong, readonly) NSString * materialUrl;
|
|
|
|
|
|
|
|
///跳转链接
|
|
|
|
@property (nonatomic, strong, readonly) NSString * clickUrl;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.9 VR视频
|
|
|
|
|
|
|
|
### 1.9.1 VR视频的判断
|
|
|
|
DWVodVideoModel对象中的vrmode,代表此视频是否是VR视频。
|
|
|
|
```
|
|
|
|
///是否支持VR 1表示播放VR视频,0表示普通
|
|
|
|
@property (nonatomic, assign, readonly) NSInteger vrmode;
|
|
|
|
```
|
|
|
|
|
|
|
|
### 1.9.2 VR视频的播放
|
|
|
|
VR视频的使用流程如下:
|
|
|
|
```
|
|
|
|
//1.首先,需要创建一个承载VR播放的视图,添加到需要展示的视图上。同时,将DWPlayerView隐藏。
|
|
|
|
self.vrView = [[UIView alloc]init];
|
|
|
|
[self addSubview:self.vrView];
|
|
|
|
self.playerView.hidden = NO;
|
|
|
|
|
|
|
|
//2.创建DWVRConfiguration、DWVRLibrary对象,并关联AVPlayerItem、VRView等属性,即可实现VR视频的播放。
|
|
|
|
self.config = [DWVRLibrary createConfig];
|
|
|
|
//关联AVPlayerItem
|
|
|
|
[_config asVideo:self.playerView.player.currentItem];
|
|
|
|
|
|
|
|
UINavigationController * currentNC = (UINavigationController *)DWAPPDELEGATE.window.rootViewController;
|
|
|
|
UIViewController * preVC = [currentNC.viewControllers objectAtIndex:currentNC.viewControllers.count - 1];
|
|
|
|
//关联VewController、VRView
|
|
|
|
[_config setContainer:preVC view:self.vrView];
|
|
|
|
//可选设置
|
|
|
|
[_config projectionMode:DWModeProjectionSphere];//效果
|
|
|
|
[_config displayMode:_display];//是否分屏
|
|
|
|
[_config interactiveMode:_interative];//交互方式
|
|
|
|
[_config pinchEnabled:true];
|
|
|
|
[_config setDirectorFactory:[[CustomDirectorFactory alloc]init]];
|
|
|
|
//通过DWVRConfiguration创建DWVRLibrary对象
|
|
|
|
self.vrLibrary = [_config build];
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 1.10 GIF录制功能
|
|
|
|
SDK提供DWGIFManager对象,来完成GIF录制。
|
|
|
|
|
|
|
|
DWGIFManager的方法属性及含义如下:
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* 制作完成GIF回调
|
|
|
|
*/
|
|
|
|
@property(nonatomic,copy) CompleteBlock completeBlock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成GIF质量
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign) GIFQuality quality;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GIF播放的次数 0无限循环
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign) NSInteger loopCount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 是否正在录制gif
|
|
|
|
*/
|
|
|
|
@property(nonatomic,readonly) BOOL isRecording;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 关联播放器,startRecordingGif录制开始前调用 !!!在每次startRecordingGif前,都要调用此方法
|
|
|
|
|
|
|
|
* @param playUrl 播放路径
|
|
|
|
* @param currentPlayer 当前播放player
|
|
|
|
* @param m3u8Method 为YES,会强制使用m3u8视频格式截取GIF方式,一般设置为NO即可
|
|
|
|
*/
|
|
|
|
-(void)associationWithUrl:(NSURL *)playUrl CurrentPlayer:(AVPlayer *)currentPlayer AndUseM3U8Method:(BOOL)m3u8Method;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 开始录制gif
|
|
|
|
*/
|
|
|
|
-(void)startRecordingGif;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 结束录制gif 如果视频播放完成,内部会自动调用此方法,完成GIF回调
|
|
|
|
*/
|
|
|
|
-(void)endRecordingGif;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 取消录制gif
|
|
|
|
*/
|
|
|
|
-(void)cancelRecordGif;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 1.11 访客信息收集
|
|
|
|
访客信息收集数据为DWVodVideoModel对象的visitor。
|
|
|
|
|
|
|
|
DWVideoVisitorModel数据及含义如下:
|
|
|
|
```
|
|
|
|
///收集器ID
|
|
|
|
@property (nonatomic, strong, readonly)NSString * visitorId;
|
|
|
|
|
|
|
|
///收集器标题
|
|
|
|
@property (nonatomic, strong, readonly)NSString * title;
|
|
|
|
|
|
|
|
///展现的时间,单位:秒
|
|
|
|
@property (nonatomic, assign, readonly)NSInteger appearTime;
|
|
|
|
|
|
|
|
///展现的图片地址
|
|
|
|
@property (nonatomic, strong, readonly)NSString * imageURL;
|
|
|
|
|
|
|
|
///图片的跳转地址
|
|
|
|
@property (nonatomic, strong, readonly)NSString * jumpURL;
|
|
|
|
|
|
|
|
///能否跳过
|
|
|
|
@property (nonatomic, assign, readonly)BOOL isJump;
|
|
|
|
|
|
|
|
///要收集的信息
|
|
|
|
@property (nonatomic, strong, readonly)NSArray <DWVideoVisitorMessageModel *> * visitorMessages;
|
|
|
|
|
|
|
|
///是否显示问答
|
|
|
|
@property (nonatomic, assign) BOOL isShow;
|
|
|
|
```
|
|
|
|
|
|
|
|
DWVideoVisitorMessageModel数据及含义如下:
|
|
|
|
```
|
|
|
|
///收集信息含义
|
|
|
|
@property (nonatomic, strong, readonly)NSString * visitorMes;
|
|
|
|
|
|
|
|
///收集信息提示
|
|
|
|
@property (nonatomic, strong, readonly)NSString * visitorTip;
|
|
|
|
```
|
|
|
|
|
|
|
|
# 2.下载功能
|
|
|
|
|
|
|
|
## 2.1 下载功能的快速集成,请详见2.集成指南
|
|
|
|
|
|
|
|
## 2.2 DWDownloadSessionManager的使用。
|
|
|
|
DWDownloadSessionManager是下载管理类,所有有关下载的操作,都是通过此对象来进行的。可根据自己的业务逻辑,来自行修改下载相关的设置。
|
|
|
|
|
|
|
|
以下是具体的属性及方法:
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
下载任务队列
|
|
|
|
*/
|
|
|
|
@property(nonatomic,strong,readonly) NSArray <DWDownloadModel *> * downloadModelList;
|
|
|
|
|
|
|
|
/**
|
|
|
|
代理
|
|
|
|
*/
|
|
|
|
@property(nonatomic,weak) id<DWDownloadSessionDelegate> delegate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
注意:修改下载设置后,对已经存在的下载任务可能无效,请清空下载任务之后修改设置
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
是否允许使用移动流量 YES支持 NO不支持 默认支持
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)BOOL allowsCellular;
|
|
|
|
|
|
|
|
/**
|
|
|
|
全部并发 默认YES, 当YES时,忽略maxDownloadCount
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)BOOL isBatchDownload;
|
|
|
|
|
|
|
|
/**
|
|
|
|
允许同时下载的最大并发数,默认为1,最大为4
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)NSInteger maxDownloadCount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
等待下载队列 先进先出 默认YES, 当NO时,先进后出
|
|
|
|
*/
|
|
|
|
@property(nonatomic,assign)BOOL resumeDownloadFIFO;
|
|
|
|
|
|
|
|
/**
|
|
|
|
初始化DWDownloadSessionManager
|
|
|
|
@return DWDownloadSessionManager对象
|
|
|
|
*/
|
|
|
|
+(DWDownloadSessionManager *)manager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
配置后台session
|
|
|
|
*/
|
|
|
|
-(void)configureBackroundSession;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化DWDownloadModel
|
|
|
|
@param videoMdoel 点播视频model 非空
|
|
|
|
@param quality 媒体品质 非空
|
|
|
|
@param othersInfo 自定义字段 可为空
|
|
|
|
@return 创建成功返回DWDownloadModel对象,如果失败,返回nil
|
|
|
|
*/
|
|
|
|
+(DWDownloadModel *)createDownloadModel:(DWVodVideoModel *)videoMdoel Quality:(NSString *)quality AndOthersInfo:(NSDictionary * _Nullable )othersInfo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
开始下载任务
|
|
|
|
@param downloadModel DWDownloadModel对象
|
|
|
|
*/
|
|
|
|
-(void)startWithDownloadModel:(DWDownloadModel *)downloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
开始下载任务 ,所有回调均已回到主线程中
|
|
|
|
@param downloadModel DWDownloadModel对象
|
|
|
|
@param progress 下载进度回调
|
|
|
|
@param state 下载状态变动回调
|
|
|
|
*/
|
|
|
|
-(void)startWithDownloadModel:(DWDownloadModel *)downloadModel progress:(DWDownloadProgressBlock)progress state:(DWDownloadStateBlock)state;
|
|
|
|
|
|
|
|
/**
|
|
|
|
暂停下载任务
|
|
|
|
@param downloadModel DWDownloadModel对象
|
|
|
|
*/
|
|
|
|
-(void)suspendWithDownloadModel:(DWDownloadModel *)downloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
恢复下载任务
|
|
|
|
@param downloadModel DWDownloadModel对象
|
|
|
|
*/
|
|
|
|
-(void)resumeWithDownloadModel:(DWDownloadModel *)downloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
删除下载任务以及本地缓存
|
|
|
|
@param downloadModel DWDownloadModel对象
|
|
|
|
*/
|
|
|
|
-(void)deleteWithDownloadModel:(DWDownloadModel *)downloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
删除全部任务
|
|
|
|
*/
|
|
|
|
-(void)deleteAllDownloadModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
获取下载模型
|
|
|
|
@param URLString 下载地址
|
|
|
|
@return DWDownloadModel对象
|
|
|
|
*/
|
|
|
|
- (DWDownloadModel *)downLoadingModelForURLString:(NSString *)URLString;
|
|
|
|
|
|
|
|
/**
|
|
|
|
判断当前资源是已在下载队列中
|
|
|
|
@param videoId 视频id 非空
|
|
|
|
@param quality 媒体品质 非空
|
|
|
|
@return YES 已存在 NO 未存在
|
|
|
|
*/
|
|
|
|
-(BOOL)checkLocalResourceWithVideoId:(NSString *)videoId WithQuality:(NSString *)quality;
|
|
|
|
|
|
|
|
/**
|
|
|
|
判断downloadModel下载链接是否有效
|
|
|
|
@param downloadModel DWDownloadModel对象
|
|
|
|
@return YES有效 NO无效,需重新获取下载链接
|
|
|
|
*/
|
|
|
|
-(BOOL)isValidateURLWithDownloadModel:(DWDownloadModel *)downloadModel;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
根据新的下载地址,继续下载此任务
|
|
|
|
@param newUrlString 新的下载地址
|
|
|
|
@param downloadModel 需要修改的downloadModel
|
|
|
|
*/
|
|
|
|
-(void)reStartDownloadUrlWithNewUrlString:(NSString *)newUrlString AndDownloadModel:(DWDownloadModel *)downloadModel;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
获取appdelegate,handleEventsForBackgroundURLSession事件回调
|
|
|
|
@param completionHandler completionHandler
|
|
|
|
*/
|
|
|
|
-(void)setBackgroundSessionCompletionHandler:(void (^)())completionHandler;
|
|
|
|
|
|
|
|
//3.x.x升级4.x.x以上版本所使用的过渡方法
|
|
|
|
/**
|
|
|
|
若从3.x.x版本升级到4.x.x,会出现旧版本下载的音视频文件找不到的情况。
|
|
|
|
可以通过执行此方法,生成新版SDk的下载任务。
|
|
|
|
|
|
|
|
@param loaclPath 对于已完成的任务,必填。对于未完成的任务,请务必传nil
|
|
|
|
@param downloadUrl 网络下载地址。对于未完成的任务,必填
|
|
|
|
@param mediaType 文件类型 1 视频 2 音频。 若不填写,默认视频
|
|
|
|
@param quality 清晰度。 若不填写,默认 10
|
|
|
|
@param desp 清晰度描述。 若不填写,默认 标清
|
|
|
|
@param vrMode 是否是VR视频。 默认
|
|
|
|
@param othersInfo 自定义字段 根据自己需求适当添加,比如添加媒体图片,标题等。
|
|
|
|
@param userId 用户ID。 选填
|
|
|
|
@param videoId 视频ID。 选填
|
|
|
|
@param totalBytesWritten 已下载的数量。对于未完成的任务,必填
|
|
|
|
@param totalBytesExpectedToWrite 文件的总大小。对于未完成的任务,必填
|
|
|
|
@return 若过渡成功,返回DWDownloadModel对象,否则返回nil
|
|
|
|
*/
|
|
|
|
-(DWDownloadModel *)migrateDownloadTask:(NSString *)loaclPath
|
|
|
|
DownloadUrl:(NSString *)downloadUrl
|
|
|
|
MediaType:(NSString *)mediaType
|
|
|
|
Quality:(NSString *)quality
|
|
|
|
Desp:(NSString *)desp
|
|
|
|
VRMode:(BOOL)vrMode
|
|
|
|
OthersInfo:(NSDictionary *)othersInfo
|
|
|
|
UserId:(NSString *)userId
|
|
|
|
VideoId:(NSString *)videoId
|
|
|
|
TotalBytesWritten:(int64_t)totalBytesWritten TotalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 2.3 下载功能的回调
|
|
|
|
DWDownloadSessionManagerDelegate,方法说明如下:
|
|
|
|
```
|
|
|
|
// 更新下载进度
|
|
|
|
- (void)downloadModel:(DWDownloadModel *)downloadModel didUpdateProgress:(DWDownloadProgress *)progress;
|
|
|
|
|
|
|
|
// 更新下载状态
|
|
|
|
- (void)downloadModel:(DWDownloadModel *)downloadModel error:(NSError *)error;
|
|
|
|
|
|
|
|
// 后台下载完成时回调
|
|
|
|
- (void)backgroundSessionCompletion;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 2.4 DWDownloadModel数据模型的使用
|
|
|
|
DWDownloadModel对象对应具体的下载任务。
|
|
|
|
|
|
|
|
以下是具体DWDownloadModel中,包含的字段及含义:
|
|
|
|
```
|
|
|
|
/// 下载地址
|
|
|
|
@property (nonatomic, strong, readonly) NSString * downloadURL;
|
|
|
|
|
|
|
|
/// 文件名 默认nil 则为下载URL中的文件名
|
|
|
|
@property (nonatomic, strong, readonly) NSString * fileName;
|
|
|
|
|
|
|
|
/// 存储路径
|
|
|
|
@property (nonatomic, strong, readonly) NSString * filePath;
|
|
|
|
|
|
|
|
/// 下载状态
|
|
|
|
@property (nonatomic, assign, readonly) DWDownloadState state;
|
|
|
|
|
|
|
|
/// 文件类型 1 视频 2 音频
|
|
|
|
@property (nonatomic, strong, readonly) NSString * mediaType;
|
|
|
|
|
|
|
|
/// 文件后缀名
|
|
|
|
@property (nonatomic ,strong, readonly) NSString * mimeType;
|
|
|
|
|
|
|
|
/// 清晰度
|
|
|
|
@property (nonatomic, strong, readonly) NSString * quality;
|
|
|
|
|
|
|
|
/// 清晰度描述
|
|
|
|
@property (nonatomic, strong, readonly) NSString * desp;
|
|
|
|
|
|
|
|
/// VR视频
|
|
|
|
@property (nonatomic, assign, readonly) BOOL vrMode;
|
|
|
|
|
|
|
|
/// URL失效后的断点续传需要设置这个数据
|
|
|
|
@property (nonatomic, strong, readonly) NSData * resumeData;
|
|
|
|
|
|
|
|
///userId
|
|
|
|
@property (nonatomic, strong, readonly)NSString * userId;
|
|
|
|
|
|
|
|
//videoId
|
|
|
|
@property (nonatomic, strong, readonly)NSString * videoId;
|
|
|
|
|
|
|
|
/// 自定义字段 根据自己需求适当添加,比如添加媒体图片,标题等
|
|
|
|
@property (nonatomic, strong) NSDictionary * othersInfo;
|
|
|
|
|
|
|
|
/// 非点播业务不需要关注此值 解压状态 0 未解压 1 解压中 2 解压完成 3 解压失败
|
|
|
|
@property (nonatomic, assign) NSInteger decompressionState;
|
|
|
|
|
|
|
|
/// 下载进度
|
|
|
|
@property (nonatomic, strong ,readonly) DWDownloadProgress *progress;
|
|
|
|
|
|
|
|
/// 下载进度更新block
|
|
|
|
@property (nonatomic, copy) DWDownloadProgressBlock progressBlock;
|
|
|
|
/// 下载状态更新block
|
|
|
|
@property (nonatomic, copy) DWDownloadStateBlock stateBlock;
|
|
|
|
```
|
|
|
|
|
|
|
|
以下是具体DWDownloadProgress中,包含的字段及含义:
|
|
|
|
```
|
|
|
|
/// 续传大小
|
|
|
|
@property (nonatomic, assign, readonly) int64_t resumeBytesWritten;
|
|
|
|
|
|
|
|
/// 这次写入的数量
|
|
|
|
@property (nonatomic, assign, readonly) int64_t bytesWritten;
|
|
|
|
|
|
|
|
/// 已下载的数量
|
|
|
|
@property (nonatomic, assign, readonly) int64_t totalBytesWritten;
|
|
|
|
|
|
|
|
/// 文件的总大小
|
|
|
|
@property (nonatomic, assign, readonly) int64_t totalBytesExpectedToWrite;
|
|
|
|
|
|
|
|
/// 下载进度
|
|
|
|
@property (nonatomic, assign, readonly) float progress;
|
|
|
|
|
|
|
|
/// 下载速度
|
|
|
|
@property (nonatomic, assign, readonly) float speed;
|
|
|
|
|
|
|
|
/// 下载剩余时间
|
|
|
|
@property (nonatomic, assign, readonly) int remainingTime;
|
|
|
|
```
|
|
|
|
|
|
|
|
## 2.5 批量下载功能
|
|
|
|
通过创建DWBatchDownloadUtility对象,来批量获取DWVodVideoModel对象,进行下载。
|
|
|
|
|
|
|
|
具体数据及相关方法如下:
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
1为视频 2为音频 0为视频+音频 若不传该参数默认为视频
|
|
|
|
*/
|
|
|
|
@property (nonatomic,copy)NSString *mediatype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
授权验证码,需要的话请设置,默认为空
|
|
|
|
*/
|
|
|
|
@property (nonatomic,copy)NSString *verificationCode;
|
|
|
|
|
|
|
|
//注意! 回调方法可能不在主线程中,如果在里面进行UI操作,请回到主线程中进行
|
|
|
|
/**
|
|
|
|
全部视频数据获取出错
|
|
|
|
*/
|
|
|
|
@property (nonatomic,copy)BatchDownloadUtilityErrorBlock errorBlock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
视频数据获取完成
|
|
|
|
*/
|
|
|
|
@property (nonatomic,copy)BatchDownloadUtilityFinishBlock finishBlock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化 会对视频数据进行去重操作,如果传入数组中有重复的视频id或获取某个视频失败,可能会导致最后输出的视频数据长度跟传入的视频id的数量不一致
|
|
|
|
* @param userId 用户ID,不能为nil
|
|
|
|
* @param key 用户秘钥,不能为nil
|
|
|
|
* @param videoIds 视频id数组,不能为nil 最多同时获取10个视频id的播放地址,超出10个按10个获取
|
|
|
|
*/
|
|
|
|
-(instancetype)initWithUserId:(NSString *)userId key:(NSString *)key AndVideoIds:(NSArray *)videoIds;
|
|
|
|
|
|
|
|
/**
|
|
|
|
开始获取批量下载数据
|
|
|
|
*/
|
|
|
|
-(void)start;
|
|
|
|
```
|
|
|
|
|
|
|
|
# 3.上传功能
|
|
|
|
|
|
|
|
## 3.1 上传功能的使用
|
|
|
|
初始化DWUploader对象,调用start方法,即可开始上传视频。
|
|
|
|
|
|
|
|
```
|
|
|
|
//videoTitle不得为空 videoPath音视频文件路径
|
|
|
|
DWUploader *uploader = [[DWUploader alloc] initWithuserId:@"账号ID"
|
|
|
|
andKey:@"APIKey"
|
|
|
|
uploadVideoTitle:@"视频标题"
|
|
|
|
videoDescription:@"视频描述"
|
|
|
|
videoTag:@"视频tag"
|
|
|
|
videoPath:@"视频本地路径"
|
|
|
|
notifyURL:@"回调地址"];
|
|
|
|
|
|
|
|
//开始上传
|
|
|
|
[uploader start];
|
|
|
|
```
|
|
|
|
|
|
|
|
## 3.2 上传功能的回调及方法
|
|
|
|
|
|
|
|
如下:
|
|
|
|
```
|
|
|
|
typedef void (^DWUploaderFinishBlock)();
|
|
|
|
typedef void (^DWErrorBlock)(NSError *error);
|
|
|
|
typedef void (^DWUploaderVideoContextForRetryBlock)(NSDictionary *videoContext);
|
|
|
|
typedef void (^DWUploaderProgressBlock)(float progress, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 在该block获取上传进度,可以在block内更新UI,如更新上传进度条。
|
|
|
|
*/
|
|
|
|
@property (copy, nonatomic)DWUploaderProgressBlock progressBlock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 上传完成时回调该block,可以在block内更新UI,如将视频标记为上传完成。
|
|
|
|
*/
|
|
|
|
@property (copy, nonatomic)DWUploaderFinishBlock finishBlock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 上传失败时回调该block,可以在该block内更新UI,如将视频标记为上传失败。
|
|
|
|
*/
|
|
|
|
@property (copy, nonatomic)DWErrorBlock failBlock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 在该block内获取上传上下文,并保存上传上下文,用来实现断线续传。
|
|
|
|
*/
|
|
|
|
@property (copy, nonatomic)DWUploaderVideoContextForRetryBlock videoContextForRetryBlock;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 当遇到网络问题或服务器原因时上传暂停,回调该block。
|
|
|
|
*/
|
|
|
|
@property (copy, nonatomic)DWErrorBlock pausedBlock;
|
|
|
|
|
|
|
|
/*
|
|
|
|
*第一次请求成功后保存信息 发生异常后如果能获取到此信息 则调用initWithVideoContext:方法做断点续传
|
|
|
|
*/
|
|
|
|
@protocol DWUploaderDelegate <NSObject>
|
|
|
|
@optional
|
|
|
|
//第一次请求成功的回调
|
|
|
|
- (void)checkUploadWithFilePath:(NSString *)filePath;
|
|
|
|
@end
|
|
|
|
|
|
|
|
/**
|
|
|
|
文件路径
|
|
|
|
*/
|
|
|
|
@property (nonatomic,copy,readonly)NSString *videoPath;
|
|
|
|
|
|
|
|
/**
|
|
|
|
开始上传
|
|
|
|
*/
|
|
|
|
- (void)start;
|
|
|
|
|
|
|
|
/**
|
|
|
|
暂停上传
|
|
|
|
*/
|
|
|
|
- (void)pause;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
继续上传
|
|
|
|
*/
|
|
|
|
- (void)resume;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
分类上传
|
|
|
|
@param categoryId 分类
|
|
|
|
*/
|
|
|
|
- (void)category:(NSString *)categoryId;
|
|
|
|
```
|
|
|
|
|
|
|
|
注意事项:通常情况下,不可对同一视频多次使用第一种初始化方式初始化上传,这样会造成大量重复视频,增加你后期管理视频的同事的工作量,且CC视频会根据你的付费套餐对每天的上传次数有不同的限制,超过最大上传次数,当天便无法上传视频。
|
|
|
|
|
|
|
|
## 4.Demo的注意事项
|
|
|
|
Demo是使用SDK对接CC视频云的示例源码,Demo的设计旨在展示SDK各项功能的使用方法,Demo中的逻辑仅供参考,如果希望应用获得更好的使用体验,请根据自己的需求更改。
|
|
|
|
|
|
|
|
注意:仅可默认体验播放、下载相关的功能,若需进行上传功能的测试,请查看4.3。
|
|
|
|
|
|
|
|
### 4.1 默认播放列表
|
|
|
|
我们提供了一些视频数据,用户在运行demo以后,无需进行额外的设置,即可体验我们SDK的功能。
|
|
|
|
|
|
|
|
### 4.2 自定义播放列表
|
|
|
|
若默认播放列表不能满足需求,可通过修改网络请求或者使用本地数据的方式来修改播放列表。具体修改方式如下。
|
|
|
|
|
|
|
|
#### 4.2.1 修改userId和APIKey
|
|
|
|
无论是通过哪种方式来修改播放列表,首先,都需要修改demo中的userId跟APIKey。请找到DWConfigurationManager.m文件,修改DWAccount_userId,DWAccount_apikey属性值即可。例:
|
|
|
|
```
|
|
|
|
self.DWAccount_userId = @"****************";
|
|
|
|
self.DWAccount_apikey = @"********************************";
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 4.2.2 网络数据获取播放列表
|
|
|
|
用户可通过修改demo中网络请求URL的方式,来修改播放列表中的数据。
|
|
|
|
```
|
|
|
|
//第一步 找到DWMainViewController.m 中的VIDEOINFOURL,并修改URL。
|
|
|
|
#define VIDEOINFOURL @"https://****************"
|
|
|
|
|
|
|
|
//第二步 reloadNetworkData方法中,根据修改的URL获取数据,进行解析,赋值即可。
|
|
|
|
-(void)reloadNetworkData
|
|
|
|
{
|
|
|
|
NSURLSession * session = [NSURLSession sharedSession];
|
|
|
|
NSURL * url = [NSURL URLWithString:VIDEOINFOURL];
|
|
|
|
|
|
|
|
NSURLSessionDataTask * task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//根据接口,解析出需要使用的video数据数组。
|
|
|
|
NSArray * vodList = ...
|
|
|
|
//这里根据返回数据,自行对DWVodModel对象赋值即可。
|
|
|
|
for (NSDictionary * vodDict in vodList) {
|
|
|
|
DWVodModel * vodModel = [[DWVodModel alloc]init];
|
|
|
|
vodModel.videoId = @"视频ID";
|
|
|
|
vodModel.title = @"视频标题";
|
|
|
|
vodModel.time = @"视频时长";
|
|
|
|
vodModel.imageUrl = @"图片地址";
|
|
|
|
[self.videoList addObject:vodModel];
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
DWVodModel * vodModel = self.videoList.firstObject;
|
|
|
|
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:vodModel.imageUrl] placeholderImage:[UIImage imageNamed:@"icon_placeholder.png"]];
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
});
|
|
|
|
}];
|
|
|
|
|
|
|
|
[task resume];
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 4.2.3 本地数据获取播放列表
|
|
|
|
用户也可不通过网络请求,通过修改本地数据来修改播放列表。
|
|
|
|
|
|
|
|
```
|
|
|
|
若需要替换自己的VideoId,请在DWMainViewController.m中,注释掉网络请求的方法,并在reloadLoaclData方法中,自行填写的videoId,以及需要的展示数据即可。
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
// [self reloadNetworkData];
|
|
|
|
[self reloadLoaclData];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)reloadLoaclData
|
|
|
|
{
|
|
|
|
//请自行替换数据
|
|
|
|
NSArray * videos = @[@"********************************",@"********************************",...];
|
|
|
|
for (int i = 0; i < videos.count; i++) {
|
|
|
|
DWVodModel * vodModel = [[DWVodModel alloc]init];
|
|
|
|
vodModel.videoId = [videos objectAtIndex:i];
|
|
|
|
vodModel.title = @"展示title";
|
|
|
|
vodModel.time = @"展示time";
|
|
|
|
vodModel.imageUrl = @"展示图片地址";
|
|
|
|
[self.videoList addObject:vodModel];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 4.3 上传功能的使用
|
|
|
|
demo中提供的默认账号并无上传功能,若需体验SDK中的上传功能,请在选择完视频之后,填写账号下的userId,以及APIKey等信息,才能使用demo中的上传功能。
|
|
|
|
|
|
|
|
## 5.调试与反馈
|
|
|
|
|
|
|
|
### 5.1 SDK错误码
|
|
|
|
以下是错误码的详细说明:
|
|
|
|
|
|
|
|
枚举|code|详细描述
|
|
|
|
--|:--|:--
|
|
|
|
ERROR_INFO_NOTMATCH|1000|视频参数错误
|
|
|
|
ERROR_VIDEO_UNAVAILABLE|1001|视频不可用
|
|
|
|
ERROR_VIDEO_PROCESSING|1002|视频处理中
|
|
|
|
ERROR_VIDEO_DELETE|1003|视频已删除
|
|
|
|
ERROR_VIDEO_TRANFAILURE|1004|视频转码失败
|
|
|
|
ERROR_REQUEST_FAILURE|1005|网络请求失败
|
|
|
|
ERROR_VIDEO_ANALYSIS|1006|PlayInfo数据解析失败
|
|
|
|
ERROR_VIDEO_UNKNOW|1007|未知错误
|
|
|
|
ERROR_PLAYERSKIN_VIDEOUNAVAILABLE|1201|视频资源不存在
|
|
|
|
ERROR_PLAYERSKIN_LOCALUNAVAILABLE|1202|离线资源不存在
|
|
|
|
ERROR_PLAYERSKIN_DISABLEAUTOROTATE|1203|禁止手动旋转
|
|
|
|
ERROR_PLAYERSKIN_BUFFEREMPTY|1204|暂无缓冲数据
|
|
|
|
ERROR_PLAYERSKIN_BUFFERTIMEOUT|1205|缓冲超时
|
|
|
|
ERROR_PLAYERSKIN_LOADTIMEOUT|1206|加载超时
|
|
|
|
ERROR_AFINFO_NOTMATCH|1301|广告参数错误
|
|
|
|
ERROR_AFINFO_NOTSERVING|1302|该用户未投放广告
|
|
|
|
ERROR_AFINFO_TYPENOTEXIST|1303|该用户无type对应类型的广告位
|
|
|
|
ERROR_AFINFO_NOTAD|1304|该用户type类型下无广告
|
|
|
|
ERROR_AFINFO_DATA|1305|数据查询异常
|
|
|
|
ERROR_AFINFO_ANALYSIS|1306|广告数据解析失败
|
|
|
|
ERROR_PLAYER_CREATE|2000|播放器创建失败
|
|
|
|
ERROR_VIDEO_PLAYERROR|2001|播放失败
|
|
|
|
ERROR_QUALITY_NOTEXIST|2002|未查找到清晰度
|
|
|
|
ERROR_LOCAL_UNAVAILABLE|2003|本地资源不可用
|
|
|
|
ERROR_PLAYURL_UNAVAILABLE|2010|播放地址不可用/不存在
|
|
|
|
ERROR_GIF_UNASSOCIATION|2100|GIF未关联播放器
|
|
|
|
ERROR_DOWNLOAD_UNAVAILABLE|3000|网络资源不存在
|
|
|
|
ERROR_DOWNLOAD_UNAUTHORIZED|3001|未获得下载授权
|
|
|
|
ERROR_DOWNLOAD_UNSUPPORTM3U8|3002|暂不支持m3u8视频格式下载
|
|
|
|
ERROR_DOWNLOAD_MOVEFILE|3077|下载完成移动文件失败
|
|
|
|
ERROR_BATCHDOWNLOAD_NOTMATCH|3100|批量下载参数有误
|
|
|
|
ERROR_UPLOAD_NOTMATCH|4000|上传参数错误
|
|
|
|
ERROR_UPLOAD_NOTENOUGHSPACE|4001|用户剩余空间不足
|
|
|
|
ERROR_UPLOAD_SERVICEEXPIRED|4002|用户服务终止
|
|
|
|
ERROR_UPLOAD_PROCESSFAIL|4003|服务器处理错误
|
|
|
|
ERROR_UPLOAD_FREQUENTACCESS|4004|访问过于频繁
|
|
|
|
ERROR_UPLOAD_NOTPERMISSION|4005|用户服务无权限
|
|
|
|
ERROR_UPLOAD_FAIL|4100|上传失败
|
|
|
|
ERROR_UPLOAD_ANALYSIS|4150|上传数据解析失败
|
|
|
|
|
|
|
|
|
|
|
|
### 5.2 通信日志的使用
|
|
|
|
SDK提供了DWLog模块用来打印HTTP通信日志,可以在App的任意位置开启或关闭打印HTTP通信日志等功能。下面是DWLog的使用方法:
|
|
|
|
```
|
|
|
|
// 开启 打印HTTP通信日志 功能
|
|
|
|
[DWLog setIsDebugHttpLog:YES];
|
|
|
|
// 关闭 打印HTTP通信日志 功能
|
|
|
|
[DWLog setIsDebugHttpLog:NO];
|
|
|
|
``` |
|
|
|
\ No newline at end of file |