gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 04:22:37 26 4
gpt4 key购买 nike

在我的应用程序中,我尝试在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com