【问题标题】:MPMoviePlayerController : Player hides Player Controls permenantly only in blow iOS6MPMoviePlayerController : 播放器仅在 iOS 6 中永久隐藏播放器控件
【发布时间】:2012-12-20 11:22:38
【问题描述】:

MPMoviePlayerController 播放器在按下完成按钮后永久隐藏播放器控件。

我有一个带有moviePlayer.controlStyle = MPMovieControlStyleEmbedded 的嵌入式播放器,当用户在moviePlayerDidEnterFullscreen 通知中点击全屏模式时,我正在制作[moviePlayer setFullscreen:NO];并将播放器视频转换为横向模式

moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));

和设置

moviePlayer.controlStyle =  MPMovieControlStyleFullscreen; 

然后,当我点击完成按钮并在 moviePlayBackDidFinish 中,我将视图转换回纵向模式并将 controlStyle 设置为 Embedded。到目前为止,它工作正常。之后该视频将暂停,当我点击播放按钮时,它开始播放,播放器将停留一段时间并永久隐藏。点击视频后,播放器将不再可见。我尝试在延迟后将播放器控件设置为嵌入。但没有任何工作。请帮助解决这个问题。

此问题仅在 iOS 6 以下的版本中出现

代码

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerDidEnterFullscreen:)
                                             name:MPMoviePlayerDidEnterFullscreenNotification
                                           object:nil];


if (mpVideoPlayerController)
{
    [mpVideoPlayerController.moviePlayer pause];
    [mpVideoPlayerController.moviePlayer stop];
}


mpVideoPlayerController = nil;
mpVideoPlayerController = [[VideoPlayerViewController alloc] initWithContentURL: theURL];


mpVideoPlayerController.moviePlayer.movieSourceType = liveStreaming ? MPMovieSourceTypeStreaming : MPMovieSourceTypeUnknown;

if ([mpVideoPlayerController.moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) {
    mpVideoPlayerController.moviePlayer.allowsAirPlay = YES;
}

[[mpVideoPlayerController.moviePlayer view] setFrame:viewInsetRect];
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
mpVideoPlayerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[viewController.view addSubview: [mpVideoPlayerController.moviePlayer view]];
[mpVideoPlayerController.moviePlayer play];
}


-(void) moviePlayerDidEnterFullscreen :(NSNotification*)notification {
    [mpVideoPlayerController.moviePlayer setFullscreen:NO];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self performSelector:@selector(setControlStyleFullscreen) withObject:nil afterDelay:0.2];
    [UIView animateWithDuration:0.3
                     animations:^{
                         mpVideoPlayerController.moviePlayer.view.transform = CGAffineTransformIdentity;
                         mpVideoPlayerController.moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
                         CGRect frame=[[UIScreen mainScreen] applicationFrame];
                         frame.origin.y=-20;
                         mpVideoPlayerController.moviePlayer.view.frame = frame;//CGRectMake(0.0, 0.0, 480.0, 300.0);
                     } completion:^(BOOL finished) {

                     }];


}

- (void) setControlStyleFullscreen 
         mpVideoPlayerController.moviePlayer.controlStyle =  MPMovieControlStyleFullscreen;

- (void) setControlStyleEmbedded 

        mpVideoPlayerController.moviePlayer.controlStyle =  MPMovieControlStyleEmbedded;



- moviePlayBackDidFinish:

    NSLog(@"moviePlayBackDidFinish:");

    [self rotateToInterfaceOrientation:UIInterfaceOrientationPortrait frameForView:(viewController).videoContentView.frame];

    [[UIApplication sharedApplication] setStatusBarHidden:NO];

    [self performSelector:@selector(setControlStyleEmbedded) withObject:nil afterDelay:0.2];

【问题讨论】:

  • 分享你使用的MPmoviecontroller的完整代码...
  • 谢谢 Vishal,请检查代码

标签: iphone ios ios5 mpmovieplayercontroller


【解决方案1】:

您的代码有点错误并触发了那些MPMoviePlayerController 错误。

  • 多余的 setFullscreen,因为我们已经处于全屏模式。
  • 多余的 setControlStyle,因为我们已经处于全屏控制风格

一般来说,您永远不应该在 MPMoviePlayerController 上强制执行已经完成的操作。

- (void)moviePlayerDidEnterFullscreen :(NSNotification*)notification 
{
    //
    //remove both lines from this notification handler
    //
    [mpVideoPlayerController.moviePlayer setFullscreen:NO];
    [self performSelector:@selector(setControlStyleFullscreen) withObject:nil afterDelay:0.2];
    [...]
} 

您也可以通过检查当前模式来扩展您的 setControlStyleFullscreen / Embedded 实现。这可能看起来很奇怪,但确实很有帮助。

- (void)setControlStyleEmbedded
{
    if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleEmbedded)
    {
        mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    }
}

- (void)setControlStyleFullscreen
{
    if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleFullscreen)
    {
        mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    • 2011-04-27
    • 2015-01-05
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多