当前位置: 首页 > 工具软件 > ZFPlayer > 使用案例 >

iOS视频 ZFPlayer使用

钦英发
2023-12-01

ZFPlayer地址

列表页

点击视频播放按钮
[self.playerView resetToPlayNewVideo:self.playerModel];

初始化
_playerView = [ZFPlayerView sharedPlayerView];
_playerView.delegate = self;
// 当cell播放视频由全屏变为小屏时候,不回到中间位置
_playerView.cellPlayerOnCenter = NO;
// 当cell划出屏幕的时候停止播放
_playerView.stopPlayWhileCellNotVisable = YES;

初始化播放数据
_playerModel = [[ZFPlayerModel alloc] init];
_playerModel.title = model.title;
model.video_url = [model.video_url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
_playerModel.videoURL = [NSURL URLWithString:model.video_url];
_playerModel.placeholderImageURLString = model.image_list;
_playerModel.scrollView = self.pullTableView;
_playerModel.indexPath = selectedIndexPath;
_playerModel.seekTime = model.seek_time;
_playerModel.resolutionDic = dic;
_playerModel.fatherViewTag = cell.coverContainer.tag;

点击停止播放
代理方法
- (void)zf_playerStopAction:(ZFPlayerModel *)playerModel;
{
RecommendListModel *model = [self.dataArray objectAtIndex:selectedIndexPath.row];
model.seek_time = playerModel.seekTime;
}

进入详情页继续播放
CNVideoViewController *contentVC = [[CNVideoViewController alloc]init];
if (selectedIndexPath&&selectedIndexPath.row==indexPath.row) {
contentVC.playerView = self.playerView;
contentVC.resetPlayer = NO;
contentVC.seekTime = self.playerModel.seekTime;
}
contentVC.modelId = model.tid;
contentVC.categoryId = _categoryId;
contentVC.recommendModel = model;
contentVC.hidesBottomBarWhenPushed = YES;
[self.ownerViewController.navigationController pushViewController:contentVC animated:YES];

详情页

@property (strong, nonatomic) RecommendListModel *recommendModel;
从xx秒开始播放视频(默认0)
@property (nonatomic, assign) NSInteger seekTime;
是否重置播放器
@property (nonatomic, assign) BOOL resetPlayer;

- (void)playAction:(UIButton*)sender
{
NSString *video_url;
if (_recommendModel.video_url) {
video_url = _recommendModel.video_url;
}else if (_articleModel.video_url) {
video_url = _articleModel.video_url;
}else{
return;
}
ZFPlayerModel *_playerModel = [[ZFPlayerModel alloc] init];
_playerModel.title = _recommendModel.title;
_playerModel.scrollView = nil;
video_url = [video_url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
_playerModel.videoURL = [NSURL URLWithString:video_url];
_playerModel.placeholderImageURLString = _recommendModel.image_list;
_playerModel.fatherView = self.playerFatherView;
_playerModel.seekTime = _recommendModel.seek_time;
if (self.resetPlayer) {
//在当前页面,设置新的视频时候调用此方法
[self.playerView resetToPlayNewVideo:_playerModel];
}else{
//指定播放的控制层和模型
//控制层传nil,默认使用ZFPlayerControlView(如自定义可传自定义的控制层)
[self.playerView playerControlView:nil playerModel:_playerModel];
//自动播放,默认不自动播放
[self.playerView autoPlayTheVideo:_playerModel];
}
}

暂停播放

- (void)zf_playerStopAction:(ZFPlayerModel *)playerModel
{
_recommendModel.seek_time = playerModel.seekTime;
}

 类似资料: