3

当我点击我的播放按钮时,我的视频就可以工作,并且我知道我的视图的代码可以更改。在视频播放完后,我似乎无法改变视图,但并不确定哪里出了问题。一旦视频播放完成后,任何想法都会让视图发生变化?播放视频后更改视图

我的代码,以播放电影

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

编辑: 我通知的对象是错误的,并没有触发我playbackFinished方法 这一变化解决了。

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

我也把这个在我的头文件,使其全球用在我的playbackFinished方法

MPMoviePlayerViewController *playerController; 

回答

1

一旦影片播放完毕后,关闭该playerController视图,而无需动画。另外检查一下,你是否在主线程中显示View2

编辑: 关闭该playerController通过

[playerController dismissModalViewControllerAnimated:NO]; 
+0

不太清楚如何让魔术发生。我不知道如何解除playerController,我不能释放它。另外我如何在主线程中呈现View2? – Sam

+0

我用代码更新了我的答案以关闭playerController。 – Ilanchezhian

+0

谢谢兰克,指出我对我的不好通知 – Sam