我正在尝试创建一个视频停止播放后显示信息页面的应用。我看过这里发布的类似问题并试图实现它,但它仍然无法正常工作。我在movieFinishedCallback方法中放了一个NSLog,但是从来没有出现过,所以我猜它甚至没有被调用。有人可以帮我搞清楚吗?
这是我的实施代码......
-(IBAction)playvideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"sample" ofType:@"mov"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playercontroller];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
}
- (void) movieFinishedCallback:(NSNotification*) notification {
NSLog (@"The video ended");
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
player = nil;
View2 *second =[[View2 alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
答案 0 :(得分:0)
我认为你可能会在电影结束后回电话,但在呈现View2时会失败。
View2是UIViewController的子类吗?我无法通过将nil传递给initWithNibName来看到如何获得有效结果:我建议在movieFinishedCallback中使用NSLog来证明你到达那里。然后是NSLog(@“second =%@”,第二个);我的猜测是没有。
修复方法是使用有效的笔尖或故事板加载一个真实的视图控制器......
// @"MainStoryboard" should be the name of the storyboard containing your VC
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
// @"SomeViewController" has to be set on the attributes inspector of the VC
// in the storyboard
SomeViewController *newVC = [storyboard instantiateViewControllerWithIdentifier:@"SomeViewController"];
[self presentModalViewController:newVC animated:YES];
答案 1 :(得分:0)
最终让它发挥作用!我不知道是否与MPMoviePlayerViewController没有响应NSNotificationCenter这一事实有关,但我使用MPMoviePlayerController来显示我的视频,注册了movieFinishedCallback的通知,然后使用movieFinishedCallback方法切换视图。请参阅本教程了解视频播放http://www.techotopia.com/index.php/Video_Playback_from_within_an_iOS_5_iPhone_Application。唯一的问题是,现在视频不会旋转到风景!