I want to play videos on Tableview
using MPMoviePlayer
. So I have 10 videos and I need to load the videos on tableview. So while scrolling on tableview, don't want to play videos. Once tableview scrolling completed, current visible cell index video needs to be auto played inside the cell. How can I implement this?
See below for the code on every 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]];
You need to add validation in your cellForRowAtIndexPath method for checking tableview rows motion. Use following code for checking if scrolling is stopped.
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
{
// Here comes your code for playing/resuming video
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With