【问题标题】:Multiple video playing issue in UITableViewCellUITableViewCell 中的多个视频播放问题
【发布时间】: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


【解决方案1】:

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

您不能使用MPMoviePlayerControllerdocumentation 清楚地说明了这一点..

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

希望对你有帮助。

【讨论】:

  • 在源代码中它使用不同的控制器来播放电影而不是一个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多