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

前端之家收集整理的这篇文章主要介绍了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

原文链接:https://www.f2er.com/iOS/329215.html

猜你在找的iOS相关文章