Vin*_*ngh 5 iphone mpmovieplayercontroller uitableview ios
在我的应用程序中,我正在尝试播放多个视频,UITableViewCell因为我使用MPMoviePlayerController它播放视频没有任何问题.但是它一次播放一个视频而在其他单元格中我得到黑屏,假设第一次有一个单元格可见它播放视频但是当我滚动第二行时,第一个单元格视频视图会随着黑屏消失.即使我滚动表视图,我也无法看到如何使所有视频视图可见.这是我在自定义单元格中播放视频时使用的代码:
Custom Cell初始化:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将受到高度赞赏.
Nis*_*agi 10
您可以使用AVFoundation framework同时播放多个视频.关于如何执行此操作的一步一步和完整源代码:ios上的多视频回放
你不能使用MPMoviePlayerController.该文件规定,明确..
虽然您可以创建多个MPMoviePlayerController对象并在界面中显示其视图,但一次只能有一个电影播放器可以播放其电影.
希望它能帮助你.
| 归档时间: |
|
| 查看次数: |
3327 次 |
| 最近记录: |