Commit df821378e9c063068e83a2e2715524e1fde936bd
1 parent
1fdbff7a
no message
Showing
5 changed files
with
65 additions
and
16 deletions
CNLivePlayer/Classes/DataRequest/CNLivePlayerNetworkManager.h
| @@ -24,6 +24,24 @@ typedef void(^GetVideoURLSuccessBlock)(NSString * _Nullable videoURL, NSInteger | @@ -24,6 +24,24 @@ typedef void(^GetVideoURLSuccessBlock)(NSString * _Nullable videoURL, NSInteger | ||
| 24 | 24 | ||
| 25 | + (CNLivePlayerNetworkManager *)manager; | 25 | + (CNLivePlayerNetworkManager *)manager; |
| 26 | 26 | ||
| 27 | +/** | ||
| 28 | + * GET 请求 | ||
| 29 | + * @param URL url | ||
| 30 | + * @param parameters 上传参数 | ||
| 31 | + * @param success 请求成功回调 | ||
| 32 | + * @param failure 请求失败回调 | ||
| 33 | + */ | ||
| 34 | ++ (void)GET:(nullable NSString *)URL parameters:(nullable NSDictionary *)parameters success:(nullable void (^)(NSURLResponse *_Nullable response, id _Nullable responseObject))success failure:(nullable void (^)(NSURLResponse *_Nullable response, NSError *_Nullable error))failure; | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * POST 请求 | ||
| 38 | + * @param URL url | ||
| 39 | + * @param parameters 上传参数 | ||
| 40 | + * @param success 请求成功回调 | ||
| 41 | + * @param failure 请求失败回调 | ||
| 42 | + */ | ||
| 43 | ++ (void)POST:(nullable NSString *)URL parameters:(nullable NSDictionary *)parameters success:(nullable void (^)(NSURLResponse *_Nullable response, id _Nullable responseObject))success failure:(nullable void (^)(NSURLResponse *_Nullable response, NSError *_Nullable error))failure; | ||
| 44 | + | ||
| 27 | #pragma mark - 针对具体业务 | 45 | #pragma mark - 针对具体业务 |
| 28 | /** | 46 | /** |
| 29 | * 鉴权 | 47 | * 鉴权 |
CNLivePlayer/Classes/DataRequest/CNLivePlayerNetworkManager.m
| @@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
| 10 | #import "CNLiveURLRequestSerialization.h" | 10 | #import "CNLiveURLRequestSerialization.h" |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | - * 网络超时时间 默认 60 | 13 | + * 网络超时时间 默认 30 |
| 14 | */ | 14 | */ |
| 15 | static NSTimeInterval TimeoutInterval = 30.0 ; | 15 | static NSTimeInterval TimeoutInterval = 30.0 ; |
| 16 | 16 | ||
| @@ -54,6 +54,17 @@ static CNLivePlayerNetworkManager *_manager = nil; | @@ -54,6 +54,17 @@ static CNLivePlayerNetworkManager *_manager = nil; | ||
| 54 | return self; | 54 | return self; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | ++ (void)GET:(NSString *)URL parameters:(NSDictionary *)parameters success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure { | ||
| 58 | + NSURLSessionDataTask *task = [[CNLivePlayerNetworkManager manager] dataTaskWithRequestMethod:@"GET" URLString:URL parameters:parameters success:success failure:failure]; | ||
| 59 | + [task resume]; | ||
| 60 | + | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | ++ (void)POST:(NSString *)URL parameters:(NSDictionary *)parameters success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure { | ||
| 64 | + NSURLSessionDataTask *task = [[CNLivePlayerNetworkManager manager] dataTaskWithRequestMethod:@"POST" URLString:URL parameters:parameters success:success failure:failure]; | ||
| 65 | + [task resume]; | ||
| 66 | +} | ||
| 67 | + | ||
| 57 | #pragma mark - 公共方法 | 68 | #pragma mark - 公共方法 |
| 58 | - (NSURLSessionDataTask *)dataTaskWithRequestMethod:(NSString *)method URLString:(NSString *)URLString parameters:(NSDictionary *)parameters success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure { | 69 | - (NSURLSessionDataTask *)dataTaskWithRequestMethod:(NSString *)method URLString:(NSString *)URLString parameters:(NSDictionary *)parameters success:(void (^)(NSURLResponse * _Nullable, id _Nullable))success failure:(void (^)(NSURLResponse * _Nullable, NSError * _Nullable))failure { |
| 59 | 70 |
Example/CNLivePlayer/CNLiveAppDelegate.m
| @@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
| 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions |
| 19 | { | 19 | { |
| 20 | // Override point for customization after application launch. | 20 | // Override point for customization after application launch. |
| 21 | - [CNLivePlayerManager setAppId:CNLivePlayer_AppId appKey:CNLivePlayer_AppKey isTestEnvironment:YES]; | 21 | + [CNLivePlayerManager setAppId:CNLivePlayer_AppId appKey:CNLivePlayer_AppKey isTestEnvironment:NO]; |
| 22 | 22 | ||
| 23 | return YES; | 23 | return YES; |
| 24 | } | 24 | } |
Example/CNLivePlayer/CNLivePlayerController.m
| @@ -53,7 +53,7 @@ | @@ -53,7 +53,7 @@ | ||
| 53 | 53 | ||
| 54 | UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; | 54 | UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 55 | btn1.frame = CGRectMake(0, 0, 100, 50); | 55 | btn1.frame = CGRectMake(0, 0, 100, 50); |
| 56 | - btn1.center = CGPointMake(self.view.center.x, self.view.center.y-50); | 56 | + btn1.center = CGPointMake(self.view.center.x, self.view.center.y-120); |
| 57 | btn1.backgroundColor = [UIColor redColor]; | 57 | btn1.backgroundColor = [UIColor redColor]; |
| 58 | [btn1 setTitle:@"下一个" forState:UIControlStateNormal]; | 58 | [btn1 setTitle:@"下一个" forState:UIControlStateNormal]; |
| 59 | [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | 59 | [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
| @@ -62,12 +62,22 @@ | @@ -62,12 +62,22 @@ | ||
| 62 | 62 | ||
| 63 | UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom]; | 63 | UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom]; |
| 64 | btn2.frame = CGRectMake(0, 0, 100, 50); | 64 | btn2.frame = CGRectMake(0, 0, 100, 50); |
| 65 | - btn2.center = CGPointMake(self.view.center.x, self.view.center.y+50); | 65 | + btn2.center = CGPointMake(self.view.center.x, self.view.center.y); |
| 66 | btn2.backgroundColor = [UIColor redColor]; | 66 | btn2.backgroundColor = [UIColor redColor]; |
| 67 | - [btn2 setTitle:@"返回" forState:UIControlStateNormal]; | 67 | + [btn2 setTitle:@"切换码率" forState:UIControlStateNormal]; |
| 68 | [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | 68 | [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
| 69 | [btn2 addTarget:self action:@selector(btnDidClicked2) forControlEvents:UIControlEventTouchUpInside]; | 69 | [btn2 addTarget:self action:@selector(btnDidClicked2) forControlEvents:UIControlEventTouchUpInside]; |
| 70 | [self.view addSubview:btn2]; | 70 | [self.view addSubview:btn2]; |
| 71 | + | ||
| 72 | + UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
| 73 | + btn3.frame = CGRectMake(0, 0, 100, 50); | ||
| 74 | + btn3.center = CGPointMake(self.view.center.x, self.view.center.y+120); | ||
| 75 | + btn3.backgroundColor = [UIColor redColor]; | ||
| 76 | + [btn3 setTitle:@"返回" forState:UIControlStateNormal]; | ||
| 77 | + [btn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | ||
| 78 | + [btn3 addTarget:self action:@selector(btnDidClicked3) forControlEvents:UIControlEventTouchUpInside]; | ||
| 79 | + [self.view addSubview:btn3]; | ||
| 80 | + | ||
| 71 | // CNLivePlayerDownloader *dowa = [[CNLivePlayerDownloader alloc]initWithUrlString:@"http://wideo02.cnlive.com/video/data1/2017/0423/206473/800/c8ff347048414b7295cef882f8361073_206473_800.m3u8" progressBlock:^(float progress) { | 81 | // CNLivePlayerDownloader *dowa = [[CNLivePlayerDownloader alloc]initWithUrlString:@"http://wideo02.cnlive.com/video/data1/2017/0423/206473/800/c8ff347048414b7295cef882f8361073_206473_800.m3u8" progressBlock:^(float progress) { |
| 72 | // NSLog(@"缓存进度中%f",progress); | 82 | // NSLog(@"缓存进度中%f",progress); |
| 73 | // }]; | 83 | // }]; |
| @@ -95,25 +105,28 @@ | @@ -95,25 +105,28 @@ | ||
| 95 | 105 | ||
| 96 | - (void)btnDidClicked1{ | 106 | - (void)btnDidClicked1{ |
| 97 | __weak typeof(self) weakSelf = self; | 107 | __weak typeof(self) weakSelf = self; |
| 98 | -// [_player setPlayerWithContentId:@"1066_716fabeaafb64236b60ecf74167c5c96" type:CNLivePlayerVod authSuccess:^{ | ||
| 99 | -// __strong typeof(self) strongSelf = weakSelf; | ||
| 100 | -// [strongSelf.player prepareToPlay]; | ||
| 101 | -// | ||
| 102 | -// } authFailure:^(NSDictionary * _Nonnull errorInfo) { | ||
| 103 | -// | ||
| 104 | -// }]; | ||
| 105 | - NSLog(@"当时已播放的时间是:%f",self.player.currentPlaybackTime); | 108 | + [_player setPlayerWithContentId:@"1066_716fabeaafb64236b60ecf74167c5c96" type:CNLivePlayerVod authSuccess:^{ |
| 109 | + __strong typeof(self) strongSelf = weakSelf; | ||
| 110 | + [strongSelf.player prepareToPlay]; | ||
| 111 | + | ||
| 112 | + } authFailure:^(NSDictionary * _Nonnull errorInfo) { | ||
| 113 | + | ||
| 114 | + }]; | ||
| 115 | + | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +- (void)btnDidClicked2{ | ||
| 119 | + __weak typeof(self) weakSelf = self; | ||
| 106 | [_player setPlayerWithContentId:nil rate:@"4" authSuccess:^{ | 120 | [_player setPlayerWithContentId:nil rate:@"4" authSuccess:^{ |
| 107 | __strong typeof(self) strongSelf = weakSelf; | 121 | __strong typeof(self) strongSelf = weakSelf; |
| 108 | [strongSelf.player prepareToPlay]; | 122 | [strongSelf.player prepareToPlay]; |
| 109 | - strongSelf.player.currentPlaybackTime = 10; | ||
| 110 | } authFailure:^(NSDictionary * _Nonnull errorInfo) { | 123 | } authFailure:^(NSDictionary * _Nonnull errorInfo) { |
| 111 | 124 | ||
| 112 | }]; | 125 | }]; |
| 113 | - | 126 | + |
| 114 | } | 127 | } |
| 115 | 128 | ||
| 116 | -- (void)btnDidClicked2{ | 129 | +- (void)btnDidClicked3{ |
| 117 | [self dismissViewControllerAnimated:YES completion:nil]; | 130 | [self dismissViewControllerAnimated:YES completion:nil]; |
| 118 | 131 | ||
| 119 | } | 132 | } |
Example/CNLivePlayer/CNLiveViewController.m
| @@ -40,6 +40,13 @@ | @@ -40,6 +40,13 @@ | ||
| 40 | [btn2 addTarget:self action:@selector(btnDidClicked2) forControlEvents:UIControlEventTouchUpInside]; | 40 | [btn2 addTarget:self action:@selector(btnDidClicked2) forControlEvents:UIControlEventTouchUpInside]; |
| 41 | [self.view addSubview:btn2]; | 41 | [self.view addSubview:btn2]; |
| 42 | 42 | ||
| 43 | + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight([UIScreen mainScreen].bounds)-80, CGRectGetWidth(self.view.frame), 30)]; | ||
| 44 | + label.text = @"北京中投视讯文化传媒股份有限公司"; | ||
| 45 | + label.font = [UIFont systemFontOfSize:16]; | ||
| 46 | + label.textAlignment = NSTextAlignmentCenter; | ||
| 47 | + [self.view addSubview:label]; | ||
| 48 | + | ||
| 49 | + | ||
| 43 | } | 50 | } |
| 44 | - (void)btnDidClicked1{ | 51 | - (void)btnDidClicked1{ |
| 45 | [self presentViewController:[CNLivePlayerController new] animated:YES completion:nil]; | 52 | [self presentViewController:[CNLivePlayerController new] animated:YES completion:nil]; |