-
Notifications
You must be signed in to change notification settings - Fork 224
ListPlay
fengxing edited this page Sep 27, 2018
·
3 revisions
在列表中播放视频,如果没有多个视频同时播放的需求,为每一个视频创建一个SuperPlayerView并不高效。建议使用一个播放器,在切换的时候修改fatherView
来达到切换视频效果。
- 在controller中创建一个播放器实例
self.superPlayer = [[SuperPlayerView alloc] initWithFrame:CGRectZero];
创建后不使用,到播放时再设置父view。
- 当在某个cell上播放时,设置faterView到改cell上,调用playWithModel即可播放
- (void)cellStartPlay:(TXWeiboListTableViewCell *)cell
{
TXWeiboListTableViewCell *tempCell = nil;
tempCell = [self.tableView cellForRowAtIndexPath:self.tempIndexPath];
tempCell.playButton.hidden = NO;
self.tempIndexPath = [self.tableView indexPathForCell:cell];
tempCell = (TXWeiboListTableViewCell *)cell;
self.superPlayer.fatherView = cell.contentView;
SuperPlayerModel *model = [SuperPlayerModel new];
model.appId = 1252463788;
model.fileId = self.fileIdArray[[self.tempIndexPath row]];
[self.superPlayer playWithModel:model];
tempCell.playButton.hidden = YES;
}
- 当cell不可见时,调用resetPlayer停止播放
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.superPlayer.fatherView == cell.contentView) {
self.superPlayer.fatherView = nil;
}
}
- 退出时,销毁SuperPlayer
- (void)didMoveToParentViewController:(nullable UIViewController *)parent
{
if (parent == nil) {
[self.superPlayer resetPlayer];
}
}