Ios 使用AVPlayer在UITableViewCell中播放视频始终获得AVPlayerTemplateBackstalledNotification

Ios 使用AVPlayer在UITableViewCell中播放视频始终获得AVPlayerTemplateBackstalledNotification,ios,objective-c,uitableview,video,avplayer,Ios,Objective C,Uitableview,Video,Avplayer,我正在尝试使用AVPlayer在UITableViewCell中播放url中的视频(与instagram不完全一样,但距离足够近) 我试图一次播放一个视频。 当我点击单元中的“播放”按钮时,视频开始播放,但仅播放1或2秒,然后我会收到一个AVPlayerTemplateBackstalledNotification 我在CustomTableViewCell.h中声明 @property AVPlayer *player; @property AVPlayerItem *playerIt

我正在尝试使用AVPlayer在UITableViewCell中播放url中的视频(与instagram不完全一样,但距离足够近)

我试图一次播放一个视频。 当我点击单元中的“播放”按钮时,视频开始播放,但仅播放1或2秒,然后我会收到一个AVPlayerTemplateBackstalledNotification

我在CustomTableViewCell.h中声明

  @property AVPlayer *player;
  @property AVPlayerItem *playerItem;
  @property AVPlayerLayer *playerLayer;
  @property AVAsset *playerAsset;
  @property NSString *playerUrl;
然后我的ViewController.m中有一个iAction

 - (IBAction)play:(id)sender {

   CustomCell *clickedCell = (CustomCell *)[[sender superview] superview];

   clickedCell.btnPlay.hidden = YES;

   clickedCell.playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:clickedCell.playerUrl]];

   clickedCell.player = [AVPlayer playerWithPlayerItem:clickedCell.playerItem];
   clickedCell.playerLayer = [AVPlayerLayer playerLayerWithPlayer:clickedCell.player];

   [[NSNotificationCenter defaultCenter]
    addObserverForName:AVPlayerItemPlaybackStalledNotification
    object:clickedCell.playerItem
    queue:[NSOperationQueue mainQueue]
    usingBlock:^(NSNotification *note) {

        NSLog(@"%@ -> %ld", @"AVPlayerItemPlaybackStalledNotification", (long)[clickedCell.playerItem status]);

 }];

   [clickedCell.playerLayer setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width)];
   [clickedCell.iamgen.layer addSublayer:clickedCell.playerLayer];
   [clickedCell.playerLayer setBackgroundColor:[UIColor clearColor].CGColor];

   [clickedCell.iamgen.layer addSublayer:clickedCell.playerLayer];

   [clickedCell.player play];

}
之所以出现clickedCell.iamgen,是因为我有一个UIIMageView,可以在其中显示视频的预览图像

我总是收到暂停通知的原因是什么?互联网连接??实现此场景的最佳方法是什么

对不起我的英语

编辑:
我敢肯定是因为缓冲区加载速度不够快。我认为这是因为如果我在AVPlayerTemplayBackstalledNotification之后反复点击播放按钮,就像视频逐帧前进一样。我想这样做是为了知道缓冲区何时已满,以便我可以继续播放。

播放本地文件时是否会发生同样的情况?您使用的资产是HLS吗?我没有在本地尝试。关于第二个问题,我不知道,我对这方面相当陌生。我从我的服务器中的url获取视频(例如),视频的数据速率可能高于连接和传输所允许的速率。使用HLS肯定是一种改进,可以防止应用商店拒绝。你有关于如何在我的服务器上实现HLS的指南吗?如果任何HTTP服务器正常工作,我已经安装了nginx。这主要是内容如何编码和格式化的问题。查看Apple开发者门户上的HTTP实时流媒体文档。