即时通讯尝试使用AVPlayer在UITableViewCell中播放来自网址的视频(不完全像Instagram,但足够接近)

我正在尝试一次播放一个视频 . 当我点击单元格中的“播放”按钮时,视频开始播放但仅持续1或2秒,然后我得到一个AVPlayerItemPlaybackStalledNotification .

我在CustomTableViewCell.h中声明了

@property AVPlayer *player;
  @property AVPlayerItem *playerItem;
  @property AVPlayerLayer *playerLayer;
  @property AVAsset *playerAsset;
  @property NSString *playerUrl;

然后我在我的ViewController.m中有一个IBAction

- (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,我在其中呈现视频的预览图像 .

我总是得到停滞通知的原因是什么?互联网连接?哪个是实现此方案的最佳方法?

对不起我的英语不好!

编辑:我很确定是因为缓冲区加载速度不够快 . 我认为这是因为如果我在AVPlayerItemPlaybackStalledNotification之后重复点击播放按钮就像视频一帧一帧前进 . 我认为这个想法是知道什么时候缓冲区足够长,我可以继续播放 .