Commit b9af0a70b69c8fbc8cba01b1b7f90512c742a353
1 parent
54dda7ae
上下切换及加载视图
Showing
5 changed files
with
102 additions
and
57 deletions
LiveVideoCloud/LiveVideoCloud/AppDelegate/AppDelegate.m
| ... | ... | @@ -9,6 +9,9 @@ |
| 9 | 9 | #import "AppDelegate.h" |
| 10 | 10 | #import "ZXTabBarController.h" |
| 11 | 11 | |
| 12 | +#define KAppId @"60_irn9edco29" | |
| 13 | +#define KAppKey @"69fe70bda67e059286ad509d9f5377f815955645b52f94" | |
| 14 | + | |
| 12 | 15 | @interface AppDelegate () |
| 13 | 16 | |
| 14 | 17 | @end |
| ... | ... | @@ -23,7 +26,7 @@ |
| 23 | 26 | self.window.rootViewController = [[ZXTabBarController alloc] init]; |
| 24 | 27 | |
| 25 | 28 | //初始化直播SDK |
| 26 | -// [[CNLiveWebcastManager manager] initWithAppId:AppId appKey:AppKey]; | |
| 29 | + [[CNLiveWebcastManager manager] initWithAppId:KAppId appKey:KAppKey]; | |
| 27 | 30 | |
| 28 | 31 | //初始化聊天SDK并连接服务器 |
| 29 | 32 | [[CNLiveChatManager sharedCNLiveChatManager] initWithAppKey:AppKey appId:AppId]; | ... | ... |
LiveVideoCloud/LiveVideoCloud/Classes/Sections/LiveSections/Controller/LVCLiveViewController.m
| ... | ... | @@ -14,10 +14,6 @@ |
| 14 | 14 | #import "LiveBaseView.h" |
| 15 | 15 | #import "LVCUGCLiveEndView.h" |
| 16 | 16 | |
| 17 | - | |
| 18 | -#define KAppId @"60_irn9edco29" | |
| 19 | -#define KAppKey @"69fe70bda67e059286ad509d9f5377f815955645b52f94" | |
| 20 | - | |
| 21 | 17 | @interface LVCLiveViewController ()<UIGestureRecognizerDelegate> { |
| 22 | 18 | |
| 23 | 19 | BOOL _isStreaming; |
| ... | ... | @@ -60,8 +56,6 @@ |
| 60 | 56 | [self.view addSubview:self.openFilterButton]; |
| 61 | 57 | [self.view addSubview:self.openFlashButton]; |
| 62 | 58 | [self.view addSubview:self.filterView]; |
| 63 | - | |
| 64 | - [[CNLiveWebcastManager manager] initWithAppId:KAppId appKey:KAppKey]; | |
| 65 | 59 | |
| 66 | 60 | // 初始化推流 |
| 67 | 61 | NSString *activityId = [NSString stringWithFormat:@"%d%d%d%d%d",arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9]; |
| ... | ... | @@ -139,8 +133,8 @@ |
| 139 | 133 | [self.view insertSubview:self.liveBaseView atIndex:1]; |
| 140 | 134 | |
| 141 | 135 | } failure:^(NSDictionary *errorDic) { |
| 142 | - NSString *str=[[NSMutableString alloc] initWithData:errorDic[@"errorMessage"] encoding:NSUTF8StringEncoding]; | |
| 143 | - NSLog(@"%@",str); | |
| 136 | + //NSString *str=[[NSMutableString alloc] initWithData:errorDic[@"errorMessage"] encoding:NSUTF8StringEncoding]; | |
| 137 | + NSLog(@"%@",errorDic); | |
| 144 | 138 | [self toast:errorDic[@"errorMessage"]]; |
| 145 | 139 | }]; |
| 146 | 140 | } | ... | ... |
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/Controller/LVCUGCLivePlayerController.m
| ... | ... | @@ -19,6 +19,9 @@ |
| 19 | 19 | float _ThirdY; |
| 20 | 20 | UIView *_tempView; |
| 21 | 21 | UIPanGestureRecognizer *_pan; |
| 22 | + LVCUGCPlayerLoadingView *_firstLoadView; | |
| 23 | + LVCUGCPlayerLoadingView *_secondLoadView; | |
| 24 | + LVCUGCPlayerLoadingView *_thirdLoadView; | |
| 22 | 25 | } |
| 23 | 26 | |
| 24 | 27 | @property (nonatomic, strong) UIView *viewOne; |
| ... | ... | @@ -52,16 +55,15 @@ |
| 52 | 55 | |
| 53 | 56 | self.view.backgroundColor = [UIColor whiteColor]; |
| 54 | 57 | |
| 55 | - [self.view addSubview:_viewOne]; | |
| 56 | - [self.view addSubview:_viewSecond]; | |
| 57 | - [self.view addSubview:_viewThird]; | |
| 58 | + [self.view addSubview:self.viewOne]; | |
| 59 | + [self.view addSubview:self.viewSecond]; | |
| 60 | + [self.view addSubview:self.viewThird]; | |
| 58 | 61 | |
| 59 | 62 | _pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)]; |
| 60 | - [_viewSecond addGestureRecognizer:_pan]; | |
| 61 | 63 | |
| 62 | 64 | [self installMovieNotificationObservers]; |
| 63 | 65 | |
| 64 | - _player = [[CNLiveMoviePlayerController alloc] initLivePlayWithChannelId:@"60_iOStest" | |
| 66 | + _player = [[CNLiveMoviePlayerController alloc] initLivePlayWithChannelId:@"iOStest" | |
| 65 | 67 | authSuccess:^{ |
| 66 | 68 | |
| 67 | 69 | _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO; |
| ... | ... | @@ -70,6 +72,7 @@ |
| 70 | 72 | [_player prepareToPlay]; |
| 71 | 73 | [_viewSecond addSubview:_player.view]; |
| 72 | 74 | [_viewSecond sendSubviewToBack:_player.view]; |
| 75 | + [_player.view addGestureRecognizer:_pan]; | |
| 73 | 76 | |
| 74 | 77 | } authFailed:^(NSDictionary *errorInfo) { |
| 75 | 78 | NSLog(@"初始化直播播放器失败:%@", errorInfo); |
| ... | ... | @@ -87,7 +90,7 @@ |
| 87 | 90 | - (void)panGesture:(UIPanGestureRecognizer *)recognizer { |
| 88 | 91 | |
| 89 | 92 | CGPoint t = [recognizer translationInView:_viewSecond]; |
| 90 | - //NSLog(@"移动距离>>>>>>>>>>>>>>%f",t.y); | |
| 93 | + NSLog(@"移动距离>>>>>>>>>>>>>>%f",t.y); | |
| 91 | 94 | |
| 92 | 95 | _viewOne.frame = CGRectMake(0, _oneY + t.y, SCREEN_WIDTH, SCREEN_HEIGHT); |
| 93 | 96 | _viewSecond.frame = CGRectMake(0, _SecondY + t.y, SCREEN_WIDTH, SCREEN_HEIGHT); |
| ... | ... | @@ -113,14 +116,37 @@ |
| 113 | 116 | |
| 114 | 117 | } completion:^(BOOL finished) { |
| 115 | 118 | |
| 119 | + [_player.view removeFromSuperview]; | |
| 120 | + [_player stop]; | |
| 121 | + _player = nil; | |
| 122 | + // 停止后的视图,拿到自己的加载图来显示 | |
| 123 | + [_viewSecond addSubview:_secondLoadView]; | |
| 116 | 124 | |
| 117 | - [_viewSecond removeGestureRecognizer:_pan]; | |
| 118 | 125 | _viewThird.frame = CGRectMake(0, -SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT); |
| 119 | 126 | _tempView = _viewOne; |
| 120 | 127 | _viewOne = _viewThird; |
| 121 | 128 | _viewThird = _viewSecond; |
| 122 | 129 | _viewSecond = _tempView; |
| 123 | - [_viewSecond addGestureRecognizer:_pan]; | |
| 130 | + //往下滑 播放上一个 | |
| 131 | + _player = [[CNLiveMoviePlayerController alloc] initLivePlayWithChannelId:@"iOStest" | |
| 132 | + authSuccess:^{ | |
| 133 | + | |
| 134 | + _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO; | |
| 135 | + _player.view.frame = self.view.bounds; | |
| 136 | + _player.shouldAutoplay = YES; | |
| 137 | + [_player prepareToPlay]; | |
| 138 | + [_viewSecond addSubview:_player.view]; | |
| 139 | + [_viewSecond sendSubviewToBack:_player.view]; | |
| 140 | + [_player.view addGestureRecognizer:_pan]; | |
| 141 | + | |
| 142 | + } authFailed:^(NSDictionary *errorInfo) { | |
| 143 | + NSLog(@"初始化直播播放器失败:%@", errorInfo); | |
| 144 | + | |
| 145 | + } getAnchorStatusResult:^(BOOL result) { | |
| 146 | + | |
| 147 | + NSLog(@"-------------获取主播状态%d", result ? YES : NO); | |
| 148 | + | |
| 149 | + }]; | |
| 124 | 150 | |
| 125 | 151 | _oneY = _viewOne.frame.origin.y; |
| 126 | 152 | _SecondY = _viewSecond.frame.origin.y; |
| ... | ... | @@ -136,6 +162,12 @@ |
| 136 | 162 | |
| 137 | 163 | } completion:^(BOOL finished) { |
| 138 | 164 | |
| 165 | + [_player.view removeFromSuperview]; | |
| 166 | + [_player stop]; | |
| 167 | + _player = nil; | |
| 168 | + // 停止后的视图,拿到自己的加载图来显示 | |
| 169 | + [_viewSecond addSubview:_secondLoadView]; | |
| 170 | + | |
| 139 | 171 | [_viewSecond removeGestureRecognizer:_pan]; |
| 140 | 172 | _viewOne.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT); |
| 141 | 173 | _tempView = _viewOne; |
| ... | ... | @@ -143,6 +175,26 @@ |
| 143 | 175 | _viewSecond = _viewThird; |
| 144 | 176 | _viewThird = _tempView; |
| 145 | 177 | [_viewSecond addGestureRecognizer:_pan]; |
| 178 | + //往上滑 播放下一个 | |
| 179 | + _player = [[CNLiveMoviePlayerController alloc] initLivePlayWithChannelId:@"iOStest" | |
| 180 | + authSuccess:^{ | |
| 181 | + | |
| 182 | + _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO; | |
| 183 | + _player.view.frame = self.view.bounds; | |
| 184 | + _player.shouldAutoplay = YES; | |
| 185 | + [_player prepareToPlay]; | |
| 186 | + [_viewSecond addSubview:_player.view]; | |
| 187 | + [_viewSecond sendSubviewToBack:_player.view]; | |
| 188 | + [_player.view addGestureRecognizer:_pan]; | |
| 189 | + | |
| 190 | + } authFailed:^(NSDictionary *errorInfo) { | |
| 191 | + NSLog(@"初始化直播播放器失败:%@", errorInfo); | |
| 192 | + | |
| 193 | + } getAnchorStatusResult:^(BOOL result) { | |
| 194 | + | |
| 195 | + NSLog(@"-------------获取主播状态%d", result ? YES : NO); | |
| 196 | + | |
| 197 | + }]; | |
| 146 | 198 | |
| 147 | 199 | _oneY = _viewOne.frame.origin.y; |
| 148 | 200 | _SecondY = _viewSecond.frame.origin.y; |
| ... | ... | @@ -261,9 +313,14 @@ |
| 261 | 313 | { |
| 262 | 314 | if (_player) { |
| 263 | 315 | NSLog(@"isPreparedToPlay"); |
| 264 | - // if (_loadingView) { | |
| 265 | - // [_loadingView removeFromSuperview]; | |
| 266 | - // } | |
| 316 | + | |
| 317 | + if (_viewSecond.subviews.count>0) { | |
| 318 | + for (UIView *subViews in _viewSecond.subviews) { | |
| 319 | + if ([subViews isKindOfClass:[LVCUGCPlayerLoadingView class]]) { | |
| 320 | + [subViews removeFromSuperview]; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + } | |
| 267 | 324 | } |
| 268 | 325 | } |
| 269 | 326 | |
| ... | ... | @@ -322,35 +379,13 @@ |
| 322 | 379 | |
| 323 | 380 | } |
| 324 | 381 | |
| 325 | -#pragma mark - 移除通知 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 326 | -- (void)removeMovieNotificationObservers | |
| 327 | -{ | |
| 328 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 329 | - name:MPMoviePlayerLoadStateDidChangeNotification | |
| 330 | - object:nil]; | |
| 331 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 332 | - name:MPMoviePlayerPlaybackDidFinishNotification | |
| 333 | - object:nil]; | |
| 334 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 335 | - name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification | |
| 336 | - object:nil]; | |
| 337 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 338 | - name:MPMoviePlayerPlaybackStateDidChangeNotification | |
| 339 | - object:nil]; | |
| 340 | - | |
| 341 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 342 | - name:CNLiveAnchorStatusChangedNotification | |
| 343 | - object:nil]; | |
| 344 | -} | |
| 345 | - | |
| 346 | -#pragma mark - getMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 382 | +#pragma mark - GetMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 347 | 383 | - (LVCUGCBackgroundView *)bgView { |
| 348 | 384 | |
| 349 | 385 | if (!_bgView) { |
| 350 | 386 | _bgView = [[LVCUGCBackgroundView alloc] initWithFrame:self.view.bounds]; |
| 351 | 387 | _bgView.hidden = YES; |
| 352 | 388 | } |
| 353 | - | |
| 354 | 389 | return _bgView; |
| 355 | 390 | } |
| 356 | 391 | |
| ... | ... | @@ -358,6 +393,8 @@ |
| 358 | 393 | if (!_viewOne) { |
| 359 | 394 | _viewOne = [[UIView alloc] initWithFrame:CGRectMake(0, -SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)]; |
| 360 | 395 | _viewOne.backgroundColor = [UIColor orangeColor]; |
| 396 | + _firstLoadView = [[LVCUGCPlayerLoadingView alloc] initWithFrame:self.view.bounds]; | |
| 397 | + [_viewOne addSubview:_firstLoadView]; | |
| 361 | 398 | _oneY = -SCREEN_HEIGHT; |
| 362 | 399 | } |
| 363 | 400 | return _viewOne; |
| ... | ... | @@ -367,6 +404,8 @@ |
| 367 | 404 | if (!_viewSecond) { |
| 368 | 405 | _viewSecond = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; |
| 369 | 406 | _viewSecond.backgroundColor = [UIColor redColor]; |
| 407 | + _secondLoadView = [[LVCUGCPlayerLoadingView alloc] initWithFrame:self.view.bounds]; | |
| 408 | + [_viewSecond addSubview:_secondLoadView]; | |
| 370 | 409 | _SecondY = 0; |
| 371 | 410 | } |
| 372 | 411 | return _viewSecond; |
| ... | ... | @@ -376,11 +415,34 @@ |
| 376 | 415 | if (!_viewThird) { |
| 377 | 416 | _viewThird = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)]; |
| 378 | 417 | _viewThird.backgroundColor = [UIColor blueColor]; |
| 418 | + _thirdLoadView = [[LVCUGCPlayerLoadingView alloc] initWithFrame:self.view.bounds]; | |
| 419 | + [_viewThird addSubview:_thirdLoadView]; | |
| 379 | 420 | _ThirdY = SCREEN_HEIGHT; |
| 380 | 421 | } |
| 381 | 422 | return _viewThird; |
| 382 | 423 | } |
| 383 | 424 | |
| 425 | +#pragma mark - 移除通知 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 426 | +- (void)removeMovieNotificationObservers | |
| 427 | +{ | |
| 428 | + [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 429 | + name:MPMoviePlayerLoadStateDidChangeNotification | |
| 430 | + object:nil]; | |
| 431 | + [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 432 | + name:MPMoviePlayerPlaybackDidFinishNotification | |
| 433 | + object:nil]; | |
| 434 | + [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 435 | + name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification | |
| 436 | + object:nil]; | |
| 437 | + [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 438 | + name:MPMoviePlayerPlaybackStateDidChangeNotification | |
| 439 | + object:nil]; | |
| 440 | + | |
| 441 | + [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 442 | + name:CNLiveAnchorStatusChangedNotification | |
| 443 | + object:nil]; | |
| 444 | +} | |
| 445 | + | |
| 384 | 446 | #pragma mark - 内存警告 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 385 | 447 | - (void)didReceiveMemoryWarning { |
| 386 | 448 | [super didReceiveMemoryWarning]; | ... | ... |
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCLivePlayerCell.h
LiveVideoCloud/LiveVideoCloud/Classes/Sections/homeSections/View/LVCUGCLivePlayerCell.m
| ... | ... | @@ -7,7 +7,6 @@ |
| 7 | 7 | // |
| 8 | 8 | |
| 9 | 9 | #import "LVCUGCLivePlayerCell.h" |
| 10 | -#import "UIImage+LVCVagueImage.h" | |
| 11 | 10 | |
| 12 | 11 | @implementation LVCUGCLivePlayerCell |
| 13 | 12 | |
| ... | ... | @@ -16,9 +15,7 @@ |
| 16 | 15 | self = [super initWithFrame:frame]; |
| 17 | 16 | if (self) { |
| 18 | 17 | self.contentView.backgroundColor = [UIColor whiteColor]; |
| 19 | - | |
| 20 | 18 | |
| 21 | - [self addSubview:self.loadingView]; | |
| 22 | 19 | } |
| 23 | 20 | return self; |
| 24 | 21 | } |
| ... | ... | @@ -31,13 +28,4 @@ |
| 31 | 28 | } |
| 32 | 29 | } |
| 33 | 30 | |
| 34 | -#pragma mark - GetMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 35 | -- (LVCUGCPlayerLoadingView *)loadingView { | |
| 36 | - | |
| 37 | - if (!_loadingView) { | |
| 38 | - _loadingView = [[LVCUGCPlayerLoadingView alloc] initWithFrame:self.contentView.bounds]; | |
| 39 | - } | |
| 40 | - return _loadingView; | |
| 41 | -} | |
| 42 | - | |
| 43 | 31 | @end | ... | ... |