LVCVodPlayerController.m 24.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
//
//  LVCVodPlayerController.m
//  LiveVideoCloud
//
//  Created by cnliveJunBo on 17/6/27.
//  Copyright © 2017年 cnlive. All rights reserved.
//

#import "LVCVodPlayerController.h"
#import <CNLivePlayerSDK/CNLiveMoviePlayerController.h>
#import "LVCVodPlayerFullController.h"
#import "LVCCommentView.h"

typedef enum {
    SwipeDirectionNone,
    SwipeDirectionVertical,
    SwipeDirectionHorizontal
} SwipeDirection;

@interface LVCVodPlayerController (){
    
    UIButton *_backButton;
    CNLiveMoviePlayerController *_player;//播放器
    BOOL _isPlaying; // 判断当前播放状态
    NSTimer *_autoHideTimer; // 自动隐藏时间
    NSTimer *_currentTimer;// 更新当前播放时间
    CGPoint _prePoint;
    BOOL _status; // 状态栏是否显示
    NSInteger _direction; // 屏幕方向 0正 1左 2右
    BOOL _isFullScreen; //判断是否全屏
    BOOL _isAppResignActive;  //App状态  是否后台  YES后台 NO前台
}

@property (nonatomic, strong) UIView *playerSuperView;  //播放器背景
@property (nonatomic, strong) UIView *topView;  //上方功能视图
@property (nonatomic, strong) UIView *bottomView; //下方
@property (nonatomic, strong) UILabel *videoTitle;   //视频标题
@property (nonatomic, strong) UIButton *playPauseBtn; //播放暂停按钮
@property (nonatomic, strong) UILabel *currentTimeLabel;  //当前时间显示
@property (nonatomic, strong) UILabel *durationLabel; //总时间
@property (nonatomic, strong) UISlider *timeSlide;  //滑动
@property (nonatomic, strong) UIProgressView *bufferProgress; //缓冲
@property (nonatomic, assign) SwipeDirection swipeDirection;// 滑动方向
@property (nonatomic, strong) UISlider *volumeSlide;   //声音控制
@property (nonatomic, strong) UIButton *toFullBtn;
@property (nonatomic, strong) LVCVodPlayerFullController *fullVC;
@property (nonatomic, strong) LVCCommentView *commentView;

@end

@implementation LVCVodPlayerController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    [[UIApplication sharedApplication] setStatusBarHidden: NO withAnimation:UIStatusBarAnimationNone];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNotifications];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.playerSuperView];
    [self.view addSubview:self.commentView];
}

- (void)setModel:(ProgramModel *)model {
    _model = model;
    
    //用来更新视频当前播放时间
    _currentTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];
    
    [self playerInitialize];
    self.commentView.model = model;
}

#pragma mark - 初始化播放器
- (void)playerInitialize {
    
    _player = [[CNLiveMoviePlayerController alloc] initVodPlayWithVId:self.model.mediaId
                                                            authSuccess:^{
                                                                
                                                                _isPlaying = YES;
                                                                
                                                                _player.view.frame = CGRectMake(0, 20, KScreenWidth, KVideoHeight);
                                                                _player.shouldAutoplay = YES;
                                                                [_player prepareToPlay];
                                                                [_playerSuperView insertSubview:_player.view atIndex:0];
                                                                
                                                                UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
                                                                [_player.view addGestureRecognizer:singleTap];// 点击手势
                                                                
                                                                UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognizerAction:)];
                                                                [_player.view addGestureRecognizer:panRecognizer];// 声音,亮度手势
                                                                
                                                                _autoHideTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(autoHideCtrlView) userInfo:nil repeats:NO];//隐藏时间
                                                                
                                                                _playPauseBtn.userInteractionEnabled = YES;
                                                            } authFailed:^(NSDictionary *errorInfo) {
                                                                NSLog(@"初始化点播播放器失败%@", errorInfo);
                                                            }];
}


#pragma mark - GetMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!
- (UIView *)playerSuperView
{
    if (!_playerSuperView) {
        _playerSuperView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KVideoHeight+20)];
        _playerSuperView.backgroundColor = [UIColor blackColor];
        _backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 15, 35, 35)];
        [_backButton setImage:[UIImage imageNamed:@"play_fanhui"] forState:UIControlStateNormal];
        [_backButton setImage:[UIImage imageNamed:@"fanhui_focused"] forState:UIControlStateHighlighted];
        [_backButton addTarget:self action:@selector(clickToBack) forControlEvents:UIControlEventTouchUpInside];
        
        [_playerSuperView addSubview:self.topView];
        [_playerSuperView addSubview:self.bottomView];
        [_playerSuperView addSubview:_backButton];
    }
    return _playerSuperView;
}

