开发者

registering for NSNotification crashing my application?

i am playing a movie using MPMovieplayerViewController and i want to register for notifications when the movie stops...i am using the following code to use NSNotification but my application is crashing when the movie stops...i have used the NSNotification in same way earlier when it executed fine.. any idea regarding what i am doing wrong??

[[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];


}

in my AppDelegate class i have registered like this

- (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];

}


Maybe it's that :

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

In the line above you pass a nil object and in the method you try to get it :

MPMoviePlayerViewController *movie = [notification object];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