views:

20

answers:

1

Hi Folks,

I am facing a problem in ipad video incorporating. My code works fine I mean it plays the video, but once the video reaches to its end. The callback method is not called.

This method is called when play video button is pressed.

-(IBAction) playVideo : (id) sender
{
  [self initPlayingVideo:@"toyVid.mp4"];
}

This method handles the playing of video.

-(void) initPlayingVideo: (NSString *) videoFile
{
  NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:videoFile];

  theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
  theMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
  theMovie.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;


  [self.view addSubview:theMovie.view];

  [[NSNotificationCenter defaultCenter]
  addObserver:self
  selector:@selector(videoPlayerDidFinishPlaying
  name:MPMoviePlayerPlaybackDidFinishNotification
  object:theMovie];

  videoPlayer = [theMovie moviePlayer];
  [videoPlayer play];
}

This is the callback method.

-(void) videoPlayerDidFinishPlaying: (NSNotification*)aNotification
{
  theMovie = [aNotification object];
  [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie.moviePlayer];
  [videoPlayer stop];
  [theMovie.moviePlayer release];
  [videoPlayer release];
  [theMovie.view removeFromSuperview];
}

Where I am doing mistake? Please guide.

Regards Ranjan

A: 

Did you miss the : and ) in your selector? I guess ) may be your typo otherwise you cannot compile your codes. Your selection takes one parameter. It should be:

selector:@selector(videoPlayerDidFinishPlaying:)

That will match to your instance method. I guess you don't have one without parameter.

David.Chu.ca
Thanks for your reply David.The listener function is as under. colon(:) and closing parenthesis ")" is there.[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayerDidFinishPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
iWasRobot
The object was wrong. Object: [theMovie moviePlayer];
iWasRobot