- (UILabel *)videoTitle { // 视频标题
    if (!_videoTitle) {
        _videoTitle = [[UILabel alloc] initWithFrame:CGRectMake(44, 15, KScreenWidth - 100, 35)];
        _videoTitle.font = [UIFont systemFontOfSize:16];
        _videoTitle.textColor = [UIColor whiteColor];
        if ([self.model.subTitle isEqualToString:@""]) {
            _videoTitle.text = self.model.title;
        } else {
            _videoTitle.text = self.model.subTitle;
        }
    }
    return _videoTitle;
}

- (UIView *)topView { // 播放器顶部功能条
    
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenHeight, 55)];
        _topView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
        [_topView addSubview:self.videoTitle];
        _topView.hidden = YES;
    }
    return _topView;
}

- (UIView *)bottomView { // 播放器底部功能条
    
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, KVideoHeight - 20, KScreenWidth, 40)];
        _bottomView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
        [_bottomView addSubview:self.playPauseBtn];
        [_bottomView addSubview:self.currentTimeLabel];
        [_bottomView addSubview:self.durationLabel];
        [_bottomView addSubview:self.bufferProgress];
        [_bottomView addSubview:self.timeSlide];
        [_bottomView addSubview:self.toFullBtn];
    }
    return _bottomView;
}

- (UIButton *)playPauseBtn { //播放暂停按钮
    if (!_playPauseBtn) {
        _playPauseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _playPauseBtn.frame = CGRectMake(0, 0, 40, 40);
        [_playPauseBtn addTarget:self action:@selector(playPause) forControlEvents:UIControlEventTouchUpInside];
        [_playPauseBtn setImage:[UIImage imageNamed:@"play_bofang"] forState:UIControlStateNormal];
        _playPauseBtn.userInteractionEnabled = NO;
    }
    return _playPauseBtn;
}

- (UILabel *)currentTimeLabel {  //当前播放时间
    if (!_currentTimeLabel) {
        _currentTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 55, 40)];
        _currentTimeLabel.textColor = [UIColor whiteColor];
        _currentTimeLabel.font = [UIFont systemFontOfSize:12];
        [_currentTimeLabel setText:[NSString stringWithFormat:@"00:00:00"]];
    }
    return _currentTimeLabel;
}

- (UILabel *)durationLabel {  //总时长
    if (!_durationLabel) {
        _durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScreenWidth - 95, 0, 55, 40)];
        _durationLabel.textColor = [UIColor whiteColor];
        _durationLabel.font = [UIFont systemFontOfSize:12];
        [_durationLabel setText:[NSString stringWithFormat:@"00:00:00"]];
    }
    return _durationLabel;
}

- (UISlider *)timeSlide {  // 滑动
    if (!_timeSlide) {
        _timeSlide = [[UISlider alloc] initWithFrame:CGRectMake(95, 0, KScreenWidth - 190, 40)];
        [_timeSlide setMinimumTrackTintColor:[UIColor redColorCNLive]];
        [_timeSlide setMaximumTrackTintColor:[UIColor clearColor]];
        [_timeSlide addTarget:self action:@selector(beginScrubbing) forControlEvents:UIControlEventTouchDown];
        [_timeSlide addTarget:self action:@selector(endScrubbing) forControlEvents:UIControlEventTouchUpInside];
        [_timeSlide addTarget:self action:@selector(endScrubbing) forControlEvents:UIControlEventTouchUpOutside];
    }
    return _timeSlide;
}

- (UIProgressView *)bufferProgress {  //  缓冲
    if (!_bufferProgress) {
        _bufferProgress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
        _bufferProgress.frame = CGRectMake(111, 19, KScreenWidth - 111- 55-40, 1);
        _bufferProgress.trackTintColor = [UIColor whiteColor];
        _bufferProgress.progressTintColor = [UIColor grayColor];
        _bufferProgress.progress = 0;
    }
    return _bufferProgress;
}

