0

I have a tableview and each cell has a webview.On each webview i load a different embed video from youtube.

CardCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CardCell"];
NSString *fullURL = [NSString stringWithFormat: @"https://youtube.com/embed/%@?",videoID];
NSURL *url = [NSURL URLWithString:fullURL];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[cell.videoView loadRequest:requestObj];
cell.videoView.scrollView.scrollEnabled = NO;

My problem is that every time i scroll the table, because of reusing the cells, on webview it shows the previous video and after a sec it shows the correct one.

I tried to use this: https://github.com/youtube/youtube-ios-player-helper but it creates every time a different web view and that makes the scrolling REALLY slow and not smooth at all.

Any solutions? `

Katerina
  • 187
  • 3
  • 16

1 Answers1

0

You surely can use the youtube ios player library.

  1. Create a custom cell and add in the cell a UIView.
  2. Change the UIView class to be a YTPlayerView subclass
  3. Create an outlet for the YTPlayerView to your custom cell subclass
  4. In the prepareForReuse, clear the previous video:

    - (void)prepareForReuse {
        [super prepareForReuse];
    
        _youTubePlayer.hidden = YES;
        [_youTubePlayer stopVideo];
        [_youTubePlayer clearVideo];
        }
    

In the above snippet the _youTubePlayer is the outLet to the YTPlayerView

You can also set a delegate for the YTPlayerViewDelegate and depending on the video status, update your cell..

Lefteris
  • 14,550
  • 2
  • 56
  • 95
  • this is what happening when i use YTPlayerView https://cloud.githubusercontent.com/assets/8028679/10536869/ede4b95e-73f6-11e5-9e4a-8d70fe4c27b1.png https://cloud.githubusercontent.com/assets/8028679/10537232/0eaf84fa-73f9-11e5-9a59-2482f504d6fe.png – Katerina Oct 16 '15 at 15:44
  • What exactly is happening ? – Lefteris Oct 16 '15 at 15:50