【发布时间】:2013-05-07 05:16:57
【问题描述】:
在我的应用程序中,我尝试在UITableViewCell 中播放多个视频,为此我使用的是MPMoviePlayerController,它可以毫无问题地播放视频。但它一次播放一个视频,在其他单元格中我得到黑屏假设第一次看到一个单元格它播放视频,但是一旦我滚动到第二行,第一个单元格视频视图就会消失并出现黑屏。即使滚动表格视图,我也不知道如何使所有视频视图可见。这是我用于在自定义单元格中播放视频的代码:
自定义单元初始化:
- (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 方法
- (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;
}
任何帮助将不胜感激。
【问题讨论】:
-
嘿@vinod - 你最终找到了一个优雅的解决方案吗?我也在为此苦苦挣扎(我需要控件,所以原始的 AVFoundation 不好)
标签: iphone ios uitableview mpmovieplayercontroller