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