Iphone 电影结束回调通知未触发
我正在尝试创建一个应用程序,在视频停止播放时显示信息页面。我在这里看到了一个类似的问题,并试图实现它,但它仍然不起作用。我在movieFinishedCallback方法中添加了一个NSLog,但从未出现过,所以我猜它甚至没有被调用。有人能帮我弄清楚吗 这是我的实现代码Iphone 电影结束回调通知未触发,iphone,xcode,video,uiviewcontroller,mpmovieplayercontroller,Iphone,Xcode,Video,Uiviewcontroller,Mpmovieplayercontroller,我正在尝试创建一个应用程序,在视频停止播放时显示信息页面。我在这里看到了一个类似的问题,并试图实现它,但它仍然不起作用。我在movieFinishedCallback方法中添加了一个NSLog,但从未出现过,所以我猜它甚至没有被调用。有人能帮我弄清楚吗 这是我的实现代码 -(IBAction)playvideo { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
-(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];
}
我想你们可能会在电影结束后被召回,但在展示View2时失败了 View2是UIViewController的子类吗?通过将nil传递给initWithNibName:,我看不出如何获得有效的结果。我建议在电影《FinishedCallback》中写一篇NSLog来证明你做到了。然后是NSLog(@“second=%@),second);我猜那是零 修复方法是使用有效的nib或从故事板加载视图控制器
// @"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];
终于成功了!我不知道这是否与MPMoviePlayerController不响应NSNotificationCenter有关,但我使用MPMoviePlayerController来显示我的视频,注册了movieFinishedCallback的通知,然后使用movieFinishedCallback方法切换视图。有关视频播放,请参见本教程。唯一的问题是,现在的视频将不会旋转到风景 谢谢@danh!是的,View2是UIViewController的子类。我尝试在movieFinishedCallback中添加一个NSLog,但它没有出现,所以可能没有被调用。视频播放得很好,但我也收到了多个…“错误加载/System/Library/Extensions/AudioIPCDriver.kext/Contents/…”最后它说找不到工厂的函数指针NewDigiCoreAudioPlugIn。。。。(捆绑,未加载)。请帮忙?我想你可以忽略播放时的错误MSG。广泛报道的模拟器问题。需要考虑一下接到通知的情况。你能看看你是否能收到loadstatechanged通知吗?那也没有记录任何东西(