我正在尝试在单元格本身中播放视频,而不是全屏视频显示。我在用MPMoviePlayerController
以此目的。
我已经定义了
MPMoviePlayerController *moviePlayer;
在实施部分
Then in cellForRowAtIndexPath:
我这样做
cell = [tableView dequeueReusableCellWithIdentifier:simpleTableVideoIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableVideoIdentifier];
}
NSDictionary *dictionary = [dataArray objectAtIndex:indexPath.section];
NSDictionary *data = dictionary;
if ([data[@"type_of_post"] isEqualToString:@"video"]) {
NSString *path = data[@"video"];
NSURL *videoURL = [NSURL URLWithString:path];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[moviePlayer.view setFrame:CGRectMake(10.0, 0.0, 300.0 , 400.0)];
[cell addSubview:moviePlayer.view];
moviePlayer.view.hidden = NO;
[moviePlayer prepareToPlay];
[moviePlayer play];
}else{
//do something else
}
显然我给它指定了一个高度heightForRowAtIndexPath:
但重点是MPMoviePlayerController *moviePlayer;
是全局定义的,它不仅仅粘在其单元格上,而且当我向下滚动时不断向下。除了我所描述的之外,我不确定还有什么其他方法可以实现这一点,这显然不是正确的方法。如果有人能引导我走向正确的方向,我将非常感激。
Thanks
切勿向单元格添加子视图:
[cell addSubview:moviePlayer.view];
仅将其添加到 contentView:
[cell.contentView addSubview:moviePlayer.view];
您犯的另一个大错误是您忘记了该单元格可以重复使用;当用户滚动时,该单元格将用于表格的不同行。因此它被重用,现在电影播放器视图仍然在其中,即使现在这是表的错误行。你不仅需要add电影播放器视图到右侧的单元格,您需要remove它来自所有错误的细胞(在else
您的代码的一部分)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)