Iphone 在iOS 3.2(iPad)中正确显示和禁用全屏MPMoviePlayerController
我在iPad应用程序中显示全屏电影时遇到很多问题,然后允许用户通过播放器控件上的“完成”按钮或“取消全屏”按钮将其关闭 最初,我使用的是Iphone 在iOS 3.2(iPad)中正确显示和禁用全屏MPMoviePlayerController,iphone,cocoa-touch,ipad,mpmovieplayercontroller,ios,Iphone,Cocoa Touch,Ipad,Mpmovieplayercontroller,Ios,我在iPad应用程序中显示全屏电影时遇到很多问题,然后允许用户通过播放器控件上的“完成”按钮或“取消全屏”按钮将其关闭 最初,我使用的是mpmovieplayervcontroller进行电影演示,但我没有从它的mpmovieplayervcontroller对象接收进入/退出全屏通知,所以我改为自己做 我可以让电影全屏显示(虽然转换很简陋),但当按下“完成”或“取消全屏”按钮时,播放器不会采取任何行动。我已经在下面发布了我的代码: - (void)startPlayingMovieWithUR
mpmovieplayervcontroller
进行电影演示,但我没有从它的mpmovieplayervcontroller
对象接收进入/退出全屏通知,所以我改为自己做
我可以让电影全屏显示(虽然转换很简陋),但当按下“完成”或“取消全屏”按钮时,播放器不会采取任何行动。我已经在下面发布了我的代码:
- (void)startPlayingMovieWithURLString:(NSString *)movieURLString {
// I get all of these callbacks **EXCEPT** the "willExitFullScreen:" callback.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.moviePlayerController setContentURL:someExistingURL];
// "self" is a UIViewController subclass, and is presented as a "fullscreen" modal view controller from its parent
// I'm setting the movie player's view's frame to take up the full rectangle of my view controller, but really I want the movie to be completely removed when the user presses "done" (that is, removed from the view hierarchy). Not sure when/where to do this.
self.moviePlayerController.view.frame = self.view.frame;
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController setFullscreen:YES animated:YES];
}
这是我的didfish回调的代码
- (void)didFinishPlayback:(NSNotification *)notification {
// This ends up recursively telling the player that playback ended, thus calling this method, thus…well you get the picture.
// What I'm trying to do here is just make the player go away and show my old UI again.
[self.moviePlayerController setFullscreen:NO animated:YES];
}
所以很明显我做错了什么,但是我一直在上下查阅文档,我不知道如何让这部电影就这么消失了。我觉得这比这更直观。我做错了什么?以下是事件->通知的工作原理:
- 用户按下“完成”按钮
MPMoviePlayerWillExitFullscreenNotification
MPMoviePlayerDidExitFullscreenNotification
- 用户按下传输上的“离开全屏”按钮
MPMoviePlayerWillExitFullscreenNotification
MPMoviePlayerDidExitFullscreenNotification
- 请注意,播放不会停止
- 电影即将结束
将MPMoviePlayerPlaybackDidFinishNotification
设置为MPMoviePlayerPlaybackDidFinishReasonUserInfoKey
mpmoviefinishreasonlaybackend
- 如果在此通知中在MoviePlayerController实例上调用
,则会收到setFullscreen:NO animated:YES
和将退出
通知DidExit
- 请注意,当用户按下“完成”或“离开”全屏按钮时,不会收到
通知playbackdidfish
[self.moviePlayerController.view removeFromSuperview]
放入DidExitFullscreen
通知处理程序中<代码>将退出完整屏幕太早
这是我的密码:
- (void)willEnterFullscreen:(NSNotification*)notification {
NSLog(@"willEnterFullscreen");
}
- (void)enteredFullscreen:(NSNotification*)notification {
NSLog(@"enteredFullscreen");
}
- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(@"willExitFullscreen");
}
- (void)exitedFullscreen:(NSNotification*)notification {
NSLog(@"exitedFullscreen");
[self.movieController.view removeFromSuperview];
self.movieController = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)playbackFinished:(NSNotification*)notification {
NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason intValue]) {
case MPMovieFinishReasonPlaybackEnded:
NSLog(@"playbackFinished. Reason: Playback Ended");
break;
case MPMovieFinishReasonPlaybackError:
NSLog(@"playbackFinished. Reason: Playback Error");
break;
case MPMovieFinishReasonUserExited:
NSLog(@"playbackFinished. Reason: User Exited");
break;
default:
break;
}
[self.movieController setFullscreen:NO animated:YES];
}
- (void)showMovie {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enteredFullscreen:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
NSURL* movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"tron" ofType:@"mov"]];
self.movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.movieController.view.frame = self.view.frame;
[self.view addSubview:movieController.view];
[self.movieController setFullscreen:YES animated:YES];
[self.movieController play];
}
对。太好了。上面确实提到了一些通知 但是,没有MPMoviePlayerPlaybackWillFinishNotification somewhy!!! 这真是个问题 当您将电影播放器作为模式调用时(无论以下哪种方法使用presentViewController/presentModalViewController/presentVideoController),如果您定义了.fullScreen=YES,则它根本不需要调用MPMoviePlayerWillExitFullscreenNotification通知(显然,因为它不是命令,所以我们进入/退出全屏,但只显示/关闭控制器) 但实际上没有任何关于视频即将完成和关闭的通知。这是需要(除了任何其他可能的情况)抓住解雇过渡开始的时刻。(当然,过渡在调用MPMoviePlayerPlaybackDidFinishNotification之前开始)。同时,在通知之前调用了application:SupportedInterfaceOrientionsforWindow:for先前显示的控制器,并且无法告诉AppDelegate当前控制器必须已经以另一个方向显示
因此,由于我的视频是全屏的,也没有显示任何控件(这是一种介绍,所以我只是在它完成之前)我的解决方案就是有一个计时器,它每短时间(0.1秒)检查一次视频的当前位置是什么…现在已经接近尾声了,现在是我自己通知的时候了。这很有帮助,当用户按“完成”时,我现在可以全屏退出,但是-playbackpunched:回调永远不会为我执行,我一辈子也弄不明白为什么不执行。你知道什么原因吗为什么会发生这种情况?即使电影播放到最后?这很奇怪,我从来没有遇到过。如果MPMoviePlayerDexitFullScreenNotification在触摸“完成”时同时调用在退出全屏时,您如何知道调用了哪个?可能用户只退出全屏,在这种情况下,我猜您不想删除视图。请注意,更改MPMoviePlayer[Will/Did][Exit/Enter]全屏通知中的控制样式会使进一步的通知陷入混乱状态。连线:有史以来最好的答案,谢谢