繁体   English   中英

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

[英]After exit full screen MPMoviePlayerController set scaling mode to MPMovieScalingModeFill in ios

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

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

然后在我全屏观看视频并退出全屏后,不将缩放模式设置为MPmovieScalingmodeFill并以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];}

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

请帮帮我。

谢谢。

我相信这会生成MPMoviePlayerScalingModeDidChangeNotification

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

MPMoviePlayerScalingModeDidChangeNotification

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

这不是“理想”的解决方案,但它有效! 基本上,一旦你退出全屏幕,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开发中一个非常常见的错误)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM