如何在iOS中的MPMoviePlayerViewController中禁用FullScreen

时间:2013-08-05 06:57:26

标签: iphone ios objective-c mpmovieplayercontroller

我正在使用MPMoviePlayerViewController

MPMoviePlayerViewController *avPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
// [movieView prepareToPlay];

[avPlayer.view setFrame: CGRectMake(0, 200, 320, 100)];  // player's frame must match parent's
[avPlayer shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];
[avPlayer shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
avPlayer.moviePlayer.scalingMode=MPMovieScalingModeAspectFit;
avPlayer.moviePlayer.useApplicationAudioSession=NO;
avPlayer.moviePlayer.controlStyle=MPMovieControlStyleEmbedded;
//avPlayer.moviePlayer.repeatMode=MPMovieRepeatModeOne;
avPlayer.moviePlayer.scalingMode=MPMovieScalingModeFill;
[self.view addSubview: avPlayer.view];

此功能正常运行。但我需要为MPMoviePlayerViewController禁用全屏。所以,我写了

avPlayer.moviePlayer.fullscreen=NO;

但这不起作用。

请你给我一些建议。

2 个答案:

答案 0 :(得分:0)

使用此代码在MPMoviePlayerViewController中禁用全屏。

moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleNone;

或选中此项以输入您的视图控制器。

 [[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(Enter:) 
                                             name:MPMoviePlayerWillEnterFullscreenNotification 
                                           object:nil];

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

我希望这段代码对你有用。

答案 1 :(得分:-3)

试试这个......

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(movieEventFullscreenHandler:) 
                                                 name:MPMoviePlayerWillEnterFullscreenNotification 
                                               object:nil];

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

    self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
}

- (void)movieEventFullscreenHandler:(NSNotification*)notification {
    [self.moviePlayer setFullscreen:NO animated:NO];
    [self.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
}

请检查this answer