Commit 966a5db2e1035376474c2e2e711e2017ff3deb33
1 parent
339f2737
no message
Showing
3 changed files
with
24 additions
and
12 deletions
CNLivePlayer/Classes/Player/CNLivePlayer.h
| ... | ... | @@ -172,13 +172,12 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); |
| 172 | 172 | */ |
| 173 | 173 | - (void)setPlayerWithContentId:(NSString *)contentId type:(CNLivePlayerType)type authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock; |
| 174 | 174 | |
| 175 | -/* 给播放器切换码率设置内容id 设置成功后才能播放(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) | |
| 176 | - * 切换视频 | |
| 175 | +/* 给点播播放器切换码率设置内容id 设置成功后才能播放(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) | |
| 176 | + * 切换视频清晰度 | |
| 177 | + * contentId 内容Id(如果不切换视频,只切换清晰度,可以将contentId=nil) | |
| 177 | 178 | * rate 码率 1-流畅,2-标清,3-高清,4-超清,默认为2 |
| 178 | - * type 内容类型 | |
| 179 | - * | |
| 180 | 179 | */ |
| 181 | -- (void)setPlayerWithRate:(NSString *)rate authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock; | |
| 180 | +- (void)setPlayerWithContentId:(NSString *)contentId rate:(NSString *)rate authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock; | |
| 182 | 181 | |
| 183 | 182 | /* |
| 184 | 183 | * 销毁播放器 | ... | ... |
CNLivePlayer/Classes/Player/CNLivePlayer.m
| ... | ... | @@ -259,17 +259,24 @@ NSString * const CNLiveHostStatusChangedNotification = @"CNLiveAnchorStatusChang |
| 259 | 259 | |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | -/* 给播放器切换码率设置内容id 设置成功后才能播放(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) | |
| 263 | - * 切换视频 | |
| 262 | +/* 给点播播放器切换码率设置内容id 设置成功后才能播放(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay) | |
| 263 | + * 切换视频清晰度 | |
| 264 | + * contentId 内容Id(如果不切换视频,只切换清晰度,可以将contentId=nil) | |
| 264 | 265 | * rate 码率 1-流畅,2-标清,3-高清,4-超清,默认为2 |
| 265 | - * type 内容类型 | |
| 266 | - * | |
| 267 | 266 | */ |
| 268 | -- (void)setPlayerWithRate:(NSString *)rate authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock{ | |
| 267 | +- (void)setPlayerWithContentId:(NSString *)contentId rate:(NSString *)rate authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock { | |
| 269 | 268 | if([_rate isEqualToString:rate]){ |
| 270 | 269 | return; |
| 271 | 270 | } |
| 271 | + if(contentId && ![contentId isEqualToString:@""]){ | |
| 272 | + _contentId = contentId; | |
| 273 | + | |
| 274 | + } | |
| 275 | + _idName = @"vid"; | |
| 276 | + _contentType = @"vod"; | |
| 277 | + _isAudio = NO; | |
| 272 | 278 | _rate = rate; |
| 279 | + | |
| 273 | 280 | __weak typeof(self) weakSelf = self; |
| 274 | 281 | dispatch_async(dispatch_get_global_queue(0, 0), ^{ |
| 275 | 282 | __strong typeof(self) strongSelf = weakSelf; | ... | ... |
Example/CNLivePlayer/CNLivePlayerController.m
| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | #import "CNLivePlayerController.h" |
| 10 | 10 | #import <libksygpulive/KSYMoviePlayerController.h> |
| 11 | 11 | #import "CNLivePlayer.h" |
| 12 | +#import "CNLivePlayerDownloader.h" | |
| 12 | 13 | |
| 13 | 14 | @interface CNLivePlayerController () |
| 14 | 15 | @property (nonatomic, strong) CNLivePlayer *player; |
| ... | ... | @@ -62,7 +63,11 @@ |
| 62 | 63 | back.backgroundColor = [UIColor greenColor]; |
| 63 | 64 | [back addTarget:self action:@selector(backDidClicked) forControlEvents:UIControlEventTouchUpInside]; |
| 64 | 65 | [self.view addSubview:back]; |
| 65 | - | |
| 66 | + CNLivePlayerDownloader *dowa = [[CNLivePlayerDownloader alloc]initWithUrlString:@"http://wideo02.cnlive.com/video/data1/2017/0423/206473/800/c8ff347048414b7295cef882f8361073_206473_800.m3u8" progressBlock:^(float progress) { | |
| 67 | + NSLog(@"缓存进度中%f",progress); | |
| 68 | + }]; | |
| 69 | + NSLog(@"缓存的url是:%@",dowa.urlString); | |
| 70 | + [dowa startDownload]; | |
| 66 | 71 | |
| 67 | 72 | // self.player = [[CNLivePlayer alloc] initWithContentURL:[NSURL URLWithString:@"http://wideo02.cnlive.com/video/data1/2017/0423/206473/800/c8ff347048414b7295cef882f8361073_206473_800.m3u8"]]; |
| 68 | 73 | // self.player.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*9/16.0); |
| ... | ... | @@ -92,7 +97,8 @@ |
| 92 | 97 | // } authFailure:^(NSDictionary * _Nonnull errorInfo) { |
| 93 | 98 | // |
| 94 | 99 | // }]; |
| 95 | - NSLog(@"是按:%f",self.player.currentPlaybackTime); | |
| 100 | + NSLog(@"当时已播放的时间是:%f",self.player.currentPlaybackTime); | |
| 101 | + [_player setplay] | |
| 96 | 102 | [_player setPlayerWithRate:@"4" authSuccess:^{ |
| 97 | 103 | __strong typeof(self) strongSelf = weakSelf; |
| 98 | 104 | [strongSelf.player prepareToPlay]; | ... | ... |