微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

iOS 7 MPMoviePlayerController寻找前进按钮将视频带到结束并显示黑屏

我在iOS 7中面临MPMoviePlayerController的问题.我进入全屏,然后在寻找前进按钮(>> |)上单击(只需点一下),视频播放结束,并给出一个带有文本“加载“标题.

注册了“MPMoviePlayerPlaybackStateDidChangeNotification”的通知.

**[[NSNotificationCenter defaultCenter] addobserver:self
                                             selector:@selector(moviePlayerPlaybackStateDidChange:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:self.player];**

只需点击一下寻找前进按钮就不会被解雇.

注册了“MPMoviePlayerPlaybackDidFinishNotification”

**[[NSNotificationCenter defaultCenter] addobserver:self
                                             selector:@selector(moviePlayerPlaybackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];**

我获得“MPMovieFinishReasonPlaybackEnded”事件触发了单击寻找前进按钮.
任何人都知道为什么?这是苹果的错误吗?

我需要停止这种单击时显示黑色屏幕的行为,或者只是禁用单击“寻找前进”按钮,这样就不会发生任何事情.

任何人都知道如何实现这一点?

解决方法

我通过完全删除MPMoviePlayer对象来修复此问题,将其设置为nil,将其从超级视图中删除,并使用原始视频Url重新添加.代码如下:
- (void)addplayerForUrl:(NSURL *)url {
  self.player = [[MPMoviePlayerController alloc] initWithContentURL:url];
  self.player.view.frame = self.videoView.bounds;
  self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  self.player.controlStyle = MPMovieControlStyleDefault;
  [self.videoView insertSubview:self.player.view atIndex:0];

  [[NSNotificationCenter defaultCenter] addobserver:self
                                           selector:@selector(moviePlayerLoadStateDidChangednotification:)
                                               name:MPMoviePlayerReadyFordisplayDidChangeNotification
                                             object:self.player];

  [[NSNotificationCenter defaultCenter] addobserver:self
                                           selector:@selector(moviePlayerPlaybackStateDidChangeNotification:)
                                               name:MPMoviePlayerPlaybackStateDidChangeNotification
                                             object:self.player];
}


#pragma mark - Notifications

- (void)moviePlayerLoadStateDidChangednotification:(NSNotification *)notification {
  self.isVideoPreloaded = YES;
  self.videoPlayButton.hidden = YES;
  self.photoImageView.hidden = YES;
  self.videoLoadingImageView.hidden = YES;
}
- (void)moviePlayerPlaybackStateDidChangeNotification:(NSNotification *)notification {
      NSURL *url = self.player.contentURL;
      switch (self.player.playbackState) {
        case MPMoviePlaybackStateSeekingBackward:
        case MPMoviePlaybackStateSeekingForward:
          break;
        case MPMoviePlaybackStatePlaying:
          self.videoPlayButton.hidden = YES;

          if (!self.isVideoPreloaded) {
            self.videoLoadingImageView.hidden = NO;
            [self.videoLoadingImageView startAnimating];
          } else {
            self.videoLoadingImageView.hidden = YES;
          }
          break;
        case MPMoviePlaybackStatePaused:
        case MPMoviePlaybackStateStopped:
          self.videoPlayButton.hidden = NO;
          self.videoLoadingImageView.hidden = YES;
          [self.player endSeeking];
          [self.player.view removeFromSuperview];
          [self.player setFullscreen:NO];
          self.player = nil;
          [self addplayerForUrl:url];
          break;
        default:
          break;
      }
    }

注意我如何保持NSURL,就在moviePlayerPlaybackStateDidChangeNotification中的switch语句之前.这样,我可以重新初始化并重新添加MPMoviePlayer对象.

Btw,我的mpmovieplayer是在tableviewCell,如果你想知道.希望这有帮助,让我知道如果你有问题.祝你好运!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