2017-04-20 73 views
2

我陷入了一个大问题。 我有一个tableview有videoplayer - AVPlayer 我有10个单元格,每个播放视频。但问题是,当我滚动tableview播放器获得重新初始化和视频播放从 开始。我想要阻止这个重新初始化和播放视频像我们离开作为最后的代码应该试图玩的视频 ?我曾尝试多个代码,但没有获得成功如何防止avplayer的单元格 - 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"]; 

    } 

玩家指数变化和视频得到改变其指数 如何得到这个问题的拼车?

+0

你需要维护AVPlayer在tableview的数据源上的查找时间 –

+0

从那里的代码? '的tableView:的cellForRowAtIndexPath:'?你需要你的代码很混乱,请格式化你的问题。另外,请使用出列,并使用单元格的重用。避免在那里添加子视图,因为重用。 – Larme

+0

Anbu.Karthik现在我不想seektime我只想要一种方法来防止重新avialyer – Anita

回答

0

如果您使用的是UItableView,它的行为显而易见。 UItableview不保留所有单元格的内存。当单元格从屏幕上消失时,tableview将它删除并在向上/向下滚动时(当新单元格出现在屏幕上时)再次添加它。 你不能改变这个UItableview的行为。

有丑陋的解决方案可用:哪个是调整您的tableview到height = HeightOfCell * numberOfCell.但是这不被建议。因为这可能会造成记忆问题。

更好的解决方案是跟踪寻道时间。您可以使用didEndDisplayingCell来存储玩家当前查找时间的值,该值将被删除。并且当该索引路径的单元格再次出现时(cellforrow),您可以向玩家寻找储值。