1 xcode
我一直试图解决这个问题,并试图遵循任何建议,但在用户按下电影播放器上的"完成"后,我似乎无法让'MPMoviePlayerPlaybackDidFinishNotification'工作.
- (void)myMovieFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie pause];
[theMovie stop];
[theMovie autorelease];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
- (void)myMovieViewFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerViewController* theMovieView=[aNotification object];
[self dismissMoviePlayerViewControllerAnimated];
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovieView];
[theMovieView pause];
[theMovieView stop];
[theMovieView autorelease];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
- (IBAction)safetyVideo:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Ball_Crunch" ofType:@"m4v"];
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
MPMoviePlayerViewController*tmpMoviePlayViewController=[[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]] retain];
if (tmpMoviePlayViewController) {
[self presentMoviePlayerViewControllerAnimated:tmpMoviePlayViewController];
tmpMoviePlayViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieViewFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:tmpMoviePlayViewController];
[tmpMoviePlayViewController.moviePlayer play];
}
}else{
MPMoviePlayerController* theMovie = [[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]] retain];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play];
}
}
Run Code Online (Sandbox Code Playgroud)
按下"完成"时电影播放正常并消失,但从不调用回调.有什么建议?
谢谢.