2

I am using MPMoviePlayerViewController to play a movie , I create a method which should detects when movie is finished then run a method :

- (void)movieFinishedWithSelector:(SEL)selectors {

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(selectors)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:[player moviePlayer]];
  }

and use this method like this , but does not work .

[self movieFinishedWithSelector:@selector(finished)];

Am I missing something ?

4

3 回答 3

2

selectors参数已经是一个选择器。不要使用@selector

- (void)movieFinishedWithSelector:(SEL)selector {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:selector
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:[player moviePlayer]];
}
于 2013-09-02T20:40:18.443 回答
2

加载电影时创建通知

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(myMovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:movieController];

完成后 myMovieFinished 将被调用

-(void)myMovieFinished:(NSNotification *)aNotification
{
    NSLog(@"%@",aNotification.userInfo);
   int reason =    [[[aNotification userInfo]valueForKey:MPMoviePlayerPlaybackDidFinishNotification]intValue];
    if (reason==MPMovieFinishReasonPlaybackEnded) {
        NSLog(@"Movie finished playing");
    }
    else if (reason==MPMovieFinishReasonUserExited)
    {
        NSLog(@"Movie finished because user exited");
    }
    else if (reason==MPMovieFinishReasonPlaybackError)
    {
        NSLog(@"movie finished playback error");
    }

    movieController=[aNotification object];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:movieController ];

}
于 2013-10-01T14:14:36.543 回答
0

你是如何定义选择器的?它应该是:

- (void)movieDidFinish:(NSNotification*)notification
于 2013-10-01T11:42:06.767 回答