设置AVPlayerItem时UITableView滞后

Pra*_*ias 5 objective-c uitableview ios avplayer avplayeritem

AVPlayer在表view.table视图中使用时设置滞后AVPlayerItem。下面是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;
}
Run Code Online (Sandbox Code Playgroud)

问题在这里

   if (!cell.avPlayer) {
        cell.avPlayer = [AVPlayer playerWithPlayerItem:cell.playerItem];
    }else{
        [cell.avPlayer replaceCurrentItemWithPlayerItem:cell.playerItem];
    }
Run Code Online (Sandbox Code Playgroud)

如果我在上面的代码表中评论,则可以正常工作而不会滞后,但是我需要替换AVPlayerItem