0

我正在使用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];

}

4

1 回答 1

1

也许是这样:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                     selector:@selector(moviePlayBackDidFinish:) 
                                         name:MPMoviePlayerPlaybackDidFinishNotification 
                                       object:nil];

在上面的行中,您传递了一个 nil 对象,并在您尝试获取它的方法中:

MPMoviePlayerViewController *movie = [notification object];
于 2010-10-29T07:48:26.753 回答