Commit ed602afdd91f91947dca29f58ea02c35a0ef5f48

Authored by zhangxiaowen
1 parent 3465c0ed

no message

CNLivePlayer/Classes/Player/CNLivePlayer.h
@@ -62,6 +62,7 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); @@ -62,6 +62,7 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo);
62 62
63 63
64 /* 初始化点播播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) 64 /* 初始化点播播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
  65 + * 码率默认2-标清
65 * 66 *
66 * videoId 视频Id 67 * videoId 视频Id
67 * authSuccess 初始化成功block 68 * authSuccess 初始化成功block
CNLivePlayer/Classes/Player/CNLivePlayer.m
@@ -18,6 +18,8 @@ @@ -18,6 +18,8 @@
18 //缓存视频 18 //缓存视频
19 #import <KSYHTTPCache/HTTPCacheDefines.h> 19 #import <KSYHTTPCache/HTTPCacheDefines.h>
20 #import "CNLiveHTTPProxyService.h" 20 #import "CNLiveHTTPProxyService.h"
  21 +//缓存的key
  22 +#define PlayerStringToKey(a, b) [NSString stringWithFormat:@"%@:%@",a,b]
21 23
22 @interface CNLivePlayer () { 24 @interface CNLivePlayer () {
23 NSString *_idName; 25 NSString *_idName;
@@ -83,6 +85,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -83,6 +85,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
83 } 85 }
84 86
85 /* 初始化点播播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) 87 /* 初始化点播播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
  88 + * 码率默认2-标清
86 * 89 *
87 * videoId 点播视频Id 90 * videoId 点播视频Id
88 * authSuccess 初始化成功block 91 * authSuccess 初始化成功block
@@ -318,8 +321,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -318,8 +321,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
318 321
319 #pragma mark - 查找本地是否有缓存url 322 #pragma mark - 查找本地是否有缓存url
320 - (void)getUrlSuccess:(void (^)(void))authSuccessBlock failure:(void (^)(NSDictionary *errorDic))authFailureBlock { 323 - (void)getUrlSuccess:(void (^)(void))authSuccessBlock failure:(void (^)(NSDictionary *errorDic))authFailureBlock {
321 - NSString *key = [NSString stringWithFormat:@"%@:%@",_contentId,_rate];  
322 - id data = [[CNLivePlayerDBTool shared] searchInTable:key]; 324 + id data = [[CNLivePlayerDBTool shared] searchInTable:PlayerStringToKey(_contentId,_rate)];
323 CNLivePlayerDBModel *model = (CNLivePlayerDBModel *)data; 325 CNLivePlayerDBModel *model = (CNLivePlayerDBModel *)data;
324 //1.判断是否存在缓存url 326 //1.判断是否存在缓存url
325 if (![model isEmpty]) { 327 if (![model isEmpty]) {
@@ -478,8 +480,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -478,8 +480,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
478 if(!strongSelf){ 480 if(!strongSelf){
479 return ; 481 return ;
480 } 482 }
481 - NSString *key = [NSString stringWithFormat:@"%@:%@",strongSelf->_contentId, strongSelf->_rate];  
482 - CNLivePlayerDBModel *model = [[CNLivePlayerDBModel alloc]initWithContenId:key url:videoURL]; 483 + CNLivePlayerDBModel *model = [[CNLivePlayerDBModel alloc]initWithContenId:PlayerStringToKey(strongSelf->_contentId, strongSelf->_rate) url:videoURL];
483 [[CNLivePlayerDBTool shared] insertTable:model]; 484 [[CNLivePlayerDBTool shared] insertTable:model];
484 485
485 __weak typeof(self) weakSelf = strongSelf; 486 __weak typeof(self) weakSelf = strongSelf;
@@ -550,8 +551,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -550,8 +551,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
550 url = videoUrl; 551 url = videoUrl;
551 552
552 } 553 }
553 - NSString *key = [NSString stringWithFormat:@"%@:%@",strongSelf->_contentId, strongSelf->_rate];  
554 - CNLivePlayerDBModel *model = [[CNLivePlayerDBModel alloc]initWithContenId:key url:url]; 554 + CNLivePlayerDBModel *model = [[CNLivePlayerDBModel alloc]initWithContenId:PlayerStringToKey(strongSelf->_contentId, strongSelf->_rate) url:url];
555 [[CNLivePlayerDBTool shared] insertTable:model]; 555 [[CNLivePlayerDBTool shared] insertTable:model];
556 556
557 __weak typeof(self) weakSelf = strongSelf; 557 __weak typeof(self) weakSelf = strongSelf;
@@ -747,8 +747,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -747,8 +747,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
747 dispatch_async(dispatch_get_main_queue(), ^{ 747 dispatch_async(dispatch_get_main_queue(), ^{
748 __strong typeof(self) strongSelf = weakSelf; 748 __strong typeof(self) strongSelf = weakSelf;
749 if(strongSelf){ 749 if(strongSelf){
750 - NSString *key = [NSString stringWithFormat:@"%@:%@",strongSelf->_contentId, strongSelf->_rate];  
751 - [[CNLivePlayerDBTool shared] updateInTable:key]; 750 + [[CNLivePlayerDBTool shared] updateInTable:PlayerStringToKey(strongSelf->_contentId, strongSelf->_rate)];
752 } 751 }
753 752
754 }); 753 });