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

前端之家收集整理的这篇文章主要介绍了ios – 如何检测MPMoviePlayerController启动电影?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用MPMoviePlayerController,如何检测电影实际上开始播放的时间 – 而不是用户搜索控件时遇到的问题?

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

解决方法

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

注册MPMoviePlayerPlaybackStateDidChangeNotification

  1. [[NSNotificationCenter defaultCenter] addObserver:self
  2. selector:@selector(MPMoviePlayerPlaybackStateDidChange:)
  3. name:MPMoviePlayerPlaybackStateDidChangeNotification
  4. object:nil];

检查此功能MPMoviePlaybackState

  1. - (void)MPMoviePlayerPlaybackStateDidChange:(NSNotification *)notification
  2. {
  3. if (player.playbackState == MPMoviePlaybackStatePlaying)
  4. { //playing
  5. }
  6. if (player.playbackState == MPMoviePlaybackStateStopped)
  7. { //stopped
  8. }if (player.playbackState == MPMoviePlaybackStatePaused)
  9. { //paused
  10. }if (player.playbackState == MPMoviePlaybackStateInterrupted)
  11. { //interrupted
  12. }if (player.playbackState == MPMoviePlaybackStateSeekingForward)
  13. { //seeking forward
  14. }if (player.playbackState == MPMoviePlaybackStateSeekingBackward)
  15. { //seeking backward
  16. }
  17.  
  18. }

删除通知

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

参考:MPMoviePlaybackState

猜你在找的iOS相关文章