Reputation: 6051
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 ?
Upvotes: 2
Views: 325
Reputation: 1258
create a notication when you load the movie
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(myMovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:movieController];
When finished the myMovieFinished will be called
-(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 ];
}
Upvotes: 2
Reputation: 3610
how did you define the selector? It should be:
- (void)movieDidFinish:(NSNotification*)notification
Upvotes: 0
Reputation: 318774
The selectors
parameter is already a selector. Don't use @selector
:
- (void)movieFinishedWithSelector:(SEL)selector {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:selector
name:MPMoviePlayerPlaybackDidFinishNotification
object:[player moviePlayer]];
}
Upvotes: 2