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 に答える