gpt4 book ai didi

ios - 退出全屏后 MPMoviePlayerController 在 ios 中将缩放模式设置为 MPMovieScalingModeFill

转载 作者:可可西里 更新时间:2023-11-01 06:15:43 24 4
gpt4 key购买 nike

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

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

然后在我全屏观看视频并退出全屏后不将缩放模式设置为MPmovieScalingmode 以默认模式填充和显示视频。

在我的视频播放代码下方

[[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];}

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

请帮帮我。

谢谢。

最佳答案

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

关于ios - 退出全屏后 MPMoviePlayerController 在 ios 中将缩放模式设置为 MPMovieScalingModeFill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18140805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com