iphone - UITableViewCell 中的多个视频播放问题

标签 iphone ios uitableview mpmovieplayercontroller

在我的应用程序中,我尝试在 UITableViewCell 中播放多个视频,为此我正在使用 MPMoviePlayerController,它可以毫无问题地播放视频。但它一次播放一个视频,在其他单元格中我得到黑屏假设第一次看到一个单元格它播放视频但是当我滚动到第二行时,第一个单元格视频 View 消失并出现黑屏。即使滚动表格 View ,我也不知道如何使所有视频 View 可见。这是我用于在自定义单元格中播放视频的代码:

自定义单元格初始化:

- (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;
}

任何帮助将不胜感激。

最佳答案

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

您不能使用 MPMoviePlayerControllerdocumentation明确指出..

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.

希望对你有帮助。

关于iphone - UITableViewCell 中的多个视频播放问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16411677/

相关文章:

iphone - 为什么 MPMovieLoadState 的状态为 5?

ios - 将 View Controller 添加到容器 View 覆盖 View

ios - Swift 的 openURL 方法不会调用带有星号的电话 (iOS 8.4)

ios - 为什么表格 View 不显示 iphone 中的任何数据

ios - 将 UIViewController 更改为 UITableViewController

jquery - iPhone jQuery : How to implement a Split view in iPad using Jquery Mobile + phone gap in iPhone

ios - 如何使用 UIAlertViewStylePlainTextInput 在 ios 7 中使用 textfieldname.text 和 textfield.placeholder?

iphone - 如何跟踪 AVAssetWriter 的写入进度?

ios - Swift 在 TableView 中展开 Optional 值时意外发现 nil

ios - 如何以编程方式隐藏我的 UITableViews 部分的标题?