Commit 339f27372a6ef7c140c88391cc8c507ae1ef1b21

Authored by zhangxiaowen
1 parent e67a39d9

no message

CNLivePlayer/Classes/Player/CNLivePlayer.h
@@ -153,6 +153,11 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); @@ -153,6 +153,11 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo);
153 */ 153 */
154 @property (nonatomic, readonly) BOOL isPreparedToPlay; 154 @property (nonatomic, readonly) BOOL isPreparedToPlay;
155 155
  156 +/*
  157 + * 当前播放的时间
  158 + */
  159 +@property(nonatomic, assign) NSTimeInterval currentPlaybackTime;
  160 +
156 #pragma mark - 方法 161 #pragma mark - 方法
157 /* 162 /*
158 * 获取主播状态(离开/已结束) 163 * 获取主播状态(离开/已结束)
CNLivePlayer/Classes/Player/CNLivePlayer.m
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 30
31 // 1-流畅,2-标清,3-高清,4-超清,默认为2 31 // 1-流畅,2-标清,3-高清,4-超清,默认为2
32 NSString *_rate; 32 NSString *_rate;
33 - 33 +
34 //音频标识 34 //音频标识
35 BOOL _isAudio; 35 BOOL _isAudio;
36 NSString *_roomId; 36 NSString *_roomId;
@@ -217,6 +217,7 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang @@ -217,6 +217,7 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang
217 if([_contentId isEqualToString:contentId]){ 217 if([_contentId isEqualToString:contentId]){
218 return; 218 return;
219 } 219 }
  220 + //暂停当前视频
220 [self pause]; 221 [self pause];
221 _retryTime = 0; 222 _retryTime = 0;
222 _type = type; 223 _type = type;
@@ -265,12 +266,15 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang @@ -265,12 +266,15 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang
265 * 266 *
266 */ 267 */
267 - (void)setPlayerWithRate:(NSString *)rate authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock{ 268 - (void)setPlayerWithRate:(NSString *)rate authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock{
  269 + if([_rate isEqualToString:rate]){
  270 + return;
  271 + }
268 _rate = rate; 272 _rate = rate;
269 __weak typeof(self) weakSelf = self; 273 __weak typeof(self) weakSelf = self;
270 dispatch_async(dispatch_get_global_queue(0, 0), ^{ 274 dispatch_async(dispatch_get_global_queue(0, 0), ^{
271 __strong typeof(self) strongSelf = weakSelf; 275 __strong typeof(self) strongSelf = weakSelf;
272 [strongSelf getUrlSuccess:authSuccessBlock failure:authFailureBlock]; 276 [strongSelf getUrlSuccess:authSuccessBlock failure:authFailureBlock];
273 - 277 +
274 }); 278 });
275 } 279 }
276 280
@@ -325,6 +329,7 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang @@ -325,6 +329,7 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang
325 }else{ 329 }else{
326 [strongSelf.player reset:YES]; 330 [strongSelf.player reset:YES];
327 [strongSelf.player setUrl:[NSURL URLWithString:strongSelf.videoUrl]]; 331 [strongSelf.player setUrl:[NSURL URLWithString:strongSelf.videoUrl]];
  332 +
328 } 333 }
329 authSuccessBlock ? authSuccessBlock() : nil; 334 authSuccessBlock ? authSuccessBlock() : nil;
330 335
@@ -868,6 +873,18 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang @@ -868,6 +873,18 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang
868 return _player.isPreparedToPlay; 873 return _player.isPreparedToPlay;
869 } 874 }
870 875
  876 +/*
  877 + * 当前播放的时间
  878 + */
  879 +- (NSTimeInterval)currentPlaybackTime{
  880 + return _player.currentPlaybackTime;
  881 +
  882 +}
  883 +- (void)setCurrentPlaybackTime:(NSTimeInterval)currentPlaybackTime{
  884 + _player.currentPlaybackTime = currentPlaybackTime;
  885 +
  886 +}
  887 +
871 #pragma mark - 方法 888 #pragma mark - 方法
872 /* 889 /*
873 * 准备视频播放 890 * 准备视频播放
Example/CNLivePlayer/CNLivePlayerController.m
@@ -84,27 +84,31 @@ @@ -84,27 +84,31 @@
84 } 84 }
85 85
86 - (void)btnDidClicked{ 86 - (void)btnDidClicked{
87 -  
88 __weak typeof(self) weakSelf = self; 87 __weak typeof(self) weakSelf = self;
89 - [_player setPlayerWithContentId:@"1066_716fabeaafb64236b60ecf74167c5c96" type:CNLivePlayerVod authSuccess:^{ 88 +// [_player setPlayerWithContentId:@"1066_716fabeaafb64236b60ecf74167c5c96" type:CNLivePlayerVod authSuccess:^{
  89 +// __strong typeof(self) strongSelf = weakSelf;
  90 +// [strongSelf.player prepareToPlay];
  91 +//
  92 +// } authFailure:^(NSDictionary * _Nonnull errorInfo) {
  93 +//
  94 +// }];
  95 + NSLog(@"是按:%f",self.player.currentPlaybackTime);
  96 + [_player setPlayerWithRate:@"4" authSuccess:^{
90 __strong typeof(self) strongSelf = weakSelf; 97 __strong typeof(self) strongSelf = weakSelf;
91 [strongSelf.player prepareToPlay]; 98 [strongSelf.player prepareToPlay];
  99 + strongSelf.player.currentPlaybackTime = 10;
92 100
93 } authFailure:^(NSDictionary * _Nonnull errorInfo) { 101 } authFailure:^(NSDictionary * _Nonnull errorInfo) {
94 102
95 }]; 103 }];
96 -// [_player setPlayerWithRate:@"4" authSuccess:^{  
97 -// __strong typeof(self) strongSelf = weakSelf;  
98 -// [strongSelf.player prepareToPlay];  
99 -// } authFailure:^(NSDictionary * _Nonnull errorInfo) {  
100 -//  
101 -// }];  
102 104
103 } 105 }
  106 +
104 - (void)backDidClicked{ 107 - (void)backDidClicked{
105 [self dismissViewControllerAnimated:YES completion:nil]; 108 [self dismissViewControllerAnimated:YES completion:nil];
106 109
107 } 110 }
  111 +
108 /* 112 /*
109 #pragma mark - Navigation 113 #pragma mark - Navigation
110 114
Example/CNLivePlayer/CNLiveViewController.m
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 8
9 #import "CNLiveViewController.h" 9 #import "CNLiveViewController.h"
10 #import "CNLivePlayerController.h" 10 #import "CNLivePlayerController.h"
  11 +#import "CNLivePlayerDBTool.h"
11 12
12 @interface CNLiveViewController () 13 @interface CNLiveViewController ()
13 14
@@ -15,6 +16,14 @@ @@ -15,6 +16,14 @@
15 16
16 @implementation CNLiveViewController 17 @implementation CNLiveViewController
17 18
  19 +-(void)viewWillAppear:(BOOL)animated{
  20 + [super viewWillAppear:animated];
  21 + NSMutableArray *data = [[CNLivePlayerDBTool shared] queryTable];
  22 + for(CNLivePlayerDBModel *model in data){
  23 + NSLog(@"%@---%@",model.contentId,model.url);
  24 + }
  25 +
  26 +}
18 - (void)viewDidLoad 27 - (void)viewDidLoad
19 { 28 {
20 [super viewDidLoad]; 29 [super viewDidLoad];