退出全屏后MPMoviePlayerController将缩放模式设置为iM中的MPMovieScalingModeFill

时间:2013-08-09 05:56:57

标签: ios mpmovieplayercontroller

在我的应用程序中,我使用mpmovieplayercontroller播放视频

首先将缩放模式设置为MPmovieScalingmodefill并将视频显示为缩放模式。

然后我全屏观看视频并退出全屏,然后不设置缩放模式 MPmovieScalingmode以defualt模式填写和显示视频。

在我的视频播放代码下方

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(ExitFullScreen:)
                                             name:MPMoviePlayerWillExitFullscreenNotification object:nil];

[appDelegate.moviePlayerController setContentURL:fileURL];

if ([appDelegate checkDevice])
{
    [appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,463)];
}
else
{
    [appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,375)];
}


[appDelegate.moviePlayerController prepareToPlay];
appDelegate.moviePlayerController.scalingMode=MPMovieScalingModeFill;
appDelegate.moviePlayerController.controlStyle=MPMovieControlStyleDefault;
appDelegate.moviePlayerController.shouldAutoplay=NO;
[appDelegate.moviePlayerController setFullscreen:YES animated:YES];
[appDelegate.moviePlayerController play];
[self.view addSubview:appDelegate.moviePlayerController.view];

- (void)ExitFullScreen:(NSNotification *)notification{
NSLog(@"Exit full Screen");
[appDelegate.moviePlayerController setControlStyle:MPMovieControlStyleEmbedded];
[appDelegate.moviePlayerController setScalingMode:MPMovieScalingModeFill];}

所以我的问题是如何在退出全屏后设置缩放模式或者在退出屏幕后不改变缩放模式?

请帮帮我。

感谢。

2 个答案:

答案 0 :(得分:0)

我相信这会生成MPMoviePlayerScalingModeDidChangeNotification

[[NSNotificationCenter defaultCenter] addObserver:self 
                selector:@selector(movieScalingModeDidChange:) 
                name:MPMoviePlayerScalingModeDidChangeNotification 
                object:nil];

<强> MPMoviePlayerScalingModeDidChangeNotification

在电影播放器​​的缩放模式发生变化时发布。没有userInfo字典。缩放模式可以通过编程或用户交互进行更改。要设置或检索影片播放器的缩放模式,请访问其scalingMode属性。状态已更改的电影播放器​​可用作与通知关联的对象。

答案 1 :(得分:0)

这不是“理想”的解决方案,但它有效! 基本上,一旦你退出全屏幕,MPMoviePlayerController实例全部搞砸了,并且将缩放属性重置为MPMovieScalingModeFill无论在何时何地你都没有帮助(我已经尝试了各种各样的东西,一小时后放弃了)。最简单的解决方案是删除MPMoviePlayerController并在每次退出全屏时简单地分配一个新的MPMoviePlayerController实例(不理想,但完全有效):

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:NO];
    if (self.moviePlayer != nil)
        [self.moviePlayer.view removeFromSuperview];
    self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
    self.moviePlayer.view.frame = CGRectMake(#, #, #, #);
    self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    self.moviePlayer.shouldAutoplay = NO;
    [self.moviePlayer setContentURL:self.videoURL];
    [self.moviePlayer prepareToPlay];
    [self.moviePlayer setScalingMode:MPMovieScalingModeFill];
    [self.view addSubview:self.moviePlayer.view];
}
PS:不要忘记打电话给super的viewDidAppear或遭遇各种不可预见的混乱(iOS开发中一个非常常见的错误)