2019独角兽企业重金招聘Python工程师标准>>>

还是直接上代码,详情如下:

一.ZFPlayer的导入。pod 'ZFPlayer',头文件 #import "ZFPlayer.h"

二.在cell中使用图片看得更清晰,代码可以直接复制

图片:  .h文件

.m文件

代码:

//
//  CellShowController.h
//  TestZFPlayer
//
//  Created by 黄亚男 on 2018/2/23.
//  Copyright © 2018年 黄亚男. All rights reserved.
//#import <UIKit/UIKit.h>#import "ZFPlayer.h"
@interface CellShowController : UIViewController+ (instancetype)sharedInstance ;@property (nonatomic, strong) ZFPlayerView *playerView;@end
//
//  CellShowController.m
//  TestZFPlayer
//
//  Created by 黄亚男 on 2018/2/23.
//  Copyright © 2018年 黄亚男. All rights reserved.
//›#import "CellShowController.h"
#import "VideoCell.h"@interface CellShowController ()<UITableViewDelegate,UITableViewDataSource,ZFPlayerDelegate>@property (nonatomic, strong) UITableView *tbView;
//视频数据
@property (nonatomic,strong) NSArray *videoData;
//图片数据
@property (nonatomic,strong) NSArray *coverUrl;@property (nonatomic, strong) ZFPlayerControlView *controlView;@end@implementation CellShowController
+ (instancetype)sharedInstance {static CellShowController *_sharedVideoVC = nil;static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{_sharedVideoVC = [[CellShowController alloc] init];_sharedVideoVC.playerView = [[ZFPlayerView alloc] init];});return _sharedVideoVC;
}
//视频数据
-(NSArray *)videoData
{if(!_videoData){//网络数据,这里为假数据_videoData = [NSArray arrayWithObjects:@"1.mp4",@"2.mp4",@"3.mp4",@"4.mp4",@"5.mp4", nil];}return _videoData;
}
//图片数据
-(NSArray *)coverUrl
{if(!_coverUrl){_coverUrl = [NSArray arrayWithObjects:@"1.jpg",@"2.png",@"3.jpg",@"4.jpg",@"5.jpg", nil];}return _coverUrl;
}-(void)viewWillAppear:(BOOL)animated
{[super viewWillAppear:animated];ZFPlayerShared.isStatusBarHidden = NO;}
// 页面消失时候
- (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear:animated];[self.playerView resetPlayer];}- (UIStatusBarStyle)preferredStatusBarStyle {// 这里设置横竖屏不同颜色的statusbarif (ZFPlayerShared.isLandscape) {return UIStatusBarStyleLightContent;}return UIStatusBarStyleDefault;
}- (BOOL)prefersStatusBarHidden {//ZFPlayerShared.isStatusBarHiddenreturn ZFPlayerShared.isStatusBarHidden;
}
- (void)viewDidLoad {[super viewDidLoad];self.navigationItem.title = @"cell中播放";[self createTableView];
}-(void)createTableView
{_tbView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, KSCREEN_WIDTH, KSCREEN_HEIGHT-20) style:UITableViewStyleGrouped];_tbView.delegate = self;_tbView.dataSource = self;//隐藏cell的分割线_tbView.separatorStyle = UITableViewCellSeparatorStyleNone;_tbView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];_tbView.estimatedRowHeight = 0;_tbView.estimatedSectionHeaderHeight = 0;_tbView.estimatedSectionFooterHeight = 0;if (@available(iOS 11.0, *)) {UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;_tbView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;}[self.view addSubview:self.tbView];
}#pragma mark UITableViewDataSource---分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{return self.videoData.count;}
#pragma mark UITableViewDataSource---行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return 1;
}
#pragma mark UITableViewDataSource---行单元
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{VideoCell *cell = [VideoCell cellWithTableView:tableView];[cell.headerImage sd_setImageWithURL:[NSURL URLWithString:self.coverUrl[indexPath.section]]];__block NSIndexPath *weakIndexPath = indexPath;__block VideoCell *weakCell  = cell;__weak typeof(self)  weakSelf = self;cell.viewBlock = ^(UIView *view) {ZFPlayerModel *playerModel = [[ZFPlayerModel alloc] init];playerModel.title            = @"";//本地播放// 文件存放路径//        NSString *path                   = FILE_PATH(model.fileName);//        NSURL *videoURL                  = [NSURL fileURLWithPath:path];//网络播放playerModel.videoURL         = [NSURL URLWithString:self.videoData[indexPath.section]];playerModel.scrollView = weakSelf.tbView;playerModel.indexPath = weakIndexPath;// 赋值分辨率字典//playerModel.resolutionDic    = dic;// player的父视图tagplayerModel.fatherViewTag = weakCell.headerImage.tag;weakSelf.playerView.delegate = self;// 设置播放控制层和model[weakSelf.playerView playerControlView:nil playerModel:playerModel];// 下载功能//weakSelf.playerView.hasDownload = YES;// 自动播放[weakSelf.playerView autoPlayTheVideo];};return cell;}
#pragma mark UITableViewDelegate---点击行单元调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark UITableViewDelegate---表头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{return 10;
}
#pragma mark UITableViewDelegate---表位高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{return 0.01;
}
#pragma mark UITableViewDelegate---行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{return 250*SCREEN_WIDTH_RATIO47;
}#pragma ================视频播放==================
- (ZFPlayerView *)playerView {if (!_playerView) {_playerView = [ZFPlayerView sharedPlayerView];_playerView.delegate = self;//(可选设置)可以设置视频的填充模式_playerView.playerLayerGravity = ZFPlayerLayerGravityResizeAspect;// 当cell播放视频由全屏变为小屏时候,不回到中间位置// _playerView.cellPlayerOnCenter = NO;// 当cell划出屏幕的时候停止播放_playerView.stopPlayWhileCellNotVisable = YES;// 静音// _playerView.mute = YES;//打开预览图self.playerView.hasPreviewView = YES;}return _playerView;
}
- (ZFPlayerControlView *)controlView {if (!_controlView) {_controlView = [[ZFPlayerControlView alloc] init];_controlView.backgroundColor = [UIColor clearColor];}return _controlView;
}@end
//
//  VideoCell.h
//  TestZFPlayer
//
//  Created by 黄亚男 on 2018/2/23.
//  Copyright © 2018年 黄亚男. All rights reserved.
//#import <UIKit/UIKit.h>typedef void(^viewBlock)(UIView *view);@interface VideoCell : UITableViewCell@property(nonatomic, copy) viewBlock viewBlock;/**占位图*/
@property (nonatomic, strong) UIImageView *headerImage;
/**播放按钮*/
@property (nonatomic, strong) UIButton *playerButton;+ (instancetype)cellWithTableView:(UITableView *)tableView;
@end
//
//  VideoCell.m
//  TestZFPlayer
//
//  Created by 黄亚男 on 2018/2/23.
//  Copyright © 2018年 黄亚男. All rights reserved.
//#import "VideoCell.h"@implementation VideoCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];if (self)    {//创建UI[self createUI];}return self;}
//创建UI
-(void)createUI{CGFloat originX,originY,width,hight;//背景图片originX = 0;originY = 0;width = KSCREEN_WIDTH;hight = 250*SCREEN_WIDTH_RATIO47;UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(originX, originY, width, hight)];_headerImage = bgView;_headerImage.tag = 20030;_headerImage.userInteractionEnabled = YES;[self.contentView addSubview:bgView];//播放按钮originX = KSCREEN_WIDTH/2-25;width = 50;originY = 100*SCREEN_WIDTH_RATIO47;UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];btn.frame = CGRectMake(originX, originY, width, width);[btn setBackgroundImage:[UIImage imageNamed:@"viedo_stop_icon"] forState:UIControlStateNormal];_playerButton = btn;btn.tag = 2005;[btn addTarget:self action:@selector(playVideo:) forControlEvents:UIControlEventTouchUpInside];[_headerImage addSubview:btn];}//视频播放
-(void)playVideo:(UIButton *)sender
{if (self.viewBlock) {_viewBlock(sender);}
}
+ (instancetype)cellWithTableView:(UITableView *)tableView{static NSString *identify = @"VideoCellID";VideoCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];if (cell == nil) {cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];}    return cell;}@end

