Commit 63ba83eea591e6477e8966631773cacf67fcbed0
1 parent
426f0dc6
修改
Showing
6 changed files
with
62 additions
and
35 deletions
LiveVideoCloud/Classes/Sections/LiveSections/Controller/LVCLiveViewController.m
| ... | ... | @@ -37,7 +37,7 @@ |
| 37 | 37 | |
| 38 | 38 | @property (nonatomic, strong) UIButton *openFlashButton; |
| 39 | 39 | |
| 40 | -@property (nonatomic ,strong) LiveBaseView * _Nullable liveBaseView; | |
| 40 | +@property (nonatomic ,strong) LiveBaseView * _Nullable liveBaseView; | |
| 41 | 41 | |
| 42 | 42 | @property (nonatomic, strong) LVCUGCLiveEndView *endView; |
| 43 | 43 | |
| ... | ... | @@ -50,18 +50,20 @@ |
| 50 | 50 | |
| 51 | 51 | self.navigationController.delegate = self; |
| 52 | 52 | self.view.backgroundColor = [UIColor whiteColor]; |
| 53 | - [self.view addSubview:self.quitButton]; | |
| 54 | 53 | [self verifyLiveAuthority]; |
| 55 | 54 | } |
| 56 | 55 | |
| 57 | 56 | #pragma mark - 验证是否有主播权限 |
| 58 | 57 | - (void)verifyLiveAuthority { |
| 59 | 58 | |
| 59 | + [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear]; | |
| 60 | + [SVProgressHUD showWithStatus:@"正在加载..."]; | |
| 60 | 61 | [LVCVerifyLiveAuthService verifyLiveAuthWithHandler:^(id data, NSError *error) { |
| 61 | 62 | |
| 63 | + [SVProgressHUD dismiss]; | |
| 62 | 64 | if (error) { |
| 63 | 65 | NSLog(@"失败===>error:%@",error); |
| 64 | - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"抱歉, 鉴权失败~ "] delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil]; | |
| 66 | + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"抱歉, 鉴权失败~ "] delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil]; | |
| 65 | 67 | alert.tag = 1005; |
| 66 | 68 | [alert show]; |
| 67 | 69 | |
| ... | ... | @@ -87,22 +89,28 @@ |
| 87 | 89 | //开始推流 |
| 88 | 90 | [self.view addSubview:self.captureView]; |
| 89 | 91 | [self.view addSubview:self.prepareView]; |
| 92 | + [self.view addSubview:self.quitButton]; | |
| 90 | 93 | [self.view addSubview:self.changeCameraButton]; |
| 91 | 94 | [self.view addSubview:self.openFilterButton]; |
| 92 | 95 | [self.view addSubview:self.openFlashButton]; |
| 93 | 96 | [self.view addSubview:self.filterView]; |
| 94 | 97 | |
| 95 | 98 | // 初始化推流 |
| 99 | + // 生成随机活动号 | |
| 96 | 100 | NSInteger time = [[NSDate date] timeIntervalSince1970]; |
| 97 | 101 | NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; |
| 98 | 102 | NSString *random = [NSString stringWithFormat:@"%d%d%d%d%d",arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9]; |
| 99 | 103 | NSString *activityId = [NSString stringWithFormat:@"%@%@",timeString,random]; |
| 100 | 104 | |
| 101 | - _kitCN = [[CNLiveGPUStreamerKit alloc] initWithDefaultConfigWithActivityId:activityId channelId:@"iOStest" isHorizontalScreen:@"0"]; | |
| 105 | + // 主播ID | |
| 106 | + NSString *channelId = data[@"channelId"]; | |
| 107 | + NSString *channelName = data[@"channelName"]; | |
| 108 | + NSString *coverImgUrl = data[@"coverImgUrl"]; | |
| 109 | + _kitCN = [[CNLiveGPUStreamerKit alloc] initWithDefaultConfigWithActivityId:activityId channelId:channelId isHorizontalScreen:@"0"]; | |
| 102 | 110 | // 封面图 |
| 103 | - _kitCN.coverImgUrl = @"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=169300069,2234409601&fm=21&gp=0.jpg"; | |
| 111 | + _kitCN.coverImgUrl = coverImgUrl; | |
| 104 | 112 | // 昵称 头像 |
| 105 | - NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"我的名字好长啊", @"name", @"http://www.qq745.com/uploads/allimg/150318/1-15031PGF8-51.jpg", @"iconUrl", nil]; | |
| 113 | + NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:channelName, @"name", [UserInformationModel manager].faceUrl, @"iconUrl", nil]; | |
| 106 | 114 | _kitCN.extensions = [self dictionaryToJson:userInfo]; |
| 107 | 115 | |
| 108 | 116 | // 设置推流配置 |
| ... | ... | @@ -115,7 +123,7 @@ |
| 115 | 123 | [self.captureView addGestureRecognizer:singleRecognizer]; |
| 116 | 124 | |
| 117 | 125 | } else { //禁用 |
| 118 | - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉, 您没有权限~" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil]; | |
| 126 | + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉, 您没有权限~" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil]; | |
| 119 | 127 | alert.tag = 1004; |
| 120 | 128 | [alert show]; |
| 121 | 129 | } |
| ... | ... | @@ -335,22 +343,23 @@ |
| 335 | 343 | |
| 336 | 344 | if ( _kitCN.captureState == CNLiveCaptureStateIdle){ |
| 337 | 345 | //初始化时状态为空闲 |
| 338 | - | |
| 346 | + NSLog(@"---------CNLiveCaptureStateIdle"); | |
| 339 | 347 | return; |
| 340 | 348 | } |
| 341 | 349 | else if (_kitCN.captureState == CNLiveCaptureStateCapturing ) { |
| 342 | 350 | //设备工作中 |
| 343 | - | |
| 351 | + NSLog(@"---------CNLiveCaptureStateCapturing"); | |
| 344 | 352 | return; |
| 345 | 353 | } |
| 346 | 354 | else if (_kitCN.captureState == CNLiveCaptureStateClosingCapture ) { |
| 347 | 355 | //关闭采集设备中 |
| 348 | - | |
| 356 | + NSLog(@"---------CNLiveCaptureStateClosingCapture"); | |
| 349 | 357 | return; |
| 350 | 358 | } |
| 351 | 359 | else if (_kitCN.captureState == CNLiveCaptureStateDevAuthDenied ) { |
| 352 | 360 | //设备授权被拒绝 |
| 353 | 361 | NSLog(@"---------CNLiveCaptureStateDevAuthDenied"); |
| 362 | + [self toast:@"设备未授权,请授权~"]; | |
| 354 | 363 | |
| 355 | 364 | return; |
| 356 | 365 | } |
| ... | ... | @@ -374,24 +383,17 @@ |
| 374 | 383 | NSLog(@"---------CNLiveStreamStateIdle"); |
| 375 | 384 | } |
| 376 | 385 | |
| 377 | - if (_kitCN.streamState == CNLiveStreamStateConnected) { | |
| 378 | - | |
| 379 | - NSLog(@"---------CNLiveStreamStateConnected"); | |
| 380 | - } | |
| 381 | - | |
| 382 | 386 | if (_kitCN.streamState == CNLiveStreamStateConnecting) { |
| 383 | 387 | |
| 384 | 388 | NSLog(@"---------CNLiveStreamStateConnecting"); |
| 385 | 389 | } |
| 386 | 390 | |
| 387 | - //推流出错 | |
| 388 | - if (_kitCN.streamState == CNLiveStreamStateError) { | |
| 391 | + if (_kitCN.streamState == CNLiveStreamStateConnected) { | |
| 389 | 392 | |
| 390 | - NSLog(@"---------CNLiveStreamStateError"); | |
| 391 | - [self onStreamError]; | |
| 393 | + NSLog(@"---------CNLiveStreamStateConnected"); | |
| 392 | 394 | } |
| 393 | 395 | |
| 394 | - //断开推流 | |
| 396 | + //断开推流中 | |
| 395 | 397 | if ( _kitCN.streamState == CNLiveStreamStateDisconnecting) { |
| 396 | 398 | |
| 397 | 399 | NSLog(@"---------CNLiveStreamStateDisconnecting"); |
| ... | ... | @@ -402,6 +404,20 @@ |
| 402 | 404 | |
| 403 | 405 | NSLog(@"---------CNLiveStopStreamSuccess"); |
| 404 | 406 | } |
| 407 | + | |
| 408 | + //结束推流失败 | |
| 409 | + if ( _kitCN.streamState == CNLiveStopStreamFailure) { | |
| 410 | + | |
| 411 | + NSLog(@"---------CNLiveStopStreamFailure"); | |
| 412 | + } | |
| 413 | + | |
| 414 | + //推流出错 | |
| 415 | + if (_kitCN.streamState == CNLiveStreamStateError) { | |
| 416 | + | |
| 417 | + NSLog(@"---------CNLiveStreamStateError"); | |
| 418 | + [self onStreamError]; | |
| 419 | + } | |
| 420 | + | |
| 405 | 421 | } |
| 406 | 422 | |
| 407 | 423 | - (void)onStreamError { // 推流失败 |
| ... | ... | @@ -425,19 +441,15 @@ |
| 425 | 441 | else if ( CNLiveStreamErrorCode_ABNORMAL == err) { |
| 426 | 442 | |
| 427 | 443 | [self toast:@"推流异常中断~~"]; |
| 444 | + [self tryReconnect]; | |
| 428 | 445 | |
| 429 | 446 | } else if (err == CNLiveStreamErrorCode_CODEC_OPEN_FAILED) { |
| 430 | 447 | NSLog(@"video codec open failed, try software codec"); |
| 431 | 448 | // 换个编码类型重新尝试 |
| 432 | 449 | _kitCN.streamerBase.videoCodec = CNLiveVideoCodec_VT264; |
| 433 | 450 | [self tryReconnect]; |
| 434 | - } | |
| 435 | - else { | |
| 436 | 451 | |
| 437 | - } | |
| 438 | - | |
| 439 | - // 断网重连 | |
| 440 | - if (err == CNLiveStreamErrorCode_CONNECT_BREAK || err == CNLiveStreamErrorCode_AV_SYNC_ERROR) { | |
| 452 | + } else if (err == CNLiveStreamErrorCode_CONNECT_BREAK || err == CNLiveStreamErrorCode_AV_SYNC_ERROR) { | |
| 441 | 453 | [self tryReconnect]; |
| 442 | 454 | } |
| 443 | 455 | |
| ... | ... | @@ -595,6 +607,7 @@ |
| 595 | 607 | } |
| 596 | 608 | |
| 597 | 609 | #pragma mark - Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 610 | + | |
| 598 | 611 | - (void)addObservers { |
| 599 | 612 | |
| 600 | 613 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureStateChange) name:CNLiveCaptureStateDidChangeNotification object:nil]; | ... | ... |
LiveVideoCloud/Classes/Sections/LiveSections/View/LVCUGCLiveEndView.m
| ... | ... | @@ -39,8 +39,10 @@ |
| 39 | 39 | - (UIImageView *)iconView { |
| 40 | 40 | |
| 41 | 41 | if (!_iconView) { |
| 42 | - NSString *path = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 43 | - UIImage *image = [UIImage imageWithContentsOfFile:path]; | |
| 42 | +// NSString *path = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 43 | +// UIImage *image = [UIImage imageWithContentsOfFile:path]; | |
| 44 | + UIImage *image = [UIImage imageWithData:[NSData | |
| 45 | + dataWithContentsOfURL:[NSURL URLWithString:[UserInformationModel manager].faceUrl]]]; | |
| 44 | 46 | _iconView = [[UIImageView alloc] initWithImage:image]; |
| 45 | 47 | _iconView.frame = CGRectMake((selfLength - 50) * 0.5, 20, 50, 50); |
| 46 | 48 | _iconView.layer.cornerRadius = 25; | ... | ... |
LiveVideoCloud/Classes/Sections/LiveSections/View/LVCUGCLivePrepareView.m
| ... | ... | @@ -35,8 +35,11 @@ |
| 35 | 35 | - (UIImageView *)iconView { |
| 36 | 36 | |
| 37 | 37 | if (!_iconView) { |
| 38 | - NSString *path = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 39 | - UIImage *image = [UIImage imageWithContentsOfFile:path]; | |
| 38 | +// NSString *path = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 39 | +// UIImage *image = [UIImage imageWithContentsOfFile:path]; | |
| 40 | + | |
| 41 | + UIImage *image = [UIImage imageWithData:[NSData | |
| 42 | + dataWithContentsOfURL:[NSURL URLWithString:[UserInformationModel manager].faceUrl]]]; | |
| 40 | 43 | _iconView = [[UIImageView alloc] initWithImage:image]; |
| 41 | 44 | _iconView.frame = CGRectMake(10, SCREEN_HEIGHT * 0.35, 90, 90); |
| 42 | 45 | _iconView.layer.cornerRadius = 45; | ... | ... |
LiveVideoCloud/Classes/Sections/homeSections/Controller/LVCUGCLiveListView.m
| ... | ... | @@ -62,7 +62,7 @@ static NSString *cellId = @"cellId"; |
| 62 | 62 | } |
| 63 | 63 | return ; |
| 64 | 64 | } |
| 65 | - NSLog(@"成功===>data%@",data); | |
| 65 | +// NSLog(@"成功===>data%@",data); | |
| 66 | 66 | |
| 67 | 67 | LVCUGCLiveListModel *model = [LVCUGCLiveListModel modelWithDic:data]; |
| 68 | 68 | _arrayM = model.activityList.mutableCopy; |
| ... | ... | @@ -91,6 +91,9 @@ static NSString *cellId = @"cellId"; |
| 91 | 91 | LVCUGCLivePlayerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; |
| 92 | 92 | |
| 93 | 93 | LVCUGCLivePlayerModel *model = _arrayM[indexPath.row]; |
| 94 | + if (indexPath.row == 0) { | |
| 95 | + NSLog(@"%@",model.extensionName); | |
| 96 | + } | |
| 94 | 97 | cell.model = model; |
| 95 | 98 | |
| 96 | 99 | return cell; | ... | ... |
LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCBackgroundView.m
| ... | ... | @@ -77,8 +77,10 @@ |
| 77 | 77 | - (UIImageView *)iconView { |
| 78 | 78 | |
| 79 | 79 | if (!_iconView) { |
| 80 | - NSString *path = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 81 | - UIImage *image = [UIImage imageWithContentsOfFile:path]; | |
| 80 | +// NSString *path = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 81 | +// UIImage *image = [UIImage imageWithContentsOfFile:path]; | |
| 82 | + UIImage *image = [UIImage imageWithData:[NSData | |
| 83 | + dataWithContentsOfURL:[NSURL URLWithString:[UserInformationModel manager].faceUrl]]]; | |
| 82 | 84 | _iconView = [[UIImageView alloc] initWithImage:image]; |
| 83 | 85 | _iconView.frame = CGRectMake((SCREEN_WIDTH - 100) * 0.5, SCREEN_HEIGHT * 0.2, 100, 100); |
| 84 | 86 | _iconView.layer.cornerRadius = 50; | ... | ... |
LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCLivePlayerCell.m
| ... | ... | @@ -63,9 +63,13 @@ |
| 63 | 63 | |
| 64 | 64 | if (model.extensionName.length > 0) { |
| 65 | 65 | _nameLabel.text = model.extensionName; |
| 66 | + } else { | |
| 67 | + _nameLabel.text = @"我的昵称"; | |
| 66 | 68 | } |
| 67 | - NSString *iconPath = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 68 | - UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath]; | |
| 69 | +// NSString *iconPath = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"]; | |
| 70 | +// UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath]; | |
| 71 | + UIImage *iconImage = [UIImage imageWithData:[NSData | |
| 72 | + dataWithContentsOfURL:[NSURL URLWithString:[UserInformationModel manager].faceUrl]]]; | |
| 69 | 73 | [_iconView sd_setImageWithURL:[NSURL URLWithString:model.extensionIcon] placeholderImage:iconImage]; |
| 70 | 74 | |
| 71 | 75 | switch ([model.activityStatus intValue]) { | ... | ... |