【发布时间】:2017-04-20 11:55:38
【问题描述】:
我陷入了一个大问题。 我有一个带有视频播放器的 tableview - AVPlayer 我有 10 个单元格,每个单元格都在播放视频。但问题是当我 scroll tableview 播放器重新初始化并从中播放视频 开始。我想阻止这种重新初始化并播放像推特这样的视频 我们离开的最后一场比赛应该尝试什么代码?我尝试了多个代码但没有成功
Code is here
if (Arr_avPlayer.count > indexPath.row){
Cell_TVC * cell = (Cell_TVC *)[Arr_avPlayer
objectAtIndex:indexPath.row];
return cell;
}
// Cell_TVC *cell = (Cell_TVC *)[tableView
dequeueReusableCellWithIdentifier:@"Cell_TVC"
forIndexPath:indexPath];
**Cell_TVC *cell = [[Cell_TVC alloc] init];**
// Cell_TVC *cell = [tableView
dequeueReusableCellWithIdentifier:@"Cell_TVC"];
// if (!cell) {
// cell = [[Cell_TVC
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"Cell_TVC"];
//
// }
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL
fileURLWithPath:[self filepath:[myIntegers
objectAtIndex:indexPath.row]]] options:nil];
cell.avPlayerItem = [[AVPlayerItem alloc] initWithAsset:asset];
cell.avPlayer = [[AVPlayer alloc]
initWithPlayerItem:cell.avPlayerItem];
cell.avPlayerLayer = [[AVPlayerLayer alloc] init];
cell.avPlayerLayer = [AVPlayerLayer
playerLayerWithPlayer:cell.avPlayer];
cell.lblTime.text = @"0.0";
CGRect contentViewFrame = cell.contentView.frame;
contentViewFrame.origin.x = 0;
contentViewFrame.origin.y = 25;
contentViewFrame.size.width = APP_width;
contentViewFrame.size.height = APP_width * 0.55;
cell.contentView.frame = contentViewFrame;
cell.contentView.backgroundColor = [UIColor redColor];
UILabel *lbl = [[UILabel
alloc]initWithFrame:CGRectMake((cell.contentView.frame.size.width / 2
) - 100, contentViewFrame.size.height + 10, 200, 100)];
//lbl.text = [NSString stringWithFormat:@"%02f:%02f", dMinutes11,
dSeconds11];
lbl.tag = indexPath.row;
[cell.avPlayerLayer setFrame:cell.contentView.frame];
[cell.contentView.layer addSublayer:cell.avPlayerLayer];
[Arr_avPlayer insertObject:cell atIndex:indexPath.row];
[cell.contentView addSubview:lbl];
if i write the cell like below
Cell_TVC *cell = [[Cell_TVC alloc] init];
i am not able to acess the property of cell and when i use like
below
if (!cell)
{
cell = [[Cell_TVC
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"Cell_TVC"];
}
播放器索引更改和视频获取更改其索引 如何解决这个问题?
【问题讨论】:
-
你需要在tableview的数据源上维护AVPlayer的seek time
-
代码从哪里来?
tableView:cellForRowAtIndexPath:?你需要你的代码很乱,请格式化你的问题。另外,请使用出队,并使用单元格的重用。避免在那里添加子视图,因为重复使用。 -
Anbu.Karthik 现在我不想要搜索时间我只是想要一种方法来防止重新初始化 avplayer
-
Larme : 这段代码写在 cellForRowAtIndexPath
标签: ios uitableview