iphone - 播放视频后更改 View

标签 iphone view mpmovieplayercontroller nsnotifications nsnotificationcenter

当我单击播放按钮时,我的视频可以正常工作,并且我知道 View 更改的代码可以正常工作。我的视频播放完毕后,我似乎无法改变 View ,不知道出了什么问题。有什么想法可以在视频播放完毕后改变 View 吗?

我的播放电影的代码

-(IBAction)playMovie:(id)sender {
NSString *movieUrl = [[NSBundle mainBundle] pathForResource:@"Movie_1666" ofType:@"m4v"]; 
playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movieUrl]];
//Smoothe Transition
//[self presentMoviePlayerViewControllerAnimated:playerController];
//Instant Transistion
[self presentModalViewController:playerController animated:NO];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[playerController.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerController]; }

我改变观点的方法

- (void)playbackFinished:(NSNotification*) notification {
MPMoviePlayerController *playerController = [notification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:playerController];

View2 *view2 = [[View2 alloc] initWithNibName:@"View2" bundle:nil];
View2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:view2 animated:YES]; }

编辑: 我的Notification对象是错误的并且没有触发我的playbackFinished方法 此更改解决了这个问题。

- (void)playbackFinished:(NSNotification*) notification {
playerController = [notification object];
[[NSNotificationCenter defaultCenter] 
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:playerController];

我还将其放入我的头文件中,使其成为全局的,以便在我的playbackFinished 方法中使用

MPMoviePlayerViewController *playerController;

最佳答案

电影播放完毕后,关闭 playerController View (不带动画)。另请检查您是否在主线程中呈现 View2

编辑: 通过

关闭playerController
[playerController dismissModalViewControllerAnimated:NO];

关于iphone - 播放视频后更改 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7873997/

相关文章:

ios - iPad MoviePlayer 在设备重启之前拒绝播放视频

ios - MPMoviePlayerController 起始图像

ios - 缺少闭包默认初始值设定项 - 快速闭包变量声明?

database - 在 CouchDb View 中列出所有数据库,验证函数

android - 膨胀 View 导致 RAM 使用增加 40mb

iphone - MPMoviePlayerController 在 iPhone 应用程序中反向(向后)播放电影不流畅

ios - 将多个托管对象上下文与核心数据库一起使用

ios - 如何减慢 iOS 版 Google map 中的相机动画位置?

ios - 容器 View Controller 中的导航 Controller 问题

python - 尝试使用外键从不同类中按字段进行选择,出现错误