当我单击播放按钮时,我的视频可以正常工作,并且我知道 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/