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

前端 未结 2 1515
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-28 11:51

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellFor         


        
2条回答
  •  被撕碎了的回忆
    2020-12-28 12:14

    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{
        if(!decelerate){
    
            [self playVideo];
        }
    }
    
    
    -(void)playVideo
    {
        if(aryTableData.count==0){
            return;
        }
    
        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
            if(ccellRect.origin.y>-200)
            {
                // 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
            }
        }
    }
    

提交回复
热议问题