In my app I am trying to play multiple videos in UITableViewCell
for this I am using MPMoviePlayerController
it plays the video without any issue. but it play one video at a time and in other cell I get black screen suppose at first time one cell is visible it play the video but as soon as I scroll for second row the first cell video view disappear with black screen. I am not getting how to make all video view visible even if I scroll the table view. this is the code I am using for play video in custom cell :
Custom Cell initialization :
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self){
NSArray *nibArray=[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
self=[nibArray objectAtIndex:0];
_player = [[MPMoviePlayerController alloc] init];
_player.view.frame = CGRectMake(0,0,320,300);
_player.movieSourceType = MPMovieSourceTypeStreaming;
[_player setContentURL:[NSURL URLWithString:@"http://files.parse.com/ef5649ee-75c6-4c76-ba3b-37be4d281125/b35589f7-c0aa-4ca8-9f7c-fd31b2dc8492-vedioTeaser.mov"]];
[_player prepareToPlay];
[_player play];
[self addSubview:_player.view];
}
return self;
}
CellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}else{
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section], nil] withRowAnimation:UITableViewRowAnimationAutomatic];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
Any help would be highly appreciated.
You can use AVFoundation framework
for playing multiple videos simultaneously .
A step by step and full source code on how to do this: multiple-video-playback-on-ios
You can't use MPMoviePlayerController
. The documentation states that clearly..
Although you can create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time can play its movie.
hope it helps you.
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