I use AVPlayer in the view.table view the delays when setting AVPlayerItem . The following is the code for the cellForRowAtIndexPath method.
- (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; }
The problem is here
if (!cell.avPlayer) { cell.avPlayer = [AVPlayer playerWithPlayerItem:cell.playerItem]; }else{ [cell.avPlayer replaceCurrentItemWithPlayerItem:cell.playerItem]; }
If I comment above, looking at the code table works correctly, keeping up, but I need to replace AVPlayerItem .
source share