0

I have a UITableview with an AVPlayer instance in every cell. My requirement is to stream video only in the visible cells hence I don't want any player instances in the invisible cells. Play method is called in cellForRowAtIndexPath. Here is my code to remove AVPlayer

- (void)tableView:(UITableView *)tableView didEndDisplayingCell: (UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
 {
    if (![ _feedsTableView.indexPathsForVisibleRows containsObject:indexPath]) {
        NSLog(@"index of visible cell  %ld",(long)indexPath.row);
        LTHomeFeedCell * cell = (LTHomeFeedCell*)[_feedsTableView cellForRowAtIndexPath:indexPath ];
        [ cell.avMoviePlayer pause ];
        cell.avMoviePlayer = [ AVPlayer playerWithURL:[NSURL URLWithString:@""] ];
        cell.avMoviePlayer = nil;
  }

But, still I hear audio from invisible cells. I'm using this same code to pause the video when I move to a different screen but I still hear the audio. How do I fix this?

Sandy Chapman
  • 11,133
  • 3
  • 58
  • 67
KiranGit
  • 61
  • 1
  • 6

1 Answers1

0

You can handle the pause function through local notifications also like this:

  • Add an observer for a local notification in the cell when you start playing the video.
  • And in the selector of that notification, write the code to pause you player and remove the notification
  • After that in didEndDisplayingCell, post that notification to pause that video.
Vikas Dadheech
  • 1,672
  • 12
  • 23
  • 1
    My issue the even after pausing and making the player instance nil i still hear audio and video stream continuous. – KiranGit Aug 05 '15 at 13:08