Automatically play videos in a Tableview cell in iOS

I want to play video on Tableview using MPMoviePlayer . So, I have 10 videos, and I need to upload the video to tableview. Therefore, scrolling through the table, do not want to play the video. When the scrolling of the table is completed, the current visible video of the cellular index should be automatically played inside the cell. How to implement this?

Below is the code for each cell,

 [self.players.view removeFromSuperview]; NSURL *videoURL = [NSURL URLWithString:str_videourl]; self.players = [[MPMoviePlayerController alloc]init]; [self.players.view setFrame:videoView.frame]; self.players.controlStyle = MPMovieControlStyleEmbedded; self.players.shouldAutoplay = YES; self.players.movieSourceType = MPMovieSourceTypeStreaming; [self.players setContentURL:videoURL]; self.players.scalingMode = MPMovieScalingModeAspectFill; self.players.view.tag=indexPath.section; [cell.viewBase addSubview:self.players.view]; [self.players prepareToPlay]; [self.players.view setBackgroundColor:[UIColor clearColor]]; 
+5
source share
1 answer

You need to add confirmation to your cellForRowAtIndexPath method to check the movement of the table rows. Use the following code to verify that the scroll stops.

 if (self.tableView.dragging == NO && self.tableView.decelerating == NO) { // Here comes your code for playing/resuming video } 
+1
source

All Articles