1

我正在使用自定义电影播放器​​播放以 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];
    }
}
4

0 回答 0