Commit a589af84a94fb40ad447ea7e8f34d0f7d1a9378e

Authored by zhangxiaowen
1 parent d74a2a4c

no message

CNLivePlayer/Classes/Player/CNLivePlayer.h
@@ -81,7 +81,8 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); @@ -81,7 +81,8 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo);
81 */ 81 */
82 - (instancetype)initAudioPlayerWithAudioId:(NSString *)audioId authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock; 82 - (instancetype)initAudioPlayerWithAudioId:(NSString *)audioId authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock;
83 83
84 -/* 设置播放器进成功后(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) 84 +
  85 +/* 给播放器设置内容id 设置成功后才能播放(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
85 * 86 *
86 * contentId 内容Id 87 * contentId 内容Id
87 * type 内容类型 88 * type 内容类型
CNLivePlayer/Classes/Player/CNLivePlayer.m
@@ -42,6 +42,7 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha @@ -42,6 +42,7 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha
42 42
43 } 43 }
44 @property (nonatomic, strong, readwrite) UIView *view; 44 @property (nonatomic, strong, readwrite) UIView *view;
  45 +@property (nonatomic, strong) UIImageView *imageView;
45 @property (nonatomic, copy) NSString *videoUrl; 46 @property (nonatomic, copy) NSString *videoUrl;
46 47
47 @end 48 @end
@@ -149,10 +150,13 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha @@ -149,10 +150,13 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha
149 _retryTime = 0; 150 _retryTime = 0;
150 [self addMovieNotificationObservers]; 151 [self addMovieNotificationObservers];
151 152
  153 + __weak typeof(self) weakSelf = self;
152 dispatch_async(dispatch_get_global_queue(0, 0), ^{ 154 dispatch_async(dispatch_get_global_queue(0, 0), ^{
153 - [self getUrlSuccess:authSuccessBlock failure:authFailureBlock]; 155 + __strong typeof(self) strongSelf = weakSelf;
  156 + [strongSelf getUrlSuccess:authSuccessBlock failure:authFailureBlock];
154 157
155 }); 158 });
  159 +
156 } 160 }
157 161
158 - (void)dealloc { 162 - (void)dealloc {
@@ -175,6 +179,7 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha @@ -175,6 +179,7 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha
175 [self removeRCloudNotificationObservers]; 179 [self removeRCloudNotificationObservers];
176 180
177 } 181 }
  182 +
178 - (void)setPlayerWithContentId:(NSString *)contentId type:(CNLivePlayerType)type authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock{ 183 - (void)setPlayerWithContentId:(NSString *)contentId type:(CNLivePlayerType)type authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock{
179 if([_contentId isEqualToString:contentId]){ 184 if([_contentId isEqualToString:contentId]){
180 return; 185 return;
@@ -209,7 +214,9 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha @@ -209,7 +214,9 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha
209 break; 214 break;
210 215
211 } 216 }
212 - 217 + self.imageView.image = [_player thumbnailImageAtCurrentTime];
  218 + self.imageView.hidden = NO;
  219 +
213 __weak typeof(self) weakSelf = self; 220 __weak typeof(self) weakSelf = self;
214 dispatch_async(dispatch_get_global_queue(0, 0), ^{ 221 dispatch_async(dispatch_get_global_queue(0, 0), ^{
215 __strong typeof(self) strongSelf = weakSelf; 222 __strong typeof(self) strongSelf = weakSelf;
@@ -677,12 +684,23 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha @@ -677,12 +684,23 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha
677 684
678 } 685 }
679 686
  687 +- (UIImageView *)imageView {
  688 + if (!_imageView) {
  689 + _imageView = [[UIImageView alloc] initWithFrame:self.player.view.bounds];
  690 + _imageView.backgroundColor = [UIColor redColor];
  691 + [self.player.view addSubview:_imageView];
  692 + }
  693 + return _imageView;
  694 +
  695 +}
  696 +
680 /* 准备视频播放 697 /* 准备视频播放
681 * 698 *
682 * MPMediaPlaybackIsPreparedToPlayDidChangeNotification, 播放器完成对视频文件的初始化时发送通知 699 * MPMediaPlaybackIsPreparedToPlayDidChangeNotification, 播放器完成对视频文件的初始化时发送通知
683 * 700 *
684 */ 701 */
685 - (void)prepareToPlay { 702 - (void)prepareToPlay {
  703 + _imageView.hidden = YES;
686 [_player prepareToPlay]; 704 [_player prepareToPlay];
687 705
688 } 706 }
Example/CNLivePlayer/CNLiveViewController.m
@@ -33,9 +33,12 @@ @@ -33,9 +33,12 @@
33 // NSLog(@"%@", errorInfo); 33 // NSLog(@"%@", errorInfo);
34 // 34 //
35 // }]; 35 // }];
36 -  
37 - _player = [[CNLivePlayer alloc]initAudioPlayerWithAudioId:@"1066_716fabeaafb64236b60ecf74167c5c96" authSuccess:^{ 36 + //1066_716fabeaafb64236b60ecf74167c5c96
  37 + //82_c8ff347048414b7295cef882f8361073
  38 + _player = [[CNLivePlayer alloc]initAudioPlayerWithAudioId:@"82_c8ff347048414b7295cef882f8361073" authSuccess:^{
38 NSLog(@"---------------初始化播放器成功---------------"); 39 NSLog(@"---------------初始化播放器成功---------------");
  40 + _player.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*9/16.0);
  41 +
39 [_player prepareToPlay]; 42 [_player prepareToPlay];
40 [self.view addSubview:_player.view]; 43 [self.view addSubview:_player.view];
41 44
@@ -60,8 +63,7 @@ @@ -60,8 +63,7 @@
60 63
61 } 64 }
62 - (void)btnDidClicked{ 65 - (void)btnDidClicked{
63 - [_player setPlayerWithContentId:@"82_c8ff347048414b7295cef882f8361073" type:CNLivePlayerVod authSuccess:^{  
64 - _player.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*9/16.0); 66 + [_player setPlayerWithContentId:@"1066_716fabeaafb64236b60ecf74167c5c96" type:CNLivePlayerVod authSuccess:^{
65 [_player prepareToPlay]; 67 [_player prepareToPlay];
66 68
67 } authFailure:^(NSDictionary * _Nonnull errorInfo) { 69 } authFailure:^(NSDictionary * _Nonnull errorInfo) {