ipad - iOS 在全屏模式下使用 MPMoviePlayerViewController (iPad)

标签 ipad video ios4

我有一个带有 5 个按钮的单 View 应用程序,当按下其中一个按钮时,播放器会向上滑动到原始 View 上并开始全屏播放视频(它应该如此)。

除了按下全屏/最小化图标(播放控件旁边的两个对角箭头指向彼此)外,一切都很好。按下此按钮时,带有五个按钮的原始 View 会在视频播放器上方向上滑动。问题是视频仍在原始 View 下播放。我真的很想消除全屏/最小化图标,但据我所知,这似乎不可能。所以...我在想,当按下全屏/最小化图标时,我可以使用观察者来收听我可以做我需要做的事情。我只是找不到任何关于如何做到这一点的可靠信息。任何帮助/方向将不胜感激。

这是我当前的代码...

-(IBAction)playvideo {

 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
 MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

 [self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

 playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
 [playerController.moviePlayer play];
 [playerController release];
 playerController=nil;
}

- (void)moviePlayerWillExitFullscreen:(NSNotification *)theNotification {

 MPMoviePlayerController *playerController = [theNotification object];
 [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerWillExitFullscreen:)
             name:MPMoviePlayerWillExitFullscreenNotification
              object:nil];

 [playerController stop];
 [self dismissMoviePlayerViewControllerAnimated];
}

最佳答案

这一行导致你出现这种行为。

[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

它与您的常规 presentModalViewController 方法非常相似。

它以模态方式呈现 Movieplayer 及其 View Controller 。所以这里的默认设置是

movieplayer.controlStyle = MPMovieControlStyleFullScreen

这是默认设置。

因此,当您按下这些对角线箭头时,它会退出该模式,并为此发出通知。但是您必须先设置一个观察者来收听该通知,就像您在电影结束时所做的那样。

你做到了

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

这添加了一个通知以观察电影完成通知。 要退出全屏模式,请再添加一个观察者,即这个..

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];

在添加 -(void) movieExitFullScreen:(NSNotification *) 选择器后,您应该可以继续使用了。希望能帮助到你。 :)

关于ipad - iOS 在全屏模式下使用 MPMoviePlayerViewController (iPad),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4027879/

相关文章:

iphone - 应用程序因在第三代 iPad 上崩溃而被拒绝

angularjs - AngularJS-具有完整外部控件的Youtube Player指令

iphone - 警报 View - 如何使用 clickedButtonAtIndex :

iphone - JEFF LAMARCHE 带提示的警报 View 在 iOS 4 中关闭屏幕

objective-c - UIImage 没有显示在 iPad 设备上,但它显示在 iPad 模拟器上

iphone - objective-C 中的私有(private)和公共(public)属性

c++ - 如何在 C++ 中使用 ffmpeg 从 .webm 视频读取 Alpha channel

php - 使用ffmpeg上传视频并将其转换为flv时文件大小增加

objective-c - 从 NSDocumentDirectory 为 UITableViewCells 延迟加载图像?

iphone - 使用动画更改路径的颜色 - iPhone Dev