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?

4

2 回答 2

2

添加此观察者

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

查看 MPMoviePlaybackStatePlaying 的通知

- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification {
     if (moviePlayer.playbackState == MPMoviePlaybackStateStopped) {
     }
}
于 2013-12-11T13:00:06.790 回答
1

注册MPMoviePlayerPlaybackStateDidChangeNotification这样的

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

在通知处理程序方法中,检查实际状态 - 例如像这样:

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

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

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

    //is playing

  } else {

  }
}

删除观察者使用此代码

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

有关更多信息,请参阅MPMoviePlayerController_Class 播放属性文档。

于 2013-12-11T13:00:36.143 回答