Commit 7d4c4b5ff33198cac6ec7cd4351507f05088317f
Merge branch 'master' of bj.gitlab.cnlive.com:ios-team/LiveVideoCloud
Showing
5 changed files
with
51 additions
and
51 deletions
LiveVideoCloud/AppDelegate/AppDelegate.m
| ... | ... | @@ -22,7 +22,7 @@ |
| 22 | 22 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 23 | 23 | self.window.rootViewController = [[ZXTabBarController alloc] init]; |
| 24 | 24 | |
| 25 | - //初始化直播SDK | |
| 25 | + //APP 启动是初始化直播SDK | |
| 26 | 26 | [[CNLiveWebcastManager manager] initWithAppId:UserAppId appKey:UserAppKey isTestEnvironment:YES]; |
| 27 | 27 | |
| 28 | 28 | //初始化聊天SDK并连接服务器 |
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | |
| 46 | 46 | // 20170327 20170328 |
| 47 | 47 | |
| 48 | - CNLiveChatUserInfo *userInfo = [[CNLiveChatUserInfo alloc] initWithUserId:@"20170328" name:@"20170328" portrait:@""]; | |
| 48 | + CNLiveChatUserInfo *userInfo = [[CNLiveChatUserInfo alloc] initWithUserId:@"20170328ll" name:@"20170328" portrait:@""]; | |
| 49 | 49 | [[CNLiveChatManager sharedCNLiveChatManager] loginServer:userInfo success:^(NSString *userId) { |
| 50 | 50 | NSLog(@"连接服务器-----success"); |
| 51 | 51 | ... | ... |
LiveVideoCloud/Classes/Sections/PGCSections/Controller/LVCLivePlayerController.m
| ... | ... | @@ -41,11 +41,18 @@ |
| 41 | 41 | - (void)viewWillAppear:(BOOL)animated |
| 42 | 42 | { |
| 43 | 43 | [super viewWillAppear:animated]; |
| 44 | + self.navigationController.navigationBar.hidden = YES; | |
| 44 | 45 | [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; |
| 45 | 46 | [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade]; |
| 46 | 47 | |
| 47 | 48 | } |
| 48 | 49 | |
| 50 | +- (void)viewDidDisappear:(BOOL)animated | |
| 51 | +{ | |
| 52 | + [super viewDidDisappear:animated]; | |
| 53 | + self.navigationController.navigationBar.hidden = NO; | |
| 54 | +} | |
| 55 | + | |
| 49 | 56 | - (void)viewWillDisappear:(BOOL)animated |
| 50 | 57 | { |
| 51 | 58 | [super viewWillDisappear:animated]; |
| ... | ... | @@ -99,6 +106,7 @@ |
| 99 | 106 | |
| 100 | 107 | - (void)addObservers |
| 101 | 108 | { |
| 109 | + //设备旋转 | |
| 102 | 110 | [[NSNotificationCenter defaultCenter] addObserver:self |
| 103 | 111 | selector:@selector(onDeviceOrientationChange:) |
| 104 | 112 | name:UIDeviceOrientationDidChangeNotification |
| ... | ... | @@ -263,7 +271,6 @@ |
| 263 | 271 | [_chatView quitChatroom]; |
| 264 | 272 | [self removeViews]; |
| 265 | 273 | |
| 266 | - self.navigationController.navigationBar.hidden = NO; | |
| 267 | 274 | [self.navigationController popViewControllerAnimated:YES]; |
| 268 | 275 | } |
| 269 | 276 | } | ... | ... |
LiveVideoCloud/Classes/Sections/PGCSections/Controller/LVCTelevisioController.m
| ... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 | |
| 14 | 14 | @interface LVCTelevisioController ()<UITableViewDelegate, UITableViewDataSource> |
| 15 | 15 | { |
| 16 | - NSMutableArray *_channelsModelArray; | |
| 16 | + NSMutableArray *_channelsModelArray; //数据源 | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | @property (nonatomic, strong) UITableView *tableView; |
| ... | ... | @@ -21,13 +21,18 @@ |
| 21 | 21 | @end |
| 22 | 22 | |
| 23 | 23 | @implementation LVCTelevisioController |
| 24 | +- (void)viewWillAppear:(BOOL)animated { | |
| 25 | + [super viewWillAppear:animated]; | |
| 26 | + self.edgesForExtendedLayout = UIRectEdgeNone; | |
| 27 | + self.navigationController.navigationBar.hidden = NO; | |
| 28 | +} | |
| 24 | 29 | |
| 25 | 30 | - (void)viewDidLoad { |
| 26 | 31 | [super viewDidLoad]; |
| 27 | 32 | // Do any additional setup after loading the view. |
| 28 | 33 | self.view.backgroundColor = [UIColor whiteColor]; |
| 29 | 34 | self.navigationItem.title = @"直播"; |
| 30 | - | |
| 35 | + | |
| 31 | 36 | _channelsModelArray = [[NSMutableArray alloc] init]; |
| 32 | 37 | |
| 33 | 38 | [self.view addSubview:self.tableView]; |
| ... | ... | @@ -37,6 +42,7 @@ |
| 37 | 42 | |
| 38 | 43 | - (void)loadData { |
| 39 | 44 | |
| 45 | + //demo使用的是本地数据 | |
| 40 | 46 | NSString *path = [[NSBundle mainBundle] pathForResource:@"TelevisionData" ofType:@"json"]; |
| 41 | 47 | NSData *data=[NSData dataWithContentsOfFile:path]; |
| 42 | 48 | NSError *error; |
| ... | ... | @@ -93,7 +99,7 @@ |
| 93 | 99 | - (UITableView *)tableView |
| 94 | 100 | { |
| 95 | 101 | if (!_tableView) { |
| 96 | - _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-49) style:UITableViewStylePlain]; | |
| 102 | + _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-49-64) style:UITableViewStylePlain]; | |
| 97 | 103 | _tableView.delegate = self; |
| 98 | 104 | _tableView.dataSource = self; |
| 99 | 105 | } | ... | ... |
LiveVideoCloud/Classes/Sections/PGCSections/View/LVCPlayer.h
| ... | ... | @@ -31,7 +31,7 @@ typedef void(^HideInputViewBlock)(BOOL hide); |
| 31 | 31 | @property (nonatomic, strong) UIImageView *contentView; //所有空间统一管理在这个view中 |
| 32 | 32 | @property (nonatomic, strong) LVCTelevisionModel *model; //所有空间统一管理在这个view中 |
| 33 | 33 | @property (nonatomic, readwrite, assign) BOOL isFullScreen; //是否是全屏 |
| 34 | -@property (nonatomic, copy) HideInputViewBlock hideBlock; //全屏模式下是否隐藏输入框 | |
| 34 | +@property (nonatomic, copy) HideInputViewBlock hideBlock; //全屏模式下是否隐藏输入框 | |
| 35 | 35 | @property (nonatomic, assign, readonly) BOOL displayBarrage; //是否显示弹幕 |
| 36 | 36 | @property (nonatomic, assign) id<LVCPlayerDelegate> delegate; |
| 37 | 37 | |
| ... | ... | @@ -39,6 +39,6 @@ typedef void(^HideInputViewBlock)(BOOL hide); |
| 39 | 39 | |
| 40 | 40 | - (void)autoHideControlView; //自动隐藏上下功能条 |
| 41 | 41 | |
| 42 | -- (void)stopPlaying; //停止播放 | |
| 42 | +- (void)stopPlaying; //停止播放 | |
| 43 | 43 | |
| 44 | 44 | @end | ... | ... |
LiveVideoCloud/Classes/Sections/PGCSections/View/LVCPlayer.m
| ... | ... | @@ -33,6 +33,7 @@ |
| 33 | 33 | |
| 34 | 34 | - (void)dealloc |
| 35 | 35 | { |
| 36 | + [self exitPlayer]; | |
| 36 | 37 | NSLog(@"LVCPlayer dealloc"); |
| 37 | 38 | } |
| 38 | 39 | |
| ... | ... | @@ -72,9 +73,9 @@ |
| 72 | 73 | NSString *channelId = [NSString stringWithFormat:@"82_%@",model.mediaId]; |
| 73 | 74 | _player = [[CNLiveMoviePlayerController alloc] initLivePlayWithChannelId:channelId anchorStatus:NO authSuccess:^{ |
| 74 | 75 | [self addObservers]; |
| 75 | - _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO; | |
| 76 | - _player.shouldAutoplay = YES; | |
| 77 | - [_player prepareToPlay]; | |
| 76 | + _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO; //自动解码 | |
| 77 | + _player.shouldAutoplay = YES; //自动播放 | |
| 78 | + [_player prepareToPlay]; //准备播放 | |
| 78 | 79 | [self.contentView addSubview:_player.view]; |
| 79 | 80 | [self.contentView sendSubviewToBack:_player.view]; |
| 80 | 81 | |
| ... | ... | @@ -86,31 +87,12 @@ |
| 86 | 87 | [_loadingView stopLoading]; |
| 87 | 88 | |
| 88 | 89 | } getAnchorStatusResult:NULL]; |
| 89 | - | |
| 90 | - /* | |
| 91 | - //点播播放 | |
| 92 | - _player = [[CNLiveMoviePlayerController alloc] initVodPlayWithVId:@"aaa123" | |
| 93 | - authSuccess:^{ | |
| 94 | - | |
| 95 | - [self addObservers]; | |
| 96 | - _player.videoDecoderMode = CNLiveMovieVideoDecoderMode_AUTO; | |
| 97 | - _player.shouldAutoplay = YES; | |
| 98 | - [_player prepareToPlay]; | |
| 99 | - [self.contentView addSubview:_player.view]; | |
| 100 | - [self.contentView sendSubviewToBack:_player.view]; | |
| 101 | - | |
| 102 | - [self makePlayerConstraint]; | |
| 103 | - | |
| 104 | - | |
| 105 | - } authFailed:^(NSDictionary *errorInfo) { | |
| 106 | - NSLog(@"初始化点播播放器失败%@", errorInfo); | |
| 107 | - | |
| 108 | - }]; | |
| 109 | - */ | |
| 90 | + | |
| 110 | 91 | } |
| 111 | 92 | |
| 112 | 93 | #pragma mark - |
| 113 | 94 | #pragma mark - action |
| 95 | +//播放/暂停 | |
| 114 | 96 | - (void)playOrPauseBtnAction:(UIButton *)btn |
| 115 | 97 | { |
| 116 | 98 | if (btn.selected) { |
| ... | ... | @@ -123,6 +105,7 @@ |
| 123 | 105 | |
| 124 | 106 | } |
| 125 | 107 | |
| 108 | +//返回 | |
| 126 | 109 | - (void)backBtnAction:(UIButton *)btn |
| 127 | 110 | { |
| 128 | 111 | if (self.delegate && [self.delegate respondsToSelector:@selector(lvcPlayer:clickedBackBtn:)]) { |
| ... | ... | @@ -130,14 +113,15 @@ |
| 130 | 113 | } |
| 131 | 114 | } |
| 132 | 115 | |
| 116 | +//全屏 | |
| 133 | 117 | - (void)fullScreenBtnAction:(UIButton *)btn |
| 134 | 118 | { |
| 135 | 119 | if (self.delegate && [self.delegate respondsToSelector:@selector(lvcPlayer:clickedFullScreenBtn:)]) { |
| 136 | 120 | [self.delegate lvcPlayer:self clickedFullScreenBtn:btn]; |
| 137 | 121 | } |
| 138 | - | |
| 139 | 122 | } |
| 140 | 123 | |
| 124 | +//弹幕 | |
| 141 | 125 | - (void)barrageSwitchAction |
| 142 | 126 | { |
| 143 | 127 | self.editBtn.hidden =! self.barrageSwitch.on; |
| ... | ... | @@ -148,6 +132,7 @@ |
| 148 | 132 | |
| 149 | 133 | } |
| 150 | 134 | |
| 135 | +//编辑弹幕 | |
| 151 | 136 | - (void)editBtnAction:(UIButton *)btn |
| 152 | 137 | { |
| 153 | 138 | if (self.hideBlock) { |
| ... | ... | @@ -161,7 +146,7 @@ |
| 161 | 146 | } |
| 162 | 147 | } |
| 163 | 148 | |
| 164 | - | |
| 149 | +//单击显示和隐藏工具条 | |
| 165 | 150 | - (void)singleTapView |
| 166 | 151 | { |
| 167 | 152 | [UIView animateWithDuration:0.25 animations:^{ |
| ... | ... | @@ -181,6 +166,7 @@ |
| 181 | 166 | |
| 182 | 167 | } |
| 183 | 168 | |
| 169 | +//自动隐藏工具条 | |
| 184 | 170 | - (void)autoHideControlView |
| 185 | 171 | { |
| 186 | 172 | if (!_timer) { |
| ... | ... | @@ -192,6 +178,7 @@ |
| 192 | 178 | } |
| 193 | 179 | } |
| 194 | 180 | |
| 181 | +//手动隐藏工具条 | |
| 195 | 182 | - (void)hideControlView |
| 196 | 183 | { |
| 197 | 184 | |
| ... | ... | @@ -211,8 +198,7 @@ |
| 211 | 198 | } |
| 212 | 199 | } |
| 213 | 200 | |
| 214 | -#pragma mark - | |
| 215 | -#pragma mark - LVCPlayerLoadingViewDelegate | |
| 201 | +//播放异常,重试 | |
| 216 | 202 | - (void)retryBtnClick |
| 217 | 203 | { |
| 218 | 204 | [_loadingView setLVCPlayerStatus:LVCPlayerStatusStartLoading]; |
| ... | ... | @@ -272,6 +258,7 @@ |
| 272 | 258 | object:nil]; |
| 273 | 259 | } |
| 274 | 260 | |
| 261 | +//加载状态通知 | |
| 275 | 262 | - (void)loadStateDidChange:(NSNotification *)notification |
| 276 | 263 | { |
| 277 | 264 | if (_player) { |
| ... | ... | @@ -291,6 +278,7 @@ |
| 291 | 278 | } |
| 292 | 279 | } |
| 293 | 280 | |
| 281 | +//播放完成通知,当状态为MPMovieFinishReasonPlaybackError时为异常结束,应显示重试页面 | |
| 294 | 282 | - (void)moviePlayBackDidFinish:(NSNotification *)notification |
| 295 | 283 | { |
| 296 | 284 | if (_player) { |
| ... | ... | @@ -314,6 +302,7 @@ |
| 314 | 302 | } |
| 315 | 303 | } |
| 316 | 304 | |
| 305 | +//播放状态改变通知 | |
| 317 | 306 | - (void)moviePlayBackStateDidChange:(NSNotification *)notification |
| 318 | 307 | { |
| 319 | 308 | if (_player) { |
| ... | ... | @@ -361,6 +350,7 @@ |
| 361 | 350 | return netString; |
| 362 | 351 | } |
| 363 | 352 | |
| 353 | +//退到后台将播放器暂停 | |
| 364 | 354 | - (void)appResignActive:(NSNotification *)noti |
| 365 | 355 | { |
| 366 | 356 | if (_player.playbackState == MPMoviePlaybackStatePlaying) { |
| ... | ... | @@ -368,6 +358,7 @@ |
| 368 | 358 | } |
| 369 | 359 | } |
| 370 | 360 | |
| 361 | +//回到前台继续播放 | |
| 371 | 362 | - (void)appBecomeActive:(NSNotification *)noti |
| 372 | 363 | { |
| 373 | 364 | if (_player.playbackState == MPMoviePlaybackStatePaused) { |
| ... | ... | @@ -377,9 +368,14 @@ |
| 377 | 368 | |
| 378 | 369 | #pragma mark - |
| 379 | 370 | #pragma mark - public |
| 371 | +//停止播放 | |
| 380 | 372 | - (void)stopPlaying |
| 381 | 373 | { |
| 382 | - [_player stop]; | |
| 374 | + if (_player) { | |
| 375 | + [_player stop]; //注* stop调用多次是会导致崩溃 | |
| 376 | + } | |
| 377 | + | |
| 378 | + [_player destroyPlayer]; | |
| 383 | 379 | _player = nil; |
| 384 | 380 | |
| 385 | 381 | if (_timer) { |
| ... | ... | @@ -392,18 +388,7 @@ |
| 392 | 388 | |
| 393 | 389 | - (void)removeMovieNotificationObservers |
| 394 | 390 | { |
| 395 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 396 | - name:MPMoviePlayerLoadStateDidChangeNotification | |
| 397 | - object:nil]; | |
| 398 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 399 | - name:MPMoviePlayerPlaybackDidFinishNotification | |
| 400 | - object:nil]; | |
| 401 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 402 | - name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification | |
| 403 | - object:nil]; | |
| 404 | - [[NSNotificationCenter defaultCenter]removeObserver:self | |
| 405 | - name:MPMoviePlayerPlaybackStateDidChangeNotification | |
| 406 | - object:nil]; | |
| 391 | + [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
| 407 | 392 | } |
| 408 | 393 | |
| 409 | 394 | #pragma mark - |
| ... | ... | @@ -511,18 +496,20 @@ |
| 511 | 496 | } |
| 512 | 497 | |
| 513 | 498 | - (void)exitPlayer { |
| 514 | - if (_player.isPlaying) { | |
| 499 | + | |
| 500 | + if (_player) { | |
| 515 | 501 | [_player stop]; |
| 516 | 502 | } |
| 517 | 503 | |
| 518 | 504 | [_player destroyPlayer]; |
| 519 | 505 | _player = nil; |
| 520 | - [self removeMovieNotificationObservers]; | |
| 521 | 506 | |
| 522 | 507 | if (_timer) { |
| 523 | 508 | [_timer invalidate]; |
| 524 | 509 | _timer = nil; |
| 525 | 510 | } |
| 511 | + | |
| 512 | + [self removeMovieNotificationObservers]; | |
| 526 | 513 | } |
| 527 | 514 | |
| 528 | 515 | #pragma mark - | ... | ... |