Commit 63ba83eea591e6477e8966631773cacf67fcbed0

Authored by 王军波
1 parent 426f0dc6

修改

LiveVideoCloud/Classes/Sections/LiveSections/Controller/LVCLiveViewController.m
@@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
37 37
38 @property (nonatomic, strong) UIButton *openFlashButton; 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 @property (nonatomic, strong) LVCUGCLiveEndView *endView; 42 @property (nonatomic, strong) LVCUGCLiveEndView *endView;
43 43
@@ -50,18 +50,20 @@ @@ -50,18 +50,20 @@
50 50
51 self.navigationController.delegate = self; 51 self.navigationController.delegate = self;
52 self.view.backgroundColor = [UIColor whiteColor]; 52 self.view.backgroundColor = [UIColor whiteColor];
53 - [self.view addSubview:self.quitButton];  
54 [self verifyLiveAuthority]; 53 [self verifyLiveAuthority];
55 } 54 }
56 55
57 #pragma mark - 验证是否有主播权限 56 #pragma mark - 验证是否有主播权限
58 - (void)verifyLiveAuthority { 57 - (void)verifyLiveAuthority {
59 58
  59 + [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
  60 + [SVProgressHUD showWithStatus:@"正在加载..."];
60 [LVCVerifyLiveAuthService verifyLiveAuthWithHandler:^(id data, NSError *error) { 61 [LVCVerifyLiveAuthService verifyLiveAuthWithHandler:^(id data, NSError *error) {
61 62
  63 + [SVProgressHUD dismiss];
62 if (error) { 64 if (error) {
63 NSLog(@"失败===>error:%@",error); 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 alert.tag = 1005; 67 alert.tag = 1005;
66 [alert show]; 68 [alert show];
67 69
@@ -87,22 +89,28 @@ @@ -87,22 +89,28 @@
87 //开始推流 89 //开始推流
88 [self.view addSubview:self.captureView]; 90 [self.view addSubview:self.captureView];
89 [self.view addSubview:self.prepareView]; 91 [self.view addSubview:self.prepareView];
  92 + [self.view addSubview:self.quitButton];
90 [self.view addSubview:self.changeCameraButton]; 93 [self.view addSubview:self.changeCameraButton];
91 [self.view addSubview:self.openFilterButton]; 94 [self.view addSubview:self.openFilterButton];
92 [self.view addSubview:self.openFlashButton]; 95 [self.view addSubview:self.openFlashButton];
93 [self.view addSubview:self.filterView]; 96 [self.view addSubview:self.filterView];
94 97
95 // 初始化推流 98 // 初始化推流
  99 + // 生成随机活动号
96 NSInteger time = [[NSDate date] timeIntervalSince1970]; 100 NSInteger time = [[NSDate date] timeIntervalSince1970];
97 NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; 101 NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
98 NSString *random = [NSString stringWithFormat:@"%d%d%d%d%d",arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9]; 102 NSString *random = [NSString stringWithFormat:@"%d%d%d%d%d",arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9];
99 NSString *activityId = [NSString stringWithFormat:@"%@%@",timeString,random]; 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 _kitCN.extensions = [self dictionaryToJson:userInfo]; 114 _kitCN.extensions = [self dictionaryToJson:userInfo];
107 115
108 // 设置推流配置 116 // 设置推流配置
@@ -115,7 +123,7 @@ @@ -115,7 +123,7 @@
115 [self.captureView addGestureRecognizer:singleRecognizer]; 123 [self.captureView addGestureRecognizer:singleRecognizer];
116 124
117 } else { //禁用 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 alert.tag = 1004; 127 alert.tag = 1004;
120 [alert show]; 128 [alert show];
121 } 129 }
@@ -335,22 +343,23 @@ @@ -335,22 +343,23 @@
335 343
336 if ( _kitCN.captureState == CNLiveCaptureStateIdle){ 344 if ( _kitCN.captureState == CNLiveCaptureStateIdle){
337 //初始化时状态为空闲 345 //初始化时状态为空闲
338 - 346 + NSLog(@"---------CNLiveCaptureStateIdle");
339 return; 347 return;
340 } 348 }
341 else if (_kitCN.captureState == CNLiveCaptureStateCapturing ) { 349 else if (_kitCN.captureState == CNLiveCaptureStateCapturing ) {
342 //设备工作中 350 //设备工作中
343 - 351 + NSLog(@"---------CNLiveCaptureStateCapturing");
344 return; 352 return;
345 } 353 }
346 else if (_kitCN.captureState == CNLiveCaptureStateClosingCapture ) { 354 else if (_kitCN.captureState == CNLiveCaptureStateClosingCapture ) {
347 //关闭采集设备中 355 //关闭采集设备中
348 - 356 + NSLog(@"---------CNLiveCaptureStateClosingCapture");
349 return; 357 return;
350 } 358 }
351 else if (_kitCN.captureState == CNLiveCaptureStateDevAuthDenied ) { 359 else if (_kitCN.captureState == CNLiveCaptureStateDevAuthDenied ) {
352 //设备授权被拒绝 360 //设备授权被拒绝
353 NSLog(@"---------CNLiveCaptureStateDevAuthDenied"); 361 NSLog(@"---------CNLiveCaptureStateDevAuthDenied");
  362 + [self toast:@"设备未授权,请授权~"];
354 363
355 return; 364 return;
356 } 365 }
@@ -374,24 +383,17 @@ @@ -374,24 +383,17 @@
374 NSLog(@"---------CNLiveStreamStateIdle"); 383 NSLog(@"---------CNLiveStreamStateIdle");
375 } 384 }
376 385
377 - if (_kitCN.streamState == CNLiveStreamStateConnected) {  
378 -  
379 - NSLog(@"---------CNLiveStreamStateConnected");  
380 - }  
381 -  
382 if (_kitCN.streamState == CNLiveStreamStateConnecting) { 386 if (_kitCN.streamState == CNLiveStreamStateConnecting) {
383 387
384 NSLog(@"---------CNLiveStreamStateConnecting"); 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 if ( _kitCN.streamState == CNLiveStreamStateDisconnecting) { 397 if ( _kitCN.streamState == CNLiveStreamStateDisconnecting) {
396 398
397 NSLog(@"---------CNLiveStreamStateDisconnecting"); 399 NSLog(@"---------CNLiveStreamStateDisconnecting");
@@ -402,6 +404,20 @@ @@ -402,6 +404,20 @@
402 404
403 NSLog(@"---------CNLiveStopStreamSuccess"); 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 - (void)onStreamError { // 推流失败 423 - (void)onStreamError { // 推流失败
@@ -425,19 +441,15 @@ @@ -425,19 +441,15 @@
425 else if ( CNLiveStreamErrorCode_ABNORMAL == err) { 441 else if ( CNLiveStreamErrorCode_ABNORMAL == err) {
426 442
427 [self toast:@"推流异常中断~~"]; 443 [self toast:@"推流异常中断~~"];
  444 + [self tryReconnect];
428 445
429 } else if (err == CNLiveStreamErrorCode_CODEC_OPEN_FAILED) { 446 } else if (err == CNLiveStreamErrorCode_CODEC_OPEN_FAILED) {
430 NSLog(@"video codec open failed, try software codec"); 447 NSLog(@"video codec open failed, try software codec");
431 // 换个编码类型重新尝试 448 // 换个编码类型重新尝试
432 _kitCN.streamerBase.videoCodec = CNLiveVideoCodec_VT264; 449 _kitCN.streamerBase.videoCodec = CNLiveVideoCodec_VT264;
433 [self tryReconnect]; 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 [self tryReconnect]; 453 [self tryReconnect];
442 } 454 }
443 455
@@ -595,6 +607,7 @@ @@ -595,6 +607,7 @@
595 } 607 }
596 608
597 #pragma mark - Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 609 #pragma mark - Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  610 +
598 - (void)addObservers { 611 - (void)addObservers {
599 612
600 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureStateChange) name:CNLiveCaptureStateDidChangeNotification object:nil]; 613 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureStateChange) name:CNLiveCaptureStateDidChangeNotification object:nil];
LiveVideoCloud/Classes/Sections/LiveSections/View/LVCUGCLiveEndView.m
@@ -39,8 +39,10 @@ @@ -39,8 +39,10 @@
39 - (UIImageView *)iconView { 39 - (UIImageView *)iconView {
40 40
41 if (!_iconView) { 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 _iconView = [[UIImageView alloc] initWithImage:image]; 46 _iconView = [[UIImageView alloc] initWithImage:image];
45 _iconView.frame = CGRectMake((selfLength - 50) * 0.5, 20, 50, 50); 47 _iconView.frame = CGRectMake((selfLength - 50) * 0.5, 20, 50, 50);
46 _iconView.layer.cornerRadius = 25; 48 _iconView.layer.cornerRadius = 25;
LiveVideoCloud/Classes/Sections/LiveSections/View/LVCUGCLivePrepareView.m
@@ -35,8 +35,11 @@ @@ -35,8 +35,11 @@
35 - (UIImageView *)iconView { 35 - (UIImageView *)iconView {
36 36
37 if (!_iconView) { 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 _iconView = [[UIImageView alloc] initWithImage:image]; 43 _iconView = [[UIImageView alloc] initWithImage:image];
41 _iconView.frame = CGRectMake(10, SCREEN_HEIGHT * 0.35, 90, 90); 44 _iconView.frame = CGRectMake(10, SCREEN_HEIGHT * 0.35, 90, 90);
42 _iconView.layer.cornerRadius = 45; 45 _iconView.layer.cornerRadius = 45;
LiveVideoCloud/Classes/Sections/homeSections/Controller/LVCUGCLiveListView.m
@@ -62,7 +62,7 @@ static NSString *cellId = @"cellId"; @@ -62,7 +62,7 @@ static NSString *cellId = @"cellId";
62 } 62 }
63 return ; 63 return ;
64 } 64 }
65 - NSLog(@"成功===>data%@",data); 65 +// NSLog(@"成功===>data%@",data);
66 66
67 LVCUGCLiveListModel *model = [LVCUGCLiveListModel modelWithDic:data]; 67 LVCUGCLiveListModel *model = [LVCUGCLiveListModel modelWithDic:data];
68 _arrayM = model.activityList.mutableCopy; 68 _arrayM = model.activityList.mutableCopy;
@@ -91,6 +91,9 @@ static NSString *cellId = @"cellId"; @@ -91,6 +91,9 @@ static NSString *cellId = @"cellId";
91 LVCUGCLivePlayerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; 91 LVCUGCLivePlayerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
92 92
93 LVCUGCLivePlayerModel *model = _arrayM[indexPath.row]; 93 LVCUGCLivePlayerModel *model = _arrayM[indexPath.row];
  94 + if (indexPath.row == 0) {
  95 + NSLog(@"%@",model.extensionName);
  96 + }
94 cell.model = model; 97 cell.model = model;
95 98
96 return cell; 99 return cell;
LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCBackgroundView.m
@@ -77,8 +77,10 @@ @@ -77,8 +77,10 @@
77 - (UIImageView *)iconView { 77 - (UIImageView *)iconView {
78 78
79 if (!_iconView) { 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 _iconView = [[UIImageView alloc] initWithImage:image]; 84 _iconView = [[UIImageView alloc] initWithImage:image];
83 _iconView.frame = CGRectMake((SCREEN_WIDTH - 100) * 0.5, SCREEN_HEIGHT * 0.2, 100, 100); 85 _iconView.frame = CGRectMake((SCREEN_WIDTH - 100) * 0.5, SCREEN_HEIGHT * 0.2, 100, 100);
84 _iconView.layer.cornerRadius = 50; 86 _iconView.layer.cornerRadius = 50;
LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCLivePlayerCell.m
@@ -63,9 +63,13 @@ @@ -63,9 +63,13 @@
63 63
64 if (model.extensionName.length > 0) { 64 if (model.extensionName.length > 0) {
65 _nameLabel.text = model.extensionName; 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 [_iconView sd_setImageWithURL:[NSURL URLWithString:model.extensionIcon] placeholderImage:iconImage]; 73 [_iconView sd_setImageWithURL:[NSURL URLWithString:model.extensionIcon] placeholderImage:iconImage];
70 74
71 switch ([model.activityStatus intValue]) { 75 switch ([model.activityStatus intValue]) {