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?
You can handle the pause function through local notifications also like this:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.