Iphone MPMoviePlayerViewController done按钮未删除播放机
我的应用程序必须在Ios5及更高版本中运行。单击按钮时,我正在将MPMoviePlayerController添加到主窗口。moviePlayerController的“完成”按钮并没有从窗口中删除moviePlayerController 我的代码是Iphone MPMoviePlayerViewController done按钮未删除播放机,iphone,ios,mpmovieplayercontroller,Iphone,Ios,Mpmovieplayercontroller,我的应用程序必须在Ios5及更高版本中运行。单击按钮时,我正在将MPMoviePlayerController添加到主窗口。moviePlayerController的“完成”按钮并没有从窗口中删除moviePlayerController 我的代码是 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"001 A
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"001 ATSW" ofType:@"m4v"]];
self.player = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.player.view setFrame:[UIScreen mainScreen].bounds];
[[[UIApplication sharedApplication] keyWindow] addSubview:self.player.view];
[[self.player moviePlayer] play];
}
-(void)videoPlayBackDidFinish:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.player.moviePlayer stop];
self.player = nil;
[self.player.view removeFromSuperview];
}
如何单击“完成”按钮移除moviePlayerController
请提供任何帮助。如文档中所述: 要关闭以模式显示的电影播放器视图控制器,请调用
dismissmovieplayervicecontrolleranimated
方法
与Apple的其他预配置控制器(如mail compose控制器或image picker控制器)一样,您有责任关闭该控制器。您可能需要做的是实际使用
presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerVC
方法来显示MPMoviewPlayerViewController,而不直接插入视图。当按下“完成”按钮时,MPMoviewPlayerViewController试图自行关闭。从我所看到的来看,没有什么好方法可以像电影结束时那样去听和做
这可能取决于你的应用程序是如何构建的,但有一些类似于
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentMoviePlayerViewControllerAnimated:player];
您应该能够替换所有代码以插入一个视图,然后使用
[[[[UIApplication sharedApplication] keyWindow] rootViewController] dismissMoviePlayerViewControllerAnimated];