ios – 如何检测MPMoviePlayerController启动电影?

我正在使用MPMoviePlayerController,如何检测电影实际上开始播放的时间 – 而不是用户搜索控件时遇到的问题?

从我做的测试中,我总是得到一个“加载状态更改”事件,并且(moviePlayer.loadState == MPMovieLoadStatePlayable)在电影启动时为TRUE,用户拖动了搜索控件(即使他从一端拖到另一端)不一定要到电影的开头).我如何区分电影开始和寻找?

解决方法

MPMoviePlaybackState
    Constants describing the current playback state of the movie player.
    enum {
       MPMoviePlaybackStateStopped,MPMoviePlaybackStatePlaying,MPMoviePlaybackStatePaused,MPMoviePlaybackStateInterrupted,MPMoviePlaybackStateSeekingForward,MPMoviePlaybackStateSeekingBackward
    };
    typedef NSInteger MPMoviePlaybackState;

注册MPMoviePlayerPlaybackStateDidChangeNotification

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

检查此功能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
      }

}

删除通知

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

参考:MPMoviePlaybackState

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...