Commit a589af84a94fb40ad447ea7e8f34d0f7d1a9378e
1 parent
d74a2a4c
no message
Showing
3 changed files
with
28 additions
and
7 deletions
CNLivePlayer/Classes/Player/CNLivePlayer.h
| ... | ... | @@ -81,7 +81,8 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); |
| 81 | 81 | */ |
| 82 | 82 | - (instancetype)initAudioPlayerWithAudioId:(NSString *)audioId authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock; |
| 83 | 83 | |
| 84 | -/* 设置播放器进成功后(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) | |
| 84 | + | |
| 85 | +/* 给播放器设置内容id 设置成功后才能播放(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) | |
| 85 | 86 | * |
| 86 | 87 | * contentId 内容Id |
| 87 | 88 | * type 内容类型 | ... | ... |
CNLivePlayer/Classes/Player/CNLivePlayer.m
| ... | ... | @@ -42,6 +42,7 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha |
| 42 | 42 | |
| 43 | 43 | } |
| 44 | 44 | @property (nonatomic, strong, readwrite) UIView *view; |
| 45 | +@property (nonatomic, strong) UIImageView *imageView; | |
| 45 | 46 | @property (nonatomic, copy) NSString *videoUrl; |
| 46 | 47 | |
| 47 | 48 | @end |
| ... | ... | @@ -149,10 +150,13 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha |
| 149 | 150 | _retryTime = 0; |
| 150 | 151 | [self addMovieNotificationObservers]; |
| 151 | 152 | |
| 153 | + __weak typeof(self) weakSelf = self; | |
| 152 | 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 | 162 | - (void)dealloc { |
| ... | ... | @@ -175,6 +179,7 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha |
| 175 | 179 | [self removeRCloudNotificationObservers]; |
| 176 | 180 | |
| 177 | 181 | } |
| 182 | + | |
| 178 | 183 | - (void)setPlayerWithContentId:(NSString *)contentId type:(CNLivePlayerType)type authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock{ |
| 179 | 184 | if([_contentId isEqualToString:contentId]){ |
| 180 | 185 | return; |
| ... | ... | @@ -209,7 +214,9 @@ NSString * const CNLiveAnchorStatusChangedNotification = @"CNLiveAnchorStatusCha |
| 209 | 214 | break; |
| 210 | 215 | |
| 211 | 216 | } |
| 212 | - | |
| 217 | + self.imageView.image = [_player thumbnailImageAtCurrentTime]; | |
| 218 | + self.imageView.hidden = NO; | |
| 219 | + | |
| 213 | 220 | __weak typeof(self) weakSelf = self; |
| 214 | 221 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ |
| 215 | 222 | __strong typeof(self) strongSelf = weakSelf; |
| ... | ... | @@ -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 | 699 | * MPMediaPlaybackIsPreparedToPlayDidChangeNotification, 播放器完成对视频文件的初始化时发送通知 |
| 683 | 700 | * |
| 684 | 701 | */ |
| 685 | 702 | - (void)prepareToPlay { |
| 703 | + _imageView.hidden = YES; | |
| 686 | 704 | [_player prepareToPlay]; |
| 687 | 705 | |
| 688 | 706 | } | ... | ... |
Example/CNLivePlayer/CNLiveViewController.m
| ... | ... | @@ -33,9 +33,12 @@ |
| 33 | 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 | 39 | NSLog(@"---------------初始化播放器成功---------------"); |
| 40 | + _player.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*9/16.0); | |
| 41 | + | |
| 39 | 42 | [_player prepareToPlay]; |
| 40 | 43 | [self.view addSubview:_player.view]; |
| 41 | 44 | |
| ... | ... | @@ -60,8 +63,7 @@ |
| 60 | 63 | |
| 61 | 64 | } |
| 62 | 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 | 67 | [_player prepareToPlay]; |
| 66 | 68 | |
| 67 | 69 | } authFailure:^(NSDictionary * _Nonnull errorInfo) { | ... | ... |