MPMoviePlayerController 添加自定义控件

在使用MPMoviePlayerController播放视频时,需要添加自定义控件,同时需要与MPMoviePlayerController默认的播放控制面板一起隐藏与显示

播放:

    _moviePlayer = [[MPMoviePlayerController alloc] init];
    _moviePlayer.contentURL = sourceMovieURL;
    _moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    _moviePlayer.shouldAutoplay = YES;
    _moviePlayer.repeatMode = MPMovieRepeatModeNone;
    _moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
    _moviePlayer.view.frame = self.bounds;
    [_moviePlayer setFullscreen:YES animated:YES];
    [self addSubview: _moviePlayer.view];
    
    if (![HelperClass CheckIsVideo:fileFullName]) {
        _about = true;
    } else {
        [_moviePlayer play];
    }
    _timerCheck = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkShowControls:) userInfo:nil repeats:true];
    [_timerCheck fire];

定时器控制自定义控件的显示与隐藏(通过检测 MPMoviePlayerController的view结构来控制):

<pre name="code" class="objc">// 设置自定义按钮是否显示
-(void)setControlsShow:(BOOL)show
{
    if (show) {
        if (!_btnReturn.superview) {
            [_moviePlayer.view addSubview:_btnReturn];
        }
    } else {
        if (_btnReturn.superview) {
            [_btnReturn removeFromSuperview];
        }
    }
}
// 检测控制面板是否显示
-(void)checkShowControls:(NSTimer *)timer
{
    BOOL showControls = false;
    do{
        NSArray* viewSub = _moviePlayer.view.subviews;
        if (!viewSub || viewSub.count<=0 || !viewSub[0])
            break;
        
        UIView* swapview =viewSub[0];
        viewSub = swapview.subviews;
        if (!viewSub || viewSub.count<=0 || !viewSub[0])
            break;
        
        UIView* videoConView = viewSub[0];
        viewSub =videoConView.subviews;
        if (!viewSub || viewSub.count<4 || !viewSub[3])
            break;
        
        
        UIView* tmpview = viewSub[3];
        
        CGRect rect = [tmpview convertRect:tmpview.frame fromView:nil];
        if (CGRectIsEmpty(rect) || CGRectIsNull(rect))
            break;
        // ios6此处就可能检测出是否隐藏
        if (tmpview.hidden)
            break;
        
        if (CGSizeEqualToSize(rect.size, CGSizeZero))
            break;
        // ios6以上需要此处来检测
        if (viewSub.count>=5) {
            tmpview = viewSub[4];
            if (CGRectIsEmpty(rect) || CGRectIsNull(rect))
                break;
            
            if (tmpview.hidden)
                break;
            
            if (CGSizeEqualToSize(rect.size, CGSizeZero))
                break;
        }
        
        showControls = true;
    }while (0);
    [self setControlsShow:showControls];
}


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值