5

在我的应用程序中,我正在尝试播放多个视频,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;
}

任何帮助将不胜感激。

4

1 回答 1

10

您可以AVFoundation framework用于同时播放多个视频。有关如何执行此操作的分步和完整源代码:multiple-video-playback-on-ios

你不能使用MPMoviePlayerController. 文件清楚地指出..

尽管您可以创建多个 MPMoviePlayerController 对象并在您的界面中显示它们的视图,但一次只有一个电影播放器​​可以播放其电影。

希望它可以帮助你。

于 2013-05-07T05:58:11.517 回答