北京中投视讯 iOS播放SDK2.1.7
一. 产品概述
CNLiveMoviePlayerController是视讯云推出的iOS平台上使用的软件开发工具包(SDK),为开发者提供简单快捷的接口,帮助开发者实现在各个平台上的多媒体播放应用。
二. 版本更新说明
-
2017.11.01(版本号:2.1.7)
1、新增预缓存和边播边缓存功能(目前只支持MP4格式);
-
2017.7.25(版本号:2.1.6)
1、新增了静音,循环播放,旋转等方法;
-
2017.6.19(版本号:2.1.4)
1、修改了初始化直播核心类方法; 2、SDK内部时间戳处理 3、新增用活动ID播放视频接口;
-
2017.5.27(版本号:2.1.3)
1、新增网络状态通知;
-
2017.5.27(版本号:2.1.1)
1、SDK内部修改了鉴权方式;
-
2017.4.12(版本号:2.0.9)
1、更新SDK内部探针;
-
2017.03.07(版本号:2.0.7)
1、修改直播云初始化方法; 2、新增直播中主播状态通知及相关方法; 3、新开放超时时间(建立连接超时时间和拉流超时时间);
-
2016.12.09(版本号:2.0.5)
1、增加控制台日志输出的开关; 2、修复播放器未完全释放导致崩溃的问题;
-
2016.12.08(版本号:2.0.4)
1、修复点播播放失败问题;
三.SDK功能特性
- 支持软硬解;
- 支持直播、点播播放;直播过程中能够防止延迟过大;
- 直播过程中实时监测主播状态;
- 重连:可以实现不销毁播放器情况下重新拉流;
- 可调节音量:调节播放器音对其他APP音量和系统音量没有影响;
- 截图:获取任何时刻视频图像;
- 支持预缓存和边播边缓存功能;
四.系统要求
- 最低支持iOS版本:iOS 8.0
- 支持的CPU架构:armv7,arm64,x86_64
五.集成方式
- 下载直播工具SDK,直播和推流融合版SDK
- 导入SDK
由于是动态库,再使用的时候需要把Framework 同时添加到‘Embedded Binaries’中。
- 导入资源库 CNLivePlayerBundle.bundle
- 引入头文件
#import <CNLivePlayerSDK/CNLiveMoviePlayerController.h>
#import <CNLivePlayerSDK/CNLiveWebcastManager.h>
注意: 提交APP到App Store 时请用发布版SDK。
六.SDK基本使用
视讯云平台
- 初始化直播云SDK
/**
@abstract 初始化直播云SDK
@param appId 在open.cnlive.com网站申请得到的 appId
@param appKey 在open.cnlive.com网站申请得到的 appKey
@warning 必传参数
*/
- (void)initWithAppId:(NSString *)appId appKey:(NSString *)appKey;
代码示例:
`[[CNLiveWebcastManager manager] initWithAppId:KAppId appKey:KAppKey];`
初始化播放器
初始化点播播放器
/* 初始化点播播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
*
* 当前版本只支持单实例的CNLiveMoviePlayerController对象,多实例将导致播放异常
*
* vId 点播视频Id
* authSuccess 初始化成功block
* authFailed 初始化失败block 回调一个errorInfo的字典
*
*/
- (instancetype)initVodPlayWithVId:(NSString *)vId
authSuccess:(void(^)(void))authSuccessBlock
authFailed:(void(^)(NSDictionary *errorInfo))authFailedBlock;
在authSuccessBlock回调中可以对播放器配置相关参数。
注意: 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay);
-
初始化直播播放器
用channelId播放:
/* 初始化直播播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
*
* 当前版本只支持单实例的CNLiveMoviePlayerController对象,多实例将导致播放异常
*
* channelId 直播视频Id
* agree 是否允许获取主播状态 YES:获取 NO:不获取
* authSuccess 初始化成功block
* authFailed 初始化失败block 回调一个errorInfo的字典
*
* result 获取主播状态 YES:获取状态成功
* NO:获取失败,不影响视频播放,但是获取不到主播离开、回来、直播结束等通知。可通过
* - (void)retryToGetAnchorStatusResult:(void(^)(BOOL result))result;方法重新获取
*/
- (instancetype)initLivePlayWithChannelId:(NSString *)channelId
anchorStatus:(BOOL)agree
authSuccess:(void(^)(void))authSuccessBlock
authFailed:(void(^)(NSDictionary *errorInfo))authFailedBlock
getAnchorStatusResult:(void(^)(BOOL result))result;
用activityId播放:
/* 初始化直播播放器(* 以channelId播放) 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
*
* 当前版本只支持单实例的CNLiveMoviePlayerController对象,多实例将导致播放异常
*
* channelId 直播视频Id (注* 若agree为YES时,必传,用于获取主播状态; 若agree为NO,可不传)
* activityId 活动Id
* agree 是否允许获取主播状态 YES:获取 NO:不获取
* authSuccess 初始化成功block
* authFailed 初始化失败block 回调一个errorInfo的字典
*
* result 获取主播状态 YES:获取状态成功
* NO:获取失败,不影响视频播放,但是获取不到主播离开、回来、直播结束等通知。可通过
* - (void)retryToGetAnchorStatusResult:(void(^)(BOOL result))result;方法重新获取
*/
- (instancetype)initLivePlayWithChannelId:(NSString *)channelId
activityId:(NSString *)activityId
anchorStatus:(BOOL)agree
authSuccess:(void(^)(void))authSuccessBlock
authFailed:(void(^)(NSDictionary *errorInfo))authFailedBlock
getAnchorStatusResult:(void(^)(BOOL result))result;
- 是否开启控制台输出日志
/*
* 是否开启控制台输出日志(默认YES)
*/
@property (nonatomic, assign) BOOL logPrintEnable;
- 切换视角和码率
/* 切换视角和码率
*
* 调用此方法会获取视频的不同视角或码率,并重新加载视频(获取视频的不同视角或码率需要一定的时间,在这段时间内,播放器不会停止播放,建议将播放器设为暂停状态(pause),并展示加载视频时的UI)
*
* channelId 直播视频Id(同一视角可不传)
* rate 清晰度(1:流畅、2:标清(默认)、3:高清、4:超清)
*
*/
- (void)changeViewWithChannelId:(NSString *)channelId rate:(NSString *)rate;
- 切换视频源
/* 切换视频源
*
* 当视频不够流畅时可调用此方法
* 调用此方法会获取不同的视频源,并重新加载视频(获取其他视频源需要一定的时间,在这段时间内,播放器不会停止播放,建议将播放器设为暂停状态(pause),并展示加载视频时的UI)
*
*/
- (void)retry;
主播直播状态
-
获取主播直播状态
若初始化直播播放器方法result 返回NO,表示主播状态连接失败,不影响播放器正常播放,但无法实时监听主播离开等状态,可通过重新连接获取。
/* 重新获取主播直播状态
*
* result 重新获取主播直播状态,YES:成功 NO:失败
*
*/
- (void)retryToGetAnchorStatusResult:(void(^)(BOOL result))result;
-
主播直播状态和消息通知
主播直播状态:
@property (nonatomic, assign, readonly) CNLiveAnchorStatus anchorStatus;主播直播状态说明:
| 状态名称 | 说明 |
|---|---|
| CNLiveAnchorStatusLiving | 主播直播中 |
| CNLiveAnchorStatusLeaving | 主播已离开 |
| CNLiveAnchorStatusEnd | 直播已结束 |
- 注册通知:
//获取主播状态通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(anchorStatusChanged:)
name:CNLiveAnchorStatusChangedNotification
object:nil];
当收到主播状态变化的通知,可通过_player. anchorStatus获取主播的状态。
代码示例:
- (void)anchorStatusChanged:(NSNotification *)notification
{
if (_player.anchorStatus == 0) {
[self toastMessage:@"主播回来了"];
} else if (_player.anchorStatus == 1) {
[self toastMessage:@"主播已离开"];
} else {
[self toastMessage:@"直播已结束"];
}
}
移除通知:
[[NSNotificationCenter defaultCenter] removeObserver:self name: CNLiveAnchorStatusChangedNotification
object:nil];
普通播放方法
- 初始化普通播放器
/*
* 初始化播放器并设置播放地址
*/
- (instancetype)initWithContentURL:(NSURL *)url;
- 解码方式
/* 解码方式(硬解/软解/自动)
*
* 建议系统版本高于8.0 选择硬解,或者自动选择解码方式,8.0以上的系统优先选择硬解
* 只在[prepareToPlay]调用前设置生效
*
*/
@property(nonatomic) CNLiveMovieVideoDecoderMode videoDecoderMode;
| 名称 | 说明 |
|---|---|
| CNLiveMovieVideoDecoderMode_Software | 软解 |
| CNLiveMovieVideoDecoderMode_Hardware | 硬解 |
| CNLiveMovieVideoDecoderMode_AUTO | 自动选择解码方式,8.0以上的系统优先选择硬解 |
- 重新启动拉流
/* 重新启动拉流
*
* url 视频播放地址,该地址可以是本地地址或者服务器地址.如果为nil,则使用前一次播放地址
*
*/
- (void)reload:(NSURL *)aUrl;
- 设置超时时间
/**
* timeout指定拉流超时时间,单位是秒
* prepareTimeout 建立链接超时时间,默认值是10秒
* readTimeout 拉流超时时间,默认值是30秒
*/
- (void)setTimeout:(int)prepareTimeout readTimeout:(int)readTimeout;
- 自动播放
/*
* 播放视频时是否需要自动播放,默认值为YES
*/
@property (nonatomic) BOOL shouldAutoplay;
- 准备视频播放
/* 准备视频播放
*
* MPMediaPlaybackIsPreparedToPlayDidChangeNotification, 播放器完成对视频文件的初始化时发送通知
*
*/
- (void)prepareToPlay;
- 查询视频准备是否完成
@property(nonatomic, readonly) BOOL isPreparedToPlay;
注意: 只读
播放/暂停/停止
- 播放当前视频:
- (void)play;
- 暂停:
- (void)pause;
播放器内部监听了UIApplicationWillEnterForegroundNotification通知,该通知发生时如果视频仍然在播放,将自动调用pause暂停当前视频播放。需要APP有后台执行权限,在工程Info.plist中添加后台运行模式,设置为audio。具体是添加UIBackgroundModes项,值为audio,当用户点击home按钮后,播放器进入后台继续读取数据并播放音频,当APP回到前台后,音频继续播放。图像渲染内容保持和音频同步,如果在开启后台运行模式后,需要切换后台暂停,需要监听相关事件并主动调用pause操作。
- 停止(结束当前视频播放):
- (void)stop;
**注意**: 重复多次调用将会导致崩溃。
调用stop结束当前播放,如果需要重新播放该视频,需要调用[prepareToPlay]([KSYMediaPlayback prepareToPlay])方法,调用stop方法后,播放器开始进入关闭当前播放的操作,操作完成将发送MPMoviePlayerPlaybackDidFinishNotification通知。
- 是否正在播放
- (BOOL)isPlaying;
- 指定播放器输出音量
/*
* 指定播放器输出音量
* leftVolume left volume scalar [0~2.0f]
* rightVolume right volume scalar [0~2.0f]
* 输入参数超出范围将失效
*/
-(void)setVolume:(float)leftVolume rigthVolume:(float)rightVolume;
- 播放视频的当前时刻
/* 播放视频的当前时刻,单位为秒
*
* 视频正常播放时,如果改变currentPlaybackTime的值,将导致播放行为跳转到新的currentPlaybackTime位置播放
* 如果在视频未播放前设置currentPlaybackTime的值,将导致播放时刻从currentPlaybackTime位置播放
*
*/
@property(nonatomic) NSTimeInterval currentPlaybackTime;
-
播放器通知
获取视频加载状态通知:
//注册通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureStateChange) name: MPMoviePlayerLoadStateDidChangeNotification
object:nil];
可通过_player.loadState获取加载状态。
`@property (nonatomic, readonly) MPMovieLoadState loadState;`
| 加载状态 | 状态说明 |
|---|---|
| MPMovieLoadStateUnknown | 加载情况未知 |
| MPMovieLoadStatePlayable | 加载完成,可以播放 |
| MPMovieLoadStatePlaythroughOK | 加载完成,如果shouldAutoplay为YES,将自动开始播放 |
| MPMovieLoadStateStalled | 视频正在加载中 |
代码示例:
- (void)loadStateDidChange:(NSNotification *)notification
{
if (_player) {
MPMovieLoadState loadState = _player.loadState;
……
}
}
移除通知:
[[NSNotificationCenter defaultCenter] removeObserver:self name: MPMoviePlayerLoadStateDidChangeNotification
object:nil];
- 视频播放状态改变通知: 注册通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureStateChange) name: MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
可通过_player. playbackState获取加载状态。
`@property (nonatomic, readonly) MPMoviePlaybackState playbackState;`
| 播放状态 | 状态说明 |
|---|---|
| MPMoviePlaybackStateStopped | 播放停止 |
| MPMoviePlaybackStatePlaying | 正在播放 |
| MPMoviePlaybackStatePaused | 播放暂停 |
| MPMoviePlaybackStateInterrupted | 播放被打断 |
| MPMoviePlaybackStateSeekingForward | 向前seeking中 |
| MPMoviePlaybackStateSeekingBackward | 向后seeking中 |
代码示例:
- (void)moviePlayBackStateDidChange:(NSNotification *)notification
{
if (_player) {
switch (_player.playbackState) {
case MPMoviePlaybackStateStopped: {
[self changePlayBtnStatus:NO];
break;
}
…….
default:
[self changePlayBtnStatus:NO];
NSLog(@"moviePlayBackStateDidChange : %ld", _player.playbackState);
break;
}
}
}
移除通知:
[[NSNotificationCenter defaultCenter] removeObserver:self name: MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
- 视频播放错误通知:
注册通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureStateChange) name: MPMoviePlayerPlaybackDidFinishNotification
object:nil];
代码示例:
- (void)moviePlayBackDidFinish:(NSNotification *)notification
{
if (_player) {
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
switch (reason)
{
case MPMovieFinishReasonPlaybackEnded:
……
default:
NSLog(@"playbackPlayBackDidFinish: ???: %d\n", reason);
break;
}
}
}
移除通知:
[[NSNotificationCenter defaultCenter] removeObserver:self name: MPMoviePlayerPlaybackDidFinishNotification
object:nil];
- 视频缓冲至可播放状态通知:
注册通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureStateChange) name: MPMoviePlayerPlaybackDidFinishNotification
object:nil];
代码示例:
- (void)mediaIsPreparedToPlayDidChange:(NSNotification *)notification
{
if (_player) {
NSLog(@"isPreparedToPlay");
}
}
移除通知:
[[NSNotificationCenter defaultCenter] removeObserver:self name: MPMoviePlayerPlaybackDidFinishNotification
object:nil];
- 网络状态改变通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerNetworkStatusChange:)
name:MPMoviePlayerNetworkStatusChangeNotification
object:nil];
可通过 MPMoviePlayerCurrNetworkStatusUserInfoKey和MPMoviePlayerLastNetworkStatusUserInfoKey分别获得网络变化过程;
代码示例:
- (void)moviePlayerNetworkStatusChange:(NSNotification *)notify {
int currStatus = [[[notify userInfo] valueForKey:MPMoviePlayerCurrNetworkStatusUserInfoKey] intValue];
int lastStatus = [[[notify userInfo] valueForKey:MPMoviePlayerLastNetworkStatusUserInfoKey] intValue];
NSLog(@"network reachable change from %@ to %@\n", [self netStatus2Str:lastStatus], [self netStatus2Str:currStatus]);
}
其他
-
当前视频总时长(只读):
@property (nonatomic, readonly) NSTimeInterval duration; -
当前视频可播放长度(只读):
@property (nonatomic, readonly) NSTimeInterval playableDuration;注意: currentPlaybackTime 标记的是播放器当前已播放的时长;playableDuration 标记的是播放器缓冲的时间,会稍大于currentPlaybackTime,与currentPlaybackTime的差值则是缓冲长度。
包含视频播放内容的view(只读): 可以通过frame设置view大大小
使用[scalingMode]可以更改视频内容在view中的显示情况;
@property (nonatomic, readonly) UIView *view;
示例代码:
_player = [[CNLiveMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://xxx.m3u8"]];
_player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO;
_player.view.frame = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.width*9/16);
_player.shouldAutoplay = YES;
[_player prepareToPlay];
[self.view addSubview:_player.view];
- 最大缓冲时长:
/* bufferTimeMax指定直播流播放时的最大缓冲时长,单位为秒
*
* 当buffer为负数时,关闭直播追赶
* 该属性仅对直播流有效
* 默认值为2秒
*
*/
@property NSTimeInterval bufferTimeMax;
- 已加载的数据大小(只读):
/* 已经加载的数据大小(只读)
*
* 已经加载的数据大小,单位是兆
* 已经加载的全部数据大小,包括音频和视频
* 数据包括已经播放的,和当前的cache数据
*
*/
@property (nonatomic, readonly) double readSize;
- 拉取数据所耗时长(只读):
/* buffer为空时,拉取数据所耗的时长(只读)
*
* 当buffer为空时,开始统计。单位为秒
*
* 当MPMoviePlayerLoadStateDidChangeNotification 通知发起
* MPMovieLoadState状态为MPMovieLoadStateStalled 开始计时
* MPMovieLoadState状态为MPMovieLoadStatePlayable 或者 MPMovieLoadStatePlaythroughOK时,结束计时
*
*/
@property (nonatomic, readonly) NSTimeInterval bufferEmptyDuration;
- 发起cache次数
/* 发起cache的次数(只读)
*
* 当buffer为空时,统计一次,统计的条件为
*
* 当MPMoviePlayerLoadStateDidChangeNotification 通知发起
* MPMovieLoadState 状态为MPMovieLoadStateStalled
*
*/
@property (nonatomic, readonly) NSInteger bufferEmptyCount;
- 截图
/* 截图
*
* 当前时刻的视频UIImage 图像
*
*/
- (UIImage *)thumbnailImageAtCurrentTime;
- 静音
/**
@abstract 是否静音
@discussion
* 默认不静音
* [prepareToPlay]方法前设置即生效,也可以在播放过程中动态切换
*/
@property(nonatomic) BOOL shouldMute;
- 循环播放
/**
@abstract 是否循环播放
@discussion 默认不循环
* 只在[prepareToPlay]调用前设置生效;
* 只有点播生效,直播场景请勿设置
*/
@property(nonatomic) BOOL shouldLoop;
- 旋转
/**
@abstract 指定逆时针旋转角度,只能是0/90/180/270, 不符合上述值不进行旋转
*/
@property (nonatomic, assign) int rotateDegress;
- 是否打断其他后台的音乐播放
/**
@abstract 是否打断其他后台的音乐播放
@discussion 也可以理解为是否允许和其他音频同时播放
@discussion YES:开始播放时,会打断其他的后台播放音频,也会被其他音频播放打断
@discussion NO: 可以与其他后台播放共存,相互之间不会被打断
@discussion 默认为YES
*/
@property(nonatomic) BOOL bInterruptOtherAudio;
边播边缓存功能
目前仅支持mp4格式的视频缓存
- 获取缓存管理类
+ (CNLiveHTTPProxyService *)manager;
- 设置缓存区位置
- (void)setCacheRoot:(NSString *)cacheRoot;
- 查看缓存区位置
- (NSString*)cacheRoot;
- 查看当前缓存策略
/**
* 查询当前缓存策略,0代表限制缓存区总大小,1代表限制缓存区文件个数
*/
- (NSInteger)getCacheStrategy;
- 设置缓存文件大小限制
- (void)setMaxCacheSizeLimited:(long long)maxCacheSize;
- 查看缓存区最大大小
- (long long)maxCacheSize;
- 设置缓存区文件总个数限制
- (void)setMaxFilesCountLimited:(NSInteger)maxFilesCount;
- 查询缓存区最大文件个数
- (NSInteger)maxFilesCount;
- 设置单个文件大小限制
/**
* 设置单个文件大小限制,超过该大小的文件将不被缓存。
* 默认大小为500M
*/
- (void)setMaxSingleFileSize:(long long)maxSingleFileSize;
- 启动server
- (void)startServer;
- 关闭server
- (void)stopServer;
- 查询server是否在运行状态
- (BOOL)isRunning;
- 获取代理后的播放地址
-(NSString*)getProxyUrl:(NSString*)url;
- 获取原始播放地址
- (NSString *)getOriginalUrl:(NSString *)url;
- 获取代理后的播放地址
-(NSString*)getProxyUrl:(NSString*)url newCache:(BOOL)newCache;
- 删除缓存区所以文件
- (void)deleteAllCachesWithError:(NSError **)error;
- 删除某个url对应的缓存文件
- (void)deleteCacheForUrl:(NSURL *)url error:(NSError **)error;
- 查询某个url缓存是否完成
- (BOOL)isCacheCompleteForUrl:(NSURL *)url;
- 获得缓存已完成文件列表
/**
* 获得缓存已完成文件列表
* 返回的数组元素为NSDictionay, 包含为url和文件路径
*/
- (NSArray *)getAllCachedFileListWithError:(NSError **)errors;
- 获得缓存未完成文件列表
/**
* 获得缓存未完成文件列表
* 返回的数组元素为NSDictionay, 包含url、文件路径、content length、cache fragments
*/
- (NSArray *)getAllCachingFileListWithError:(NSError **)error;
- 获得url对应缓存文件的路径
- (NSArray *)getCacheFragmentForUrl:(NSURL *)url error:(NSError **)error;
- 发送http请求时需要header带上的字段
/**
发送http请求时需要header带上的字段
必须 key:value 都是NSString类型
@param headers 请求头带的字段
*/
- (void)setHttpHeaders:(NSDictionary<NSString *,NSString *> *)headers;
代码示例:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
ViewController *rootVC = [[ViewController alloc] init];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:rootVC];
self.window.rootViewController = nvc;
//初始化直播SDK
[[CNLiveWebcastManager manager] initWithAppId:KAppId appKey:KAppKey isTestEnvironment:YES];
//设置缓存区位置
[[CNLiveHTTPProxyService manager] setCacheRoot:[NSTemporaryDirectory() stringByAppendingPathComponent:@"cachetest"]];
NSLog(@"%@", [CNLiveWebcastManager getVersion]);
//开启服务
[[CNLiveHTTPProxyService manager] startServer];
[self.window makeKeyAndVisible];
return YES;
}
开启/关闭服务:
- (void)applicationWillResignActive:(UIApplication *)application {
//开启服务
[[CNLiveHTTPProxyService manager] startServer];
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
//停止服务
[[CNLiveHTTPProxyService manager] stopServer];
}
预缓存
视频下载器,一个视频文件对应一个下载器,用于开播前预先缓存视频 目前只支持mp4格式
- 初始化下载器
/**
* 初始化下载器
* @param urlString 视频原始地址(未经过代理处理的)
* @param progressBlock 视频缓存进度回调
*/
- (instancetype)initWithUrlString:(NSString *)urlString
progressBlock:(void(^)(float progress))progressBlock;
- 开始缓存
- (void)startDownload;
- 暂停缓存
- (void)pauseDownload;
- 当前缓存的url
- (NSString *)urlString;
- 获取视频缓存状态
- (CNLiveFileDownloaderState)downloaderState;
- 播放地址为url的视频时,调用此方法
+ (void)handleOpenPlayerForUrl:(NSString *)url
progressBlock:(void(^)(float progress))progressBlock;
- 停止播放地址为url的视频时,调用此方法
+ (void)handleClosePlayerForUrl:(NSString *)url
progressBlock:(void(^)(float progress))progressBlock;
| 任务状态 | 含义 |
|---|---|
| CNLiveFileDownloaderStateUnknown | 未知 |
| CNLiveFileDownloaderStatePause | 暂停 |
| CNLiveFileDownloaderStateDownloading | 下载中 |
| CNLiveFileDownloaderStateInvalid | 无效 |
| CNLiveFileDownloaderStateFinished | 完成 |
七.常见错误提示
常见失败信息:
errorCode = "sys_1015";
errorMessage = "app \U5f02\U5e38”;
//appid和bundleID不一致
errorCode = "sys_1002";
errorMessage = "sign error”;
//appkey和appid不一致