How to detect MPMoviePlayerController starts a movie?

Sagi Mann picture Sagi Mann · Oct 1, 2013 · Viewed 11.2k times · Source

I am using MPMoviePlayerController, how do I detect when the movie actually started playing - as opposed to when the user fiddles with the seek controls?

From the tests I made, I always get a "load state change" event and (moviePlayer.loadState == MPMovieLoadStatePlayable) is TRUE whenever the movie starts AND after the user dragged the seek control (even if he dragged it from end to middle - not necessarily to the beginning of the movie). How do I distinguish between movie-start and seek?

Answer

Vivek Sehrawat picture Vivek Sehrawat · Oct 1, 2013
    MPMoviePlaybackState
    Constants describing the current playback state of the movie player.
    enum {
       MPMoviePlaybackStateStopped,
       MPMoviePlaybackStatePlaying,
       MPMoviePlaybackStatePaused,
       MPMoviePlaybackStateInterrupted,
       MPMoviePlaybackStateSeekingForward,
       MPMoviePlaybackStateSeekingBackward
    };
    typedef NSInteger MPMoviePlaybackState;

Register for the MPMoviePlayerPlaybackStateDidChangeNotification

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

Check in this function MPMoviePlaybackState

- (void)MPMoviePlayerPlaybackStateDidChange:(NSNotification *)notification
    {
      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
      }

}

Remove notification by

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

Refer :MPMoviePlaybackState