视频进入全屏但不会退出(iOS 6.1)

时间:2013-08-08 21:21:45

标签: ios mpmovieplayercontroller fullscreen

我正在使用自定义电影播放器​​以MPMoviePlayer为基础播放视频,而当调用 setFullscreen:YES 时播放器将进入全屏状态,当 setFullscreen:NO 被调用。

我试过了:

  • 将视频的视图添加为较小窗口的子视图,并重置视图的框架
  • 使用通知,如下所示(基于我在另一个关于此问题的问题中所阅读的内容)

这是我目前使用的代码。我见过的所有答案都没有为我解决问题,所以任何帮助都会非常感激。

- (IBAction)fullScreenPressed:(id)sender {
    if ([self mediaIsVideo]){
        if ([self.videoController.moviePlayer isFullscreen]){
            [self.videoController.moviePlayer setFullscreen:NO animated:YES];
            UIImage *full = [UIImage imageNamed:@"fullscreen-vector-icon.png"];
            [self.videoFullscreenButton setImage:full forState:UIControlStateNormal];
        }else{
            //video is in fullscreen, add notification observer
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitFullscreen) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
            [self.videoController.moviePlayer setFullscreen:YES animated:YES];
            UIImage *undoFull = [UIImage imageNamed:@"fullscreen-exit-vector-icon.png"];
            [self.videoFullscreenButton setImage:undoFull forState:UIControlStateNormal];
        }
}

-(void)exitFullscreen{
    if ([self mediaIsVideo]){
        NSLog(@"notification selector called");
        [self.videoController.moviePlayer setFullscreen:NO animated:YES];
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    }
}

0 个答案:

没有答案