- (UISlider *)volumeSlide   //音量改变  不直接展示MPVolumeView,而是获取它的子视图slide来改变系统音量
{
    if (!_volumeSlide) {
        MPVolumeView *slide = [[MPVolumeView alloc] init];
        for (UIView *view in [slide subviews]) {
            if ([view isKindOfClass:[UISlider class]]) {
                _volumeSlide = (UISlider *)view;
            }
        }
    }
    return _volumeSlide;
}

- (UIButton *)toFullBtn   //全屏按钮
{
    if (!_toFullBtn) {
        _toFullBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_toFullBtn setImage:[UIImage imageNamed:@"play_fangda_default"] forState:UIControlStateNormal];
        [_toFullBtn setImage:[UIImage imageNamed:@"play_fangda_focused"] forState:UIControlStateHighlighted];
        _toFullBtn.frame = CGRectMake(KScreenWidth - 40, 2.5, 35, 35);
        [_toFullBtn addTarget:self action:@selector(clickButtonToFull) forControlEvents:UIControlEventTouchUpInside];
    }
    return _toFullBtn;
}

- (LVCVodPlayerFullController *)fullVC { //全屏播放器
    if (!_fullVC) {
        _fullVC = [[LVCVodPlayerFullController alloc] init];
    }
    return _fullVC;
}

- (LVCCommentView *)commentView {
    
    if (!_commentView) {
        _commentView = [[LVCCommentView alloc] initWithFrame:CGRectMake(0, KVideoHeight + 20, KScreenWidth, KScreenHeight - KVideoHeight - 20)];
    }
    return _commentView;
}

#pragma mark - Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- (void)addNotifications {
    
    // 设备方向监听通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(deviceOrientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
    
    //视频播放状态改变
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackStateDidChange:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(appResignActive)
                                                 name:UIApplicationWillResignActiveNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(appBecomeActive)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];
}

#pragma mark - 屏幕旋转通知监听
- (void)deviceOrientationChanged:(id)sender {
    
    if ([[UIDevice currentDevice] orientation] ==  UIDeviceOrientationPortrait)
    {
        if (_direction == 0 || _isAppResignActive) {
            return;
        }
        
        [self clickToBack];
        
    }else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
    {
        // 1 左
        if (_direction == 1 || _direction == 2 || _isAppResignActive) {
            return;
        } else {
            _direction = 1;
            [self scrollToFull];
        }
        
    }else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
    {
        // 2 右
        if (_direction == 2 || _direction == 1 || _isAppResignActive) {
            return;
        } else {
            _direction = 2;
            [self scrollToFull];
        }
    }
}

#pragma mark - App 状态通知
- (void)appResignActive {
    
    _isAppResignActive = YES;
    [_player pause];
}

- (void)appBecomeActive {
    
    _isAppResignActive = NO;
    [_player play];
}

- (void)clickButtonToFull {
    
    _direction = 1;
    [self scrollToFull];
}

- (void)scrollToFull {
    
    CGFloat angle = _direction == 2 ? M_PI_2 : -M_PI_2;
    
    [self presentViewController:self.fullVC animated:NO completion:^{
       
        [self.playerSuperView removeFromSuperview];
        [self.fullVC.view addSubview:self.playerSuperView];
        
        [self toFullFrameChange];
        
        self.playerSuperView.transform = CGAffineTransformMakeRotation(angle);
        [UIView animateWithDuration:0.3 animations:^{
            self.playerSuperView.transform = CGAffineTransformMakeRotation(0);
        }];
    }];
}

- (void)toFullFrameChange {
    
    _isFullScreen = YES;
    _toFullBtn.hidden = YES;
    _topView.hidden = NO;
    [_playerSuperView setFrame:CGRectMake(0.0f, 0.0f, KScreenHeight, KScreenWidth)];
    _player.view.frame = _playerSuperView.bounds;
    _bottomView.frame = CGRectMake(0, KScreenWidth - 55, KScreenHeight, 55);
    _durationLabel.x = KScreenHeight - 55;
    _timeSlide.width = KScreenHeight - 150;
    _bufferProgress.width = KScreenHeight - 111 - 55;
}

