0

I need to show images and videos as the slide show in an application. I have kept the images and videos link in an array and determining which is video and which is image, and set the slide show timings according to the video time length and 2 sec for each image, Now the problem is when I start the slide show and the video comes and it plays, I cannot determine the video is stopped playing or not?

I am using MPMediaplayer and checking the stopping by

      if (player.playbackState == MPMoviePlaybackStatePlaying)
      { //playing
      }
      if (player.playbackState == MPMoviePlaybackStateStopped)
      { //stopped
      }if (player.playbackState == MPMoviePlaybackStatePaused)
      { //paused
      }if (player.playbackState == MPMoviePlaybackStateInterrupted)
      { //interrupted
      }if (player.playbackState == MPMoviePlaybackStateSeekingForward)
      { //seeking forward
      }if (player.playbackState == MPMoviePlaybackStateSeekingBackward)
      { //seeking backward
      }

But all the time it is going to the MPMoviePlaybackStatePaused section, when the video is stopped. Can anyone help me why it is going to that condition all the time when video stopped ? or any other method that can help me to determine the video is stopped playing?

Manab Kumar Mal
  • 20,788
  • 5
  • 31
  • 43

2 Answers2

2

Add this observer

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

Check out the notifications for MPMoviePlaybackStatePlaying

- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification {
     if (moviePlayer.playbackState == MPMoviePlaybackStateStopped) {
     }
}
Mohammad Rabi
  • 1,412
  • 2
  • 21
  • 41
1

Register for the MPMoviePlayerPlaybackStateDidChangeNotification like this

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(MPMoviePlayerPlaybackStateDidChange:) 
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification 
                                               object:nil];

Within the notification handler method, check for the actual state - e.g. like this:

- (void)MPMoviePlayerPlaybackStateDidChange:(NSNotification *)notification
{

  if (player.playbackState == MPMoviePlaybackStateStopped)
  { 
     //stopped playing

  } else if (player.playbackState == MPMoviePlaybackStatePlaying) {

    //is playing

  } else {

  }
}

to remove the observer use this code

[[NSNotificationCenter defaultCenter] removeObserver:self 
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:nil];

refer MPMoviePlayerController_Class playback property doc for more info.

Suhit Patil
  • 11,748
  • 3
  • 50
  • 60
  • Is there any problem arises if we don't remove the observer, as we have practiced to remove the observer in normal Notification Center? – Manab Kumar Mal Dec 11 '13 at 13:09
  • Will I use the code like, `[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];` in the `MPMoviePlayerPlaybackStateDidChange` Method? – Manab Kumar Mal Dec 11 '13 at 13:15