iOS 7 MPMoviePlayerController搜索转发按钮将视频带到结束并显示黑屏

[英]iOS 7 MPMoviePlayerController seek forward button brings the video to the End and displays Black screen


I am facing an issue with MPMoviePlayerController in iOS 7. I enter the fullscreen and then click (just a single tap) on seek forward button (>>|) , and the video playback ends and gives a black screen with a text "Loading" on the header.

我在iOS 7中遇到了MPMoviePlayerController的问题。我进入全屏,然后点击(只需点击一下)搜索转发按钮(>> |),视频播放结束并给出带有文本“正在加载”的黑屏在标题上。

I registered notification for "MPMoviePlayerPlaybackStateDidChangeNotification".

我注册了“MPMoviePlayerPlaybackStateDidChangeNotification”的通知。

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

It does not get fired on a single click of seek forward button.

单击“向前搜索”按钮不会触发它。

Also on registration of "MPMoviePlayerPlaybackDidFinishNotification"

同时注册“MPMoviePlayerPlaybackDidFinishNotification”

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

I get "MPMovieFinishReasonPlaybackEnded" event fired on that single click of seek forward button. Any one knows the reason why? Is this a bug in apple?

我点击了“向前搜索”按钮,就会触发“MPMovieFinishReasonPlaybackEnded”事件。谁知道原因?这是苹果中的错误吗?

I need to either stop this behavior of showing a black screen on single click , or just disable single click of seek forward button so that nothing happens.

我需要停止在单击时显示黑屏的行为,或者只是禁用单击“向前搜索”按钮以便不会发生任何事情。

Any one knows how to achieve this?

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

3 个解决方案

#1


2  

I fixed this by removing the MPMoviePlayer object completely, setting it to nil, removing it from it's superview and re-adding it using the original video Url. Code below:

我通过完全删除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;
      }
    }

Notice how I keep the NSURL, right before the switch statement in the moviePlayerPlaybackStateDidChangeNotification. That way, I can re-initialize and re-add the MPMoviePlayer object.

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

Btw, my mpmovieplayer is on a tableviewCell if you're wondering. Hope this helps and let me know if you have questions. Good luck!

顺便说一句,如果你想知道的话,我的mpmovieplayer就在tableviewCell上。希望这有帮助,如果您有疑问,请告诉我。祝你好运!

#2


2  

MPMoviePlayerLoadStateDidChangeNotification will be called when you single tap on the fast-forward or rewind button. You should check the loadState and just give it the path to your video and prepareToPlay again.

单击快进或快退按钮时,将调用MPMoviePlayerLoadStateDidChangeNotification。你应该检查一下loadState,然后再给它一个视频的路径,再给prepareToPlay。

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

    MPMoviePlayerController *moviePlayer = notification.object;
    MPMovieLoadState loadState = moviePlayer.loadState;

    if(loadState == MPMovieLoadStateUnknown) {
        moviePlayer.contentURL = [NSURL fileURLWithPath:videoPath]
        [moviePlayer prepareToPlay];
    }

    .....
}

#3


0  

The reason you're getting MPMovieFinishReasonPlaybackEnded is because playback reached the end of the video (sorry if this is obvious). So it seem's your seek forward actions are seeking all the way to the end of the video. You can check the playback state with MPMoviePlaybackStateSeekingForward.

你获得MPMovieFinishReasonPlaybackEnded的原因是因为播放到达了视频的结尾(对不起,如果这很明显)。因此,您的前瞻性行动似乎一直在寻找视频的结尾。您可以使用MPMoviePlaybackStateSeekingForward检查播放状态。

A quick solution could be to create your own forward button that seek's ahead by a specified time (ie. 5 seconds). But perhaps this isn't the functionality you're looking for.

一个快速的解决方案可能是创建自己的前进按钮,在指定的时间(即5秒)内寻找前进。但也许这不是您正在寻找的功能。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2013/10/24/2f5364e5dbb5f677f466236699a1e60c.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号