我在桌面视图上播放视频,但不希望视频广告重复播放,因为它会重新制作视频。
我尝试将单元格缓存在数组中并从数组中加载(如果存在)但是当查看弹出到上一个视图时会出现问题。
即使视频被删除,视频也会继续播放。
AVTableViewCell *cachedCell = [self.cellList objectForKey:indexPath];
if (cachedCell) {
return cachedCell;
} else {
AVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AVTableViewCell" forIndexPath:indexPath];
[cell configCell:indexPath];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (section == 1) {
[self.cellList setObject:(AVTableViewCell *)cell forKey:indexPath];
}
}
下面的代码我在弹出视频控制器之前移除视频,但视频或音频仍在播放。
- (IBAction)btnBackTapped:(id)sender {
// To Avoid the re-using video cell, implemented cache so make sure it got removed before going back to the previous screen.
AVTableViewCell *cachedCell = [self.cellList objectForKey:[NSIndexPath indexPathForRow:0 inSection:1]];
if (cachedCell)
{
if (cachedCell.isJWVideo) {
[cachedCell.player stop];
[cachedCell.player.view removeFromSuperview];
cachedCell.player = nil;
} else {
[cachedCell.ytPlayerView stopVideo];
[cachedCell.ytPlayerView clearVideo];
cachedCell.ytPlayerView = nil;
}
[self.cellList removeAllObjects];
self.cellList = nil;
}
[self.navigationController popViewControllerAnimated:YES];
}
还有其他技术可以在桌面视图单元格上播放视频而无需重复使用吗?因为当我向上和向下滚动时,它会阻止滚动视图再次加载视频。
答案 0 :(得分:0)
我建议不要缓存表格单元格 - 你可能会遇到各种各样的问题。
在AVTableViewCell
中,您应该覆盖prepareForReuse
方法并在那里设置self.ytPlayerView = nil
。
这样,刚刚重新使用的表格单元格会被移交给您的tableview代码空白,因此他们无法尝试重新加载旧的视频播放器视图。