How do I play video (autoplay) in UITableViewCell in iOS

I am playing a video in UITableViewCell. For that I am using the following code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *VideoCellIdentifier = @"VideoCell";

    NSDictionary *_response_data = [self.response objectAtIndex:indexPath.row];

    VideoCustomCell *cell = (VideoCustomCell *) [tableView dequeueReusableCellWithIdentifier:VideoCellIdentifier];

    if (cell == nil) {
        NSArray *topLevelObjects;
        topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"VideoCustomCell" owner:self options:nil];
        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (VideoCustomCell *) currentObject;
                cell.delegate  = self;

    avPlayer = [[AVPlayer playerWithURL:[NSURL URLWithString:[_response_data valueForKey:@"media_id"]]] retain];
    avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
    avPlayerLayer.frame = cell.video_player_view.layer.bounds;
    avPlayerLayer.videoGravity = AVLayerVideoGravityResize;
    [cell.video_player_view.layer addSublayer: avPlayerLayer];
    [avPlayer play];

    return cell;

The video is playing properly, but I want to play only one video at a time. Play the video of the cell which is fully visible.

  • iOS 4.2 - Printing DOC, PPT, XLS, etc. with Apple AirPrint?
  • Warning: Attempt to present View Controller on * which is already presenting <UISearchController: 0x142a1f7c0>
  • 'FBSDKLoginKit/FBSDKLoginKit.h' file not found (Facebook SDK for iOS v4.2 & Xcode 7)
  • Why doesn't Remove Observer from NSNotificationCenter:addObserverForName:usingBlock get called
  • Parse API 1.6.4 - cannot build project
  • JSON structure with Swift and Alamofire
  • 2 Solutions Collect From Internet About “How do I play video (autoplay) in UITableViewCell in iOS”

    Use this two method of scrolling and handle play video. This two method will call in either way when tableview stop scrolling

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
        if(![scrollView isDecelerating] && ![scrollView isDragging]){
            [self playVideo];
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
            [self playVideo];
        for(UITableViewCell *cell in [tblView visibleCells])
            VideoCell *ccell = (VideoCell*)cell;
            CGRect ccellRect = [APP_DEL.window convertRect:ccell.bounds fromView:ccell];
            // NSLog(@"--Cell frame %f",ccellRect.origin.y);
            //Set Condition of cell visible within some range
                // Handle Video Play
                int row = [[tblView indexPathForCell:ccell] row];
                NSString *strUrl = [[aryTableData objectAtIndex:row] valueForKey:@"video_url"] ;
                [ccell startVideoFromURL:strUrl]; //You can handle video play in cell or table view

    You should write your code of playing in didselect method so as you select row it will only play not other.

    (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        // your player code