iphone - 在电影播放结束时切换 View Controller ?

标签 iphone objective-c mpmovieplayercontroller

在我的应用程序中,有一个最终用户可以按下的 UIButton,它会按下使用 MPMoviePlayerController 在帧中播放视频的 View Controller 。

我希望能够检测视频何时结束,当发生这种情况时,推送一个新的 View Controller 。虽然我似乎找不到可以做到这一点的代码。

有人知道该怎么做吗?

视频播放代码如下所示:

//video stuff
CGRect myVideoRect = CGRectMake(0.0f, 145.0f, 320.0f, 160.0f);
movieUrl = [[NSBundle mainBundle] URLForResource:@"myMovie" withExtension:@"m4v"];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
[[moviePlayerController view] setFrame:myVideoRect];
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];

谢谢!

最佳答案

注册您的 View Controller 以监听播放器的playbackdidfinish通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];

然后实现一个playbackFinished方法,您可以在其中推送新的 View Controller 或执行任何其他操作。

关于iphone - 在电影播放结束时切换 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5627972/

相关文章:

iphone - 在后台线程中使用 "setNeedsDisplay"方法时访问错误

iphone - 如何检测用户是否在 UIScrollView 中向后滚动了一个 View ?

ios - 由于内容中的换行导致 xml 解析不准确

iphone - 在没有控件的情况下在 iPhone 中打开视频

iphone - MPMoviePlayerViewController 拔下耳机时停止播放

iphone - Div 在 iphone 上不跨越整个宽度

ios - 为什么当我暂停 AVAudioPlayer 时锁屏音频控件会消失?

objective-c - 在 Swift 中使用一个返回 Optional 或 Throw 的 Objective-C 函数

c++ - C++ 中的派生类型转换问题

iphone - 工具栏上带有自定义按钮的 MPMoviePlayerController