效果图:

    

三.在View中,这个比较简单

上图:

代码:

//
//  ViewShowController.m
//  TestZFPlayer
//
//  Created by 黄亚男 on 2018/2/24.
//  Copyright © 2018年 黄亚男. All rights reserved.
//#import "ViewShowController.h"@interface ViewShowController () <ZFPlayerDelegate>@property (strong, nonatomic) ZFPlayerView *playerView;
/** 播放器View的父视图*/
@property (strong, nonatomic) UIImageView *fatherView;@property (nonatomic, strong) ZFPlayerModel *playerModel;@end@implementation ViewShowController-(void)viewWillAppear:(BOOL)animated
{[super viewWillAppear:animated];ZFPlayerShared.isStatusBarHidden = NO;}
// 页面消失时候
- (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear:animated];[self.playerView resetPlayer];}- (UIStatusBarStyle)preferredStatusBarStyle {// 这里设置横竖屏不同颜色的statusbarif (ZFPlayerShared.isLandscape) {return UIStatusBarStyleLightContent;}return UIStatusBarStyleDefault;
}- (void)viewDidLoad {[super viewDidLoad];[self createUI];}-(void)createUI
{UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, KSCREEN_WIDTH, 250*SCREEN_WIDTH_RATIO47)];_fatherView = bgView;_fatherView.tag = 10090;_fatherView.userInteractionEnabled = YES;//图片网址,为假数据[_fatherView sd_setImageWithURL:[NSURL URLWithString:@"http://2.jpg"]];[self.view addSubview:bgView];//播放按钮UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];btn.frame = CGRectMake(KSCREEN_WIDTH/2-25, 100*SCREEN_WIDTH_RATIO47,50, 50);[btn setBackgroundImage:[UIImage imageNamed:@"viedo_stop_icon"] forState:UIControlStateNormal];btn.tag = 2005;[btn addTarget:self action:@selector(playViewVideo:) forControlEvents:UIControlEventTouchUpInside];[_fatherView addSubview:btn];}- (ZFPlayerModel *)playerModel {if (!_playerModel) {_playerModel                  = [[ZFPlayerModel alloc] init];_playerModel.title            = @"这里设置视频标题";_playerModel.placeholderImage = [UIImage imageNamed:@"loading_bgView1"];_playerModel.fatherView       = self.fatherView;}return _playerModel;
}
- (ZFPlayerView *)playerView {if (!_playerView) {_playerView = [[ZFPlayerView alloc] init];[_playerView playerControlView:nil playerModel:self.playerModel];// 设置代理_playerView.delegate = self;//(可选设置)可以设置视频的填充模式,内部设置默认(ZFPlayerLayerGravityResizeAspect:等比例填充,直到一个维度到达区域边界)// _playerView.playerLayerGravity = ZFPlayerLayerGravityResize;// 打开下载功能(默认没有这个功能)_playerView.hasDownload    = YES;// 打开预览图_playerView.hasPreviewView = YES;//        _playerView.forcePortrait = YES;/// 默认全屏播放//        _playerView.fullScreenPlay = YES;}return _playerView;
}
#pragma mark -点击按钮播放
-(void)playViewVideo:(UIButton *)btn
{_playerModel.videoURL         = [NSURL URLWithString:@"http://1.mp4"];//网络地址(为假链接)_playerModel.placeholderImage = [UIImage imageNamed:@"1"];[self.playerView resetToPlayNewVideo:self.playerModel];}#pragma mark - ZFPlayerDelegate//小屏时返回按钮
//- (void)zf_playerBackAction
//{
//    [self.navigationController popViewControllerAnimated:YES];
//}
//下载按钮
- (void)zf_playerDownload:(NSString *)url
{NSLog(@"0000");
}@end

效果图:

    

写的比较匆忙,不足之处,请留言

转载于:https://my.oschina.net/huangyn/blog/1625274

iOS--视频播放器之ZFPlayer相关推荐

  1. iOS视频播放器之ZFPlayer剖析

    2019独角兽企业重金招聘Python工程师标准>>> 引言 本文主要针对ZFPlayer的功能实现来剖析,以及总结一下大家遇到的问题和解决方案 首先ZFPlayer现在拥有的功能: ...

  2. 从零开始学习音视频编程技术(七) FFMPEG Qt视频播放器之SDL的使用

    从零开始学习音视频编程技术(七) FFMPEG Qt视频播放器之SDL的使用 原文地址:http://blog.yundiantech.com/?log=blog&id=10 前面介绍了使用F ...

  3. iOS 视频播放器开发

    需求设计 做一个小学生教育辅导视频播放器. 参考小猿搜题视频播放器 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-L0GsyFSt-1675164972791)(htt ...

  4. iOS: ios视频播放(MPMediaPlayerController,AVPlayer,AVPlayerViewcontroller、ffmpeg-AVPlayer)...

    介绍: 和音频播放一样,ios也提供个很多的API.如mediaPlayer.framework下的MPMediaPlayerController.AVFounditon.framework下的AVP ...

  5. 从零开始学习音视频编程技术(六) FFMPEG Qt视频播放器之显示图像

    从零开始学习音视频编程技术(六) FFMPEG Qt视频播放器之显示图像 原文地址:http://blog.yundiantech.com/?log=blog&id=9 前面讲解了如何用FFM ...

  6. iOS视频播放的基本方法

    本文总结了iOS中最常见的视频播放方法,不同的方法都各具特点,我希望能够总结它们的不同,方便在开发中选择合适的技术方案. Apple为我们提供了多种方法来实现视频播放,包括MPMoviePlayerC ...

  7. 基于libVLC的视频播放器之二:使用VLC-Qt播放RTSP流

    此篇是 使用VLC浏览器插件播放RTSP流的姊妹篇. 一.直接使用libVLC libVLC是VLC media player多媒体框架的核心引擎和接口,开发者使用它能轻松的创建大量具有VLC特性的应 ...

  8. FFmpeg开发(五)——Qt视频播放器之封装FFmpeg类(参考了暴风影音、迅雷影音)

    FFmpeg开发(五)--Qt视频播放器之封装FFmpeg类(参考了暴风影音.迅雷影音) 上一篇介绍了,使用Qt和FFmpeg写的播放器.页面大家可以点进去查看和下载. FFmpeg开发(四)--Qt ...

  9. FFmpeg开发(七)——Qt视频播放器之播放列表类(参考了暴风影音、迅雷影音)

    FFmpeg开发(七)--Qt视频播放器之播放列表类(参考了暴风影音.迅雷影音) 上一篇分享了音频类的封装. FFmpeg开发(六)--Qt视频播放器之封装音频类(参考了暴风影音.迅雷影音) 本播放器 ...

  10. FFmpeg开发(八)——Qt视频播放器之多线程的使用(参考了暴风影音、迅雷影音)

    FFmpeg开发(八)--Qt视频播放器之多线程的使用(参考了暴风影音.迅雷影音) 上篇文章介绍了: FFmpeg开发(七)--Qt视频播放器之播放列表类(参考了暴风影音.迅雷影音) 本播放器系列相关 ...

最新文章

  1. c语言程序与设计苏小红,c语言程序设计苏小红
  2. 时间序列数据的预处理
  3. MySQL — 外键关联操作
  4. 180W多路输出式单片精密开关电源电路及分析
  5. tomcat容器是如何创建servlet类实例?用到了什么原理?
  6. 勒索软件赎金该不该交?
  7. 华为手机刷linux系统,华为Harmony OS 2.0手机Beta版刷机包流出:电脑助手一键刷入/手动...
  8. linux五周第三次课(3月7日)笔记
  9. java8时间类的好处_Java8——时间类
  10. STM32固件库的安装
  11. R语言单因素、多因素方差分析ANOVA analysis of variance
  12. 火山引擎举办视频云科技原力峰会,发布面向体验的全新视频云产品矩阵
  13. UWB定位系统在冬奥会上满足哪些需求
  14. python多线程爬机票_Python 爬取携程所有机票找出最低折扣机票,让你无忧回家过年...
  15. 对话「平衡车之父」:把Solowheel带回中国
  16. 不到3000块钱,如何支撑起每月500万次访问量及80TB流量的网站?
  17. MSBI表格模型与多维模型比较
  18. 计算机使用了休眠 怎么唤醒,电脑睡眠模式怎么唤醒?
  19. 针对salaries表emp_no字段创建索引idx_emp_no,查询emp_no为10005, 使用强制索引。
  20. 2021较全 腾讯云服务器安装宝塔面板建网站全过程(图文教程)

热门文章

  1. 极速办公(word)字体如何设置为斜体
  2. 海康nvr sdk java调用,海康SDK开发NVR拍照功能
  3. 机器学习算法(八):基于BP神经网络的预测(乳腺癌分类实践)
  4. python智慧树视频爬取_python爬虫利器之requests库的用法(超全面的爬取网页案例)...
  5. vue微信扫码登录过程
  6. 如何安装固态硬盘和重装系统???
  7. 编译原理(第3版) 清华大学出版社 黄贤英等人著作 课程知识点总结
  8. 计算机组成原理之模2运算
  9. 代码对比工具,我就用这5个
  10. 代码规范化的七大原则