1
我在桌面视图中使用AVPlayer。我想要开始视频播放,在滚动表格视图时停止播放视频。告诉我有什么可行的方法来做到这一点?AVPlayer恢复能力
- (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;
}
您必须保留一系列视频持续时间,以便在该视频暂停视频时再次滚动至相同视频,首先检查开始播放视频持续时间在阵列 –
目前,我正在做你说的。问题是我重复使用细胞。 somtimes它不需要正确的AVPlayerItem当前time.i'll试着让你知道,谢谢。 – PramukaD
粘贴一些代码 –