- (void)clickToBack {  //退出
    
    if (_isFullScreen) {
        
        CGFloat angle = _direction == 2 ? -M_PI_2 : M_PI_2;
        [self.fullVC dismissViewControllerAnimated:NO completion:^{
            
            [self.playerSuperView removeFromSuperview];
            [self.view insertSubview:self.playerSuperView atIndex:0];
            [self fromFullToNormal];
            self.playerSuperView.transform = CGAffineTransformMakeRotation(angle);
            [UIView animateWithDuration:0.3 animations:^{
                self.playerSuperView.transform = CGAffineTransformMakeRotation(0);
            }];
        }];
    } else {
        
        [_player stop];
        [_autoHideTimer invalidate];
        _autoHideTimer = nil;
        [_currentTimer invalidate];
        _currentTimer = nil;
        [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
        [_playerSuperView removeFromSuperview];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)fromFullToNormal {
    
    _isFullScreen = NO;
    _toFullBtn.hidden = NO;
    _topView.hidden = YES;
    
    _playerSuperView.bounds = CGRectMake(0, 0, KScreenWidth, KVideoHeight + 20);
    CGPoint backPoint = CGPointMake(KScreenWidth * 0.5, KVideoHeight * 0.5 + 10);
    _playerSuperView.center = backPoint;
    _player.view.frame = CGRectMake(0, 20, KScreenWidth, KVideoHeight);
    _bottomView.frame = CGRectMake(0, KVideoHeight - 20, KScreenWidth, 40);
    _durationLabel.x = KScreenWidth - 95;
    _timeSlide.width = KScreenWidth - 190;
    _bufferProgress.width = KScreenWidth - 111- 55-40;
    _direction = 0;
}

- (void)playPause {  //播放暂停
    
    _isPlaying = _isPlaying == YES ? NO : YES;
    
    if (_player.isPlaying) {
        [_player pause];
        [_autoHideTimer invalidate];
    } else {
        [_player play];
        _autoHideTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(autoHideCtrlView) userInfo:nil repeats:NO];
    }
}

- (void)autoHideCtrlView { //自动隐藏上下功能视图
    [UIView animateWithDuration:0.3 animations:^{
        self.topView.alpha = 0;
        self.bottomView.alpha = 0;
        _status = YES;
        if (_isFullScreen) {
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
        }
    }];
}

- (void)singleTap:(UIGestureRecognizer *)tap { //单击手势
    
    if (_isPlaying) {
        [_autoHideTimer invalidate];
        _autoHideTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(autoHideCtrlView) userInfo:nil repeats:NO];
    }
    [UIView animateWithDuration:0.5 animations:^{
        self.topView.alpha = self.topView.alpha == 0 ? 1 : 0;
        self.bottomView.alpha = self.bottomView.alpha == 0 ? 1 : 0;
        _status = self.topView.alpha == 0 ? YES : NO;
        
        if (_isFullScreen) {
            [[UIApplication sharedApplication] setStatusBarHidden:_status withAnimation:UIStatusBarAnimationFade];
        }
    }];
}

- (void)timeChange { // 更新当前播放时间
    
    _bufferProgress.progress = _player.playableDuration/_player.duration;
    if (!_player.isPreparedToPlay) {
        return;
    }
    _timeSlide.value = _player.currentPlaybackTime;
    _timeSlide.maximumValue = _player.duration;
    
    // 当前播放时间
    NSInteger currentSeconds = (NSInteger)_player.currentPlaybackTime;
    NSInteger seconds = currentSeconds % 60;
    NSInteger minutes = currentSeconds / 60;
    NSInteger hours = minutes / 60;
    
    // 总时长
    NSInteger durationall = (NSInteger)_player.duration;
    NSInteger durationSeconds = durationall % 60;
    NSInteger durationMinutes = durationall / 60;
    NSInteger durationHours = durationMinutes / 60;
    
    // 当前时间
    _currentTimeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld", (long)hours, (long)minutes%60, (long)seconds];
    // 总时长
    _durationLabel.text = [NSString stringWithFormat:@"%02ld:%02ld:%02ld", (long)durationHours, (long)durationMinutes%60, (long)durationSeconds];
}

// 滑动监听方法
- (void)beginScrubbing {
    [_player pause];
    [_currentTimer invalidate];
    [_autoHideTimer invalidate];
}

- (void)endScrubbing {
    [_player setCurrentPlaybackTime:_timeSlide.value];
    [_player play];
    _currentTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];
    _autoHideTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(autoHideCtrlView) userInfo:nil repeats:NO];
}

