Commit 339f27372a6ef7c140c88391cc8c507ae1ef1b21
1 parent
e67a39d9
no message
Showing
4 changed files
with
45 additions
and
10 deletions
CNLivePlayer/Classes/Player/CNLivePlayer.h
| ... | ... | @@ -153,6 +153,11 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); |
| 153 | 153 | */ |
| 154 | 154 | @property (nonatomic, readonly) BOOL isPreparedToPlay; |
| 155 | 155 | |
| 156 | +/* | |
| 157 | + * 当前播放的时间 | |
| 158 | + */ | |
| 159 | +@property(nonatomic, assign) NSTimeInterval currentPlaybackTime; | |
| 160 | + | |
| 156 | 161 | #pragma mark - 方法 |
| 157 | 162 | /* |
| 158 | 163 | * 获取主播状态(离开/已结束) | ... | ... |
CNLivePlayer/Classes/Player/CNLivePlayer.m
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | |
| 31 | 31 | // 1-流畅,2-标清,3-高清,4-超清,默认为2 |
| 32 | 32 | NSString *_rate; |
| 33 | - | |
| 33 | + | |
| 34 | 34 | //音频标识 |
| 35 | 35 | BOOL _isAudio; |
| 36 | 36 | NSString *_roomId; |
| ... | ... | @@ -217,6 +217,7 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang |
| 217 | 217 | if([_contentId isEqualToString:contentId]){ |
| 218 | 218 | return; |
| 219 | 219 | } |
| 220 | + //暂停当前视频 | |
| 220 | 221 | [self pause]; |
| 221 | 222 | _retryTime = 0; |
| 222 | 223 | _type = type; |
| ... | ... | @@ -265,12 +266,15 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang |
| 265 | 266 | * |
| 266 | 267 | */ |
| 267 | 268 | - (void)setPlayerWithRate:(NSString *)rate authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock{ |
| 269 | + if([_rate isEqualToString:rate]){ | |
| 270 | + return; | |
| 271 | + } | |
| 268 | 272 | _rate = rate; |
| 269 | 273 | __weak typeof(self) weakSelf = self; |
| 270 | 274 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ |
| 271 | 275 | __strong typeof(self) strongSelf = weakSelf; |
| 272 | 276 | [strongSelf getUrlSuccess:authSuccessBlock failure:authFailureBlock]; |
| 273 | - | |
| 277 | + | |
| 274 | 278 | }); |
| 275 | 279 | } |
| 276 | 280 | |
| ... | ... | @@ -325,6 +329,7 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang |
| 325 | 329 | }else{ |
| 326 | 330 | [strongSelf.player reset:YES]; |
| 327 | 331 | [strongSelf.player setUrl:[NSURL URLWithString:strongSelf.videoUrl]]; |
| 332 | + | |
| 328 | 333 | } |
| 329 | 334 | authSuccessBlock ? authSuccessBlock() : nil; |
| 330 | 335 | |
| ... | ... | @@ -868,6 +873,18 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang |
| 868 | 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 | 888 | #pragma mark - 方法 |
| 872 | 889 | /* |
| 873 | 890 | * 准备视频播放 | ... | ... |
Example/CNLivePlayer/CNLivePlayerController.m
| ... | ... | @@ -84,27 +84,31 @@ |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | - (void)btnDidClicked{ |
| 87 | - | |
| 88 | 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 | 97 | __strong typeof(self) strongSelf = weakSelf; |
| 91 | 98 | [strongSelf.player prepareToPlay]; |
| 99 | + strongSelf.player.currentPlaybackTime = 10; | |
| 92 | 100 | |
| 93 | 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 | 107 | - (void)backDidClicked{ |
| 105 | 108 | [self dismissViewControllerAnimated:YES completion:nil]; |
| 106 | 109 | |
| 107 | 110 | } |
| 111 | + | |
| 108 | 112 | /* |
| 109 | 113 | #pragma mark - Navigation |
| 110 | 114 | ... | ... |
Example/CNLivePlayer/CNLiveViewController.m
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | #import "CNLiveViewController.h" |
| 10 | 10 | #import "CNLivePlayerController.h" |
| 11 | +#import "CNLivePlayerDBTool.h" | |
| 11 | 12 | |
| 12 | 13 | @interface CNLiveViewController () |
| 13 | 14 | |
| ... | ... | @@ -15,6 +16,14 @@ |
| 15 | 16 | |
| 16 | 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 | 27 | - (void)viewDidLoad |
| 19 | 28 | { |
| 20 | 29 | [super viewDidLoad]; | ... | ... |