2017-04-20 7 views
2

大きな問題が残っています。 私はvideoplayerを持っている1つのtableviewを持っています - AVPlayer 私は10のセルとそれぞれのビデオを再生しています。問題は、私が スクロールテーブルビューをプレイヤーが再初期化してビデオ再生を から開始するときです。私はこの再初期化を防止し、twitterのようなビデオを再生したいです。最後に残すように再生するコードは試してください。私は、複数のコードを試してみましたが、セルのavplayer - テーブルビューの再初期化を防ぐ方法

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

uは、テーブルビューのデータソースでAVPlayerのシーク時間を維持する必要があります –

+0

そのコードはどこですか? 'tableView:cellForRowAtIndexPath:'?あなたのコードは面倒です、あなたの質問をフォーマットしてください。また、デキューを使用して、セルの再利用を使用してください。再利用のために、そこにサブビューを追加することも避けてください。 – Larme

+0

Anbu.Karthik今すぐ見ることができません。seektimeが必要です。avplayerの再初期化を防ぐ方法が必要です – Anita

答えて

0

UItableviewを使用している場合は、明らかな動作です。 UItableviewは、すべてのセルをメモリに保持しません。セルが画面から消えると、tableviewでそのセルが削除され、下/上にスクロールすると(新しいセルが画面に表示されたとき)、再び追加されます。 このUItableviewの動作を変更することはできません。

醜い解決策があります:テーブルビューのサイズをheight = HeightOfCell * numberOfCell.に変更するのはどちらですか?これはメモリの問題を引き起こす可能性があるためです。

シーク時間を把握することをお勧めします。 didEndDisplayingCellを使用して、Playerの現在のシーク時間の値を削除するセルに格納することができます。そのインデックスパスのセルが再び表示されると(cellforrow)、プレーヤーに保存された値を求めることができます。

関連する問題