- (void)panRecognizerAction:(UIPanGestureRecognizer *)panRecognizer { // 声音拖拽方法
    
    switch (panRecognizer.state) {
        case UIGestureRecognizerStateBegan:
        {
            self.swipeDirection = SwipeDirectionNone;
            _prePoint = [panRecognizer locationInView:_playerSuperView];
        }
            break;
        case UIGestureRecognizerStateChanged:
        {
            CGPoint currp = [panRecognizer locationInView:_playerSuperView];
            CGPoint distance = [panRecognizer translationInView:_playerSuperView];
            CGFloat xLength = currp.x-_prePoint.x;
            CGFloat yLength = _prePoint.y-currp.y;
            
            NSLog(@"x:%f   y:%f  d:%f",xLength,yLength,distance.x);
            _prePoint = currp;
            
            switch (self.swipeDirection) {
                case SwipeDirectionNone:
                    if (fabs(xLength)>fabs(yLength)) {
                        // 水平
                        self.swipeDirection = SwipeDirectionHorizontal;
                    }else{
                        // 垂直
                        self.swipeDirection = SwipeDirectionVertical;
                    }
                    break;
                case SwipeDirectionVertical:
                {
                    CGFloat middle = 0;
                    if (_isFullScreen) {
                        middle = KScreenHeight*0.5;
                    } else {
                        middle = KScreenWidth*0.5;
                    }
                    if (_prePoint.x < middle) {
                        [self swipeVerticalVolume:yLength];
                    } else {
                        [self swipeVerticalBrightness:yLength];
                    }
                }
                    break;
                case SwipeDirectionHorizontal:
                {
                    [_player pause];
                    [_currentTimer invalidate];
                    [_autoHideTimer invalidate];
                    _timeSlide.value += xLength/KScreenHeight*_player.duration;
                }
                    break;
                default:
                    break;
            }
        }
            break;
        case UIGestureRecognizerStateEnded:
        case UIGestureRecognizerStateCancelled:
        case UIGestureRecognizerStateFailed:
        {
            if (self.swipeDirection == SwipeDirectionHorizontal) {
                [_player setCurrentPlaybackTime:_timeSlide.value];
                [_player play];
                _currentTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];
                _autoHideTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(autoHideCtrlView) userInfo:nil repeats:NO];
            }
        }
            break;
            
        default:
            break;
    }
}

- (void)swipeVerticalVolume:(CGFloat)length {   //纵向滑动手势声音
    
    self.volumeSlide.value += length/KScreenWidth;
}

- (void)swipeVerticalBrightness:(CGFloat)length {  //纵向滑动手势亮度
    
    [UIScreen mainScreen].brightness += length/KScreenWidth;
}

- (void)moviePlayBackStateDidChange:(NSNotification *)notification { //播放状态通知
    if (_player) {
        
        switch (_player.playbackState) {
            case MPMoviePlaybackStateStopped: {
                [self changePlayBtnStatus:NO];
                NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateStopped");
                break;
            }
            case MPMoviePlaybackStatePlaying: {
                [self changePlayBtnStatus:YES];
                NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStatePlaying");
                break;
            }
            case MPMoviePlaybackStatePaused:
                [self changePlayBtnStatus:NO];
                NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStatePaused");
                break;
            case MPMoviePlaybackStateInterrupted:
                [self changePlayBtnStatus:NO];
                NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateInterrupted");
                break;
            case MPMoviePlaybackStateSeekingForward:
                [self changePlayBtnStatus:NO];
                NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateSeekingForward");
                break;
            case MPMoviePlaybackStateSeekingBackward:
                [self changePlayBtnStatus:NO];
                NSLog(@"moviePlayBackStateDidChange : MPMoviePlaybackStateSeekingBackward");
                break;
            default:
                [self changePlayBtnStatus:NO];
                NSLog(@"moviePlayBackStateDidChange : %ld", _player.playbackState);
                break;
        }
    }
}

- (void)changePlayBtnStatus:(BOOL)playing { //改变播放暂停按钮图片
    if (playing) {
        [_playPauseBtn setImage:[UIImage imageNamed:@"play_bofang"] forState:UIControlStateNormal];
    } else {
        [_playPauseBtn setImage:[UIImage imageNamed:@"play_zanting"] forState:UIControlStateNormal];
    }
}

- (void)dealloc {
    NSLog(@"dealloc");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end