我正在使用MPMovieplayerViewController播放电影,并且我想在电影停止时注册通知...我正在使用以下代码来使用NSNotification但是当电影停止时我的应用程序崩溃了...我以相同的方式使用了NSNotification早些时候它执行得很好..关于我做错了什么有什么想法吗?
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
NSLog(@"moviePlayBackDidFinish");
MPMoviePlayerViewController *movie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
[self performSelector:@selector(stopRecording) withObject:nil afterDelay:1.0];
}
-(void)playbackFinishedCallback:(NSNotification *)notification{
MPMoviePlayerViewController *movie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
NSLog(@"playbackFinishedCallback:");
[self performSelector:@selector(stopRecording) withObject:nil afterDelay:1.0];
}
在我的 AppDelegate 类中,我已经像这样注册了
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[navigationController release];
[window release];
[super dealloc];
}