6

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];
4

1 回答 1

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;
    }
}
于 2012-12-21T10:02:07.900 回答