我在设置 AVPlayerItem 时在表 view.table 视图中使用 AVPlayer . 下面是 cellForRowAtIndexPath 方法代码 .

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *tableIdentifier = @"tableIdentifier";
     CustomTableCell *cell = [self.videoTableView dequeueReusableCellWithIdentifier:tableIdentifier];
     if (cell == nil) {
         cell = [[[NSBundle mainBundle]loadNibNamed:@"VideoCell" owner:self                   options:nil]objectAtIndex:0];
    }
     dispatch_queue_t queue =  dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
     dispatch_async(queue, ^{
         AVAsset *avAssert = [AVAsset assetWithURL:[NSURL URLWithString:@"url"]];
         cell.playerItem =[[AVPlayerItem alloc]initWithAsset:avAssert];
         dispatch_sync(dispatch_get_main_queue(), ^{
             if (!cell.avPlayer) {
                 cell.avPlayer = [AVPlayer playerWithPlayerItem:cell.playerItem];
            }else{
                [cell.avPlayer replaceCurrentItemWithPlayerItem:cell.playerItem];
    }
    if (!cell.avPlayerLayer) {
        cell.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:cell.avPlayer];
        cell.avPlayerLayer.frame = cell.videoPlayerView.layer.bounds;
        cell.avPlayerLayer.videoGravity = AVLayerVideoGravityResize;
        [cell.videoPlayerView.layer addSublayer: cell.avPlayerLayer];
        if (indexPath.row == 0) {
            cell.avPlayer.muted = NO;
            [cell.avPlayer play];
        }
    }
        });
    });
return cell;
}

问题在这里,

if (!cell.avPlayer) {
        cell.avPlayer = [AVPlayer playerWithPlayerItem:cell.playerItem];
    }else{
        [cell.avPlayer replaceCurrentItemWithPlayerItem:cell.playerItem];
    }

如果我评论上面的代码表视图正常工作没有滞后但我需要替换 AVPlayerItem .