iOS AVPlayer showing screen with a cross line on Play icon

三世轮回 提交于 2019-12-13 14:13:07

问题


Screen Shot of AVPlayer error

Below is the code snippet, url is the the video url. This error occurs randomly. I'm unable to trace what is the issue. Also the video is stored in cloud and video buggers to play on the AVPlayer. Is anything missing in the below code.

+ (void)presentVideoForURL:(NSURL *)URL parentViewController:(UIViewController *)parentViewController {

      AVAudioSession *audioSession = [AVAudioSession sharedInstance];
      NSError *setCategoryError;
      if (![audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]) {
           Error(@"setCategoryError %@", setCategoryError.localizedDescription);
      }
      NSError *activationError;
      if (![audioSession setActive:YES error:&activationError]) {
           Error(@"activationError: %@", activationError.localizedDescription);
      }

      AVPlayer *player = [[AVPlayer alloc] initWithURL:URL];
      AVPlayerViewController *playerController = [[AVPlayerViewController alloc] init];
      playerController.player = player;

      [parentViewController presentViewController:playerController animated:YES completion:^{
           [player play];
           [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:AVPlayerItemDidPlayToEndTimeNotification object:player.currentItem];
           [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:AVPlayerItemFailedToPlayToEndTimeNotification object:player.currentItem];
      }];
}

回答1:


Check the following 2 scenarios.

1) Check whether the url is correct or not.

2) If your network is slow and AVPlayer is not getting adequate data into it's buffer,it stops loading and shows a UI like you mentioned (A cross bar in play button).So try using high sped network. If this is the issue,you can restart the player using the playback stall notification.

I had the 2nd issue and I fixed the same like this.



来源:https://stackoverflow.com/questions/37989932/ios-avplayer-showing-screen-with-a-cross-line-on-play-icon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!