ZFLandScapeControlView2.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. //
  2. // ZFLandScapeControlView.m
  3. // ZFPlayer
  4. //
  5. // Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. #import "ZFLandScapeControlView2.h"
  25. #import "ZFAVPlayerManager.h"
  26. #import "UIView+ZFFrame.h"
  27. #import "ZFUtilities.h"
  28. #import "ZFPlayerStatusBar.h"
  29. #if __has_include(<ZFPlayer/ZFPlayer.h>)
  30. #import <ZFPlayer/ZFPlayerConst.h>
  31. #else
  32. #import "ZFPlayerConst.h"
  33. #endif
  34. @interface ZFLandScapeControlView2 () <ZFSliderViewDelegate,UITableViewDelegate,UITableViewDataSource>
  35. @property (nonatomic, strong) ZFPlayerStatusBar *statusBarView;
  36. /// 顶部工具栏
  37. @property (nonatomic, strong) UIView *topToolView;
  38. /// 返回按钮
  39. @property (nonatomic, strong) UIButton *backBtn;
  40. /// 标题
  41. @property (nonatomic, strong) UILabel *titleLabel;
  42. /// 底部工具栏
  43. @property (nonatomic, strong) UIView *bottomToolView;
  44. /// 播放或暂停按钮
  45. @property (nonatomic, strong) UIButton *playOrPauseBtn;
  46. @property (nonatomic, strong) UILabel *playOrPauseBtn_temp;
  47. @property (nonatomic, strong) UIButton *nextBtn;
  48. @property (nonatomic, strong) UIButton *speedBtn;
  49. @property (nonatomic, strong) UIButton *pBtn;
  50. /// 播放的当前时间
  51. @property (nonatomic, strong) UILabel *currentTimeLabel;
  52. /// 滑杆
  53. @property (nonatomic, strong) ZFSliderView *slider;
  54. /// 视频总时间
  55. @property (nonatomic, strong) UILabel *totalTimeLabel;
  56. /// 锁定屏幕按钮
  57. @property (nonatomic, strong) UIButton *lockBtn;
  58. @property (nonatomic, assign) BOOL isShow;
  59. @property (nonatomic, strong) UITableView *changeStateTableView;
  60. //0倍速、1清晰度
  61. @property (nonatomic, assign) int stateType;
  62. @property (nonatomic, strong) NSArray* speedArr;
  63. @property (nonatomic, strong) NSArray* speedValArr;
  64. @property (nonatomic, assign) NSInteger defaultSpeedIndex;
  65. @property (nonatomic, assign)NSTimeInterval currentTime;
  66. @end
  67. @implementation ZFLandScapeControlView2
  68. - (void)dealloc {
  69. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
  70. }
  71. -(void)setPArr:(NSArray *)pArr{
  72. _pArr = pArr;
  73. }
  74. -(void)setDefaultPIndex:(NSInteger)defaultPIndex{
  75. _defaultPIndex = defaultPIndex;
  76. NSArray *pa= self.pArr[defaultPIndex];
  77. [self.pBtn setTitle:pa[0] forState:UIControlStateNormal];
  78. }
  79. - (instancetype)initWithFrame:(CGRect)frame {
  80. if (self = [super initWithFrame:frame]) {
  81. self.defaultSpeedIndex = 3;
  82. self.defaultPIndex = 2;
  83. self.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
  84. self.speedArr = @[@"2X",@"1.5X",@"1.25X",@"正常",@"0.5X"];
  85. self.speedValArr = @[@"2",@"1.5",@"1.25",@"1.0",@"0.5"];
  86. [self addSubview:self.topToolView];
  87. [self.topToolView addSubview:self.statusBarView];
  88. [self.topToolView addSubview:self.backBtn];
  89. [self.topToolView addSubview:self.titleLabel];
  90. [self addSubview:self.bottomToolView];
  91. [self.bottomToolView addSubview:self.playOrPauseBtn_temp];
  92. [self.bottomToolView addSubview:self.playOrPauseBtn];
  93. [self.bottomToolView addSubview:self.currentTimeLabel];
  94. [self.bottomToolView addSubview:self.slider];
  95. [self.bottomToolView addSubview:self.totalTimeLabel];
  96. [self.bottomToolView addSubview:self.nextBtn];
  97. [self.bottomToolView addSubview:self.speedBtn];
  98. [self.bottomToolView addSubview:self.pBtn];
  99. [self addSubview:self.lockBtn];
  100. UIImageView *iv= [UIImageView new];
  101. iv.backgroundColor = rgba(0, 0, 0, 0.5);
  102. self.changeStateImageView = iv;
  103. iv.image = [UIImage imageNamed:@""];
  104. iv.userInteractionEnabled = true;
  105. [self addSubview:iv];
  106. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.top.right.equalTo(self);
  108. make.width.mas_equalTo(@(440));
  109. make.height.mas_equalTo(@(kScreenWidth));
  110. }];
  111. [iv addSubview:self.changeStateTableView];
  112. [self.changeStateTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.edges.equalTo(iv);
  114. }];
  115. iv.hidden = true;
  116. // 设置子控件的响应事件
  117. [self makeSubViewsAction];
  118. [self resetControlView];
  119. /// statusBarFrame changed
  120. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutControllerViews) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
  121. }
  122. return self;
  123. }
  124. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  125. //倍速
  126. @zf_weakify(self);
  127. if(self.stateType == 0){
  128. pcell2 *cell = [pcell2 cellWithTableView:tableView];
  129. cell.str = self.speedArr[indexPath.row];
  130. if(self.defaultSpeedIndex == indexPath.row){
  131. cell.isSel = true;
  132. }else{
  133. cell.isSel = false;
  134. }
  135. cell.tapBlock = ^(NSInteger index) {
  136. @zf_strongify(self);
  137. if(self.defaultSpeedIndex == indexPath.row){
  138. return;
  139. }
  140. self.defaultSpeedIndex = indexPath.row;
  141. [self.changeStateTableView reloadData];
  142. self.changeStateImageView.hidden = true;
  143. if(self.speedBtnClickCallback){
  144. self.speedBtnClickCallback([self.speedValArr[indexPath.row] floatValue]);
  145. }
  146. [self->_speedBtn setTitle:self.speedArr[indexPath.row] forState:UIControlStateNormal];
  147. };
  148. return cell;
  149. //清晰度
  150. }else{
  151. pcell1 *cell = [pcell1 cellWithTableView:tableView];
  152. cell.strArr = self.pArr[indexPath.row];
  153. if(self.defaultPIndex == indexPath.row){
  154. cell.isSel = true;
  155. }else{
  156. cell.isSel = false;
  157. }
  158. cell.tapBlock = ^(NSInteger index) {
  159. @zf_strongify(self);
  160. // ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager;
  161. // manager.rate = [self.speedValArr[indexPath.row] floatValue];
  162. if(self.defaultPIndex == indexPath.row){
  163. return;
  164. }
  165. self.defaultPIndex = indexPath.row;
  166. [self.changeStateTableView reloadData];
  167. if(self.pBtnClickCallback){
  168. NSString *t = self.currentTimeLabel.text;
  169. int ti = 0;
  170. NSArray *arr = [t componentsSeparatedByString:@":"];
  171. if(arr.count == 3){
  172. ti = [arr[0] intValue] *3600 + [arr[1] intValue]*60 + [arr[2] intValue];
  173. }else if(arr.count == 2){
  174. ti = [arr[0] intValue]*60 + [arr[1] intValue];
  175. }else if(arr.count == 1){
  176. ti = [arr[0] intValue];;
  177. }
  178. self.pBtnClickCallback(indexPath.row,ti);
  179. }
  180. self.changeStateImageView.hidden = true;
  181. NSArray *pa= self.pArr[indexPath.row];
  182. [self->_pBtn setTitle:pa[0] forState:UIControlStateNormal];
  183. };
  184. return cell;
  185. }
  186. }
  187. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  188. if(self.stateType == 0){
  189. return self.speedArr.count;
  190. }else{
  191. return self.pArr.count;
  192. }
  193. }
  194. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  195. if(self.stateType == 0){
  196. return 48;
  197. }else{
  198. return 66;
  199. }
  200. }
  201. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  202. // if(self.stateType == 0){
  203. // }
  204. }
  205. -(UITableView *)changeStateTableView{
  206. if(!_changeStateTableView){
  207. _changeStateTableView =[[UITableView alloc] initWithFrame:self.bounds style:UITableViewStyleGrouped];
  208. _changeStateTableView.delegate = self;
  209. _changeStateTableView.dataSource = self;
  210. _changeStateTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  211. _changeStateTableView.showsVerticalScrollIndicator = false;
  212. _changeStateTableView.showsHorizontalScrollIndicator = false;
  213. _changeStateTableView.backgroundColor = [UIColor clearColor];
  214. // _tableView.backgroundColor = [UIColor redColor];
  215. if (@available(iOS 11, *)) {
  216. _changeStateTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  217. _changeStateTableView.estimatedRowHeight = 0;
  218. _changeStateTableView.estimatedSectionFooterHeight = 0;
  219. _changeStateTableView.estimatedSectionHeaderHeight = 0;
  220. UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  221. UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  222. CGFloat topSafeArea = safeAreaInsets.top;
  223. _changeStateTableView.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, 0, 0);
  224. // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
  225. }
  226. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
  227. if (@available(iOS 15.0, *)) {
  228. _changeStateTableView.sectionHeaderTopPadding = 0;
  229. }
  230. #endif
  231. }
  232. return _changeStateTableView;
  233. }
  234. - (void)layoutSubviews {
  235. [super layoutSubviews];
  236. CGFloat min_x = 0;
  237. CGFloat min_y = 0;
  238. CGFloat min_w = 0;
  239. CGFloat min_h = 0;
  240. CGFloat min_view_w = self.bounds.size.width;
  241. CGFloat min_view_h = self.bounds.size.height;
  242. CGFloat min_margin = 9;
  243. min_x = 0;
  244. min_y = 0;
  245. min_w = min_view_w;
  246. min_h = iPhoneX ? 110 : 80;
  247. self.topToolView.frame = CGRectMake(min_x, min_y, min_w, min_h);
  248. min_x = 0;
  249. min_y = 0;
  250. min_w = min_view_w;
  251. min_h = 20;
  252. self.statusBarView.frame = CGRectMake(min_x, min_y, min_w, min_h);
  253. min_x = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: 15;
  254. if (@available(iOS 13.0, *)) {
  255. if (self.showCustomStatusBar) {
  256. min_y = self.statusBarView.zf_bottom;
  257. } else {
  258. min_y = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ? 10 : (iPhoneX ? 40 : 20);
  259. }
  260. } else {
  261. min_y = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 10: (iPhoneX ? 40 : 20);
  262. }
  263. min_w = 40;
  264. min_h = 40;
  265. self.backBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  266. min_x = self.backBtn.zf_right + 5;
  267. min_y = 0;
  268. min_w = min_view_w - min_x - 15 ;
  269. min_h = 30;
  270. self.titleLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
  271. self.titleLabel.zf_centerY = self.backBtn.zf_centerY;
  272. min_h = iPhoneX ? 100 : 100;
  273. min_x = 0;
  274. min_y = min_view_h - min_h;
  275. min_w = min_view_w;
  276. self.bottomToolView.frame = CGRectMake(min_x, min_y, min_w, min_h);
  277. min_x = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: 15;
  278. min_y = 32;
  279. min_w = 30;
  280. min_h = 30;
  281. self.playOrPauseBtn_temp.frame = CGRectMake(min_x, min_y, min_w, min_h);
  282. // self.playOrPauseBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  283. // min_x = self.playOrPauseBtn_temp.zf_right;
  284. min_y = 0;
  285. min_w = 62;
  286. min_h = 30;
  287. self.currentTimeLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
  288. self.currentTimeLabel.zf_centerY = self.playOrPauseBtn_temp.zf_centerY;
  289. min_w = 62;
  290. min_x = self.bottomToolView.zf_width - min_w - ((iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: min_margin);
  291. min_y = 0;
  292. min_h = 30;
  293. self.totalTimeLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
  294. self.totalTimeLabel.zf_centerY = self.playOrPauseBtn_temp.zf_centerY;
  295. min_x = self.currentTimeLabel.zf_right + 4;
  296. min_y = 0;
  297. min_w = self.totalTimeLabel.zf_left - min_x - 4;
  298. min_h = 30;
  299. self.slider.frame = CGRectMake(min_x, min_y, min_w, min_h);
  300. self.slider.zf_centerY = self.playOrPauseBtn_temp.zf_centerY;
  301. min_x = 0;
  302. min_y = self.currentTimeLabel.zf_bottom+6;
  303. min_w = 24;
  304. min_h = 24;
  305. self.playOrPauseBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  306. self.playOrPauseBtn.zf_centerX = self.currentTimeLabel.zf_centerX;
  307. min_x = self.playOrPauseBtn.zf_right+12;
  308. min_y = 0;
  309. min_w = 24;
  310. min_h = 24;
  311. self.nextBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  312. self.nextBtn.zf_centerY = self.playOrPauseBtn.zf_centerY;
  313. min_x = 0;
  314. min_y = 0;
  315. min_w = 50;
  316. min_h = 20;
  317. self.pBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  318. self.pBtn.zf_centerY = self.playOrPauseBtn.zf_centerY;
  319. self.pBtn.zf_centerX = self.totalTimeLabel.zf_centerX;
  320. min_x = 0;
  321. min_y = 0;
  322. min_w = 30;
  323. min_h = 20;
  324. self.speedBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  325. self.speedBtn.zf_centerY = self.playOrPauseBtn.zf_centerY;
  326. self.speedBtn.zf_right = self.pBtn.zf_left-20;
  327. min_x = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 50: 18;
  328. min_y = 0;
  329. min_w = 40;
  330. min_h = 40;
  331. self.lockBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  332. self.lockBtn.zf_centerY = self.zf_centerY;
  333. if (!self.isShow) {
  334. self.topToolView.zf_y = -self.topToolView.zf_height;
  335. self.bottomToolView.zf_y = self.zf_height;
  336. self.lockBtn.zf_left = iPhoneX ? -82: -47;
  337. } else {
  338. self.lockBtn.zf_left = iPhoneX ? 50: 18;
  339. if (self.player.isLockedScreen) {
  340. self.topToolView.zf_y = -self.topToolView.zf_height;
  341. self.bottomToolView.zf_y = self.zf_height;
  342. } else {
  343. self.topToolView.zf_y = 0;
  344. self.bottomToolView.zf_y = self.zf_height - self.bottomToolView.zf_height;
  345. }
  346. }
  347. }
  348. - (void)makeSubViewsAction {
  349. [self.backBtn addTarget:self action:@selector(backBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
  350. [self.playOrPauseBtn addTarget:self action:@selector(playPauseButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
  351. [self.lockBtn addTarget:self action:@selector(lockButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
  352. [self.speedBtn addTarget:self action:@selector(speedButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
  353. [self.pBtn addTarget:self action:@selector(pButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
  354. [self.nextBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
  355. }
  356. -(void)nextAction{
  357. if(self.nextBtnClickCallback){
  358. self.nextBtnClickCallback();
  359. }
  360. }
  361. - (void)hideControlDetailView{
  362. self.changeStateImageView.hidden = true;
  363. }
  364. #pragma mark - action
  365. - (void)layoutControllerViews {
  366. [self layoutIfNeeded];
  367. [self setNeedsLayout];
  368. }
  369. -(void)speedButtonClickAction{
  370. [self hideControlView];
  371. self.stateType = 0;
  372. // UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  373. // UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  374. // CGFloat topSafeArea = safeAreaInsets.top;
  375. self.changeStateTableView.contentInset = UIEdgeInsetsMake((kScreenHeight - 48*self.speedArr.count)/2-20, 0, 0, 0);
  376. //
  377. [self.changeStateTableView reloadData];
  378. self.changeStateImageView.hidden = false;
  379. // if(self.speedBtnClickCallback){
  380. // self.speedBtnClickCallback();
  381. // }
  382. }
  383. -(void)pButtonClickAction{
  384. [self hideControlView];
  385. self.stateType = 1;
  386. // UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  387. // UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  388. // CGFloat topSafeArea = safeAreaInsets.top;
  389. self.changeStateTableView.contentInset = UIEdgeInsetsMake((kScreenHeight - 66*self.pArr.count)/2-20, 0, 0, 0);
  390. //(SCREEN_WIDTH - 66*self.pArr.count)/2
  391. [self.changeStateTableView reloadData];
  392. self.changeStateImageView.hidden = false;
  393. // if(self.pBtnClickCallback){
  394. // self.pBtnClickCallback();
  395. // }
  396. }
  397. - (void)backBtnClickAction:(UIButton *)sender {
  398. self.lockBtn.selected = NO;
  399. self.player.lockedScreen = NO;
  400. self.lockBtn.selected = NO;
  401. if (self.player.orientationObserver.supportInterfaceOrientation & ZFInterfaceOrientationMaskPortrait) {
  402. [self.player enterFullScreen:NO animated:YES];
  403. }
  404. if (self.backBtnClickCallback) {
  405. self.backBtnClickCallback();
  406. }
  407. }
  408. - (void)playPauseButtonClickAction:(UIButton *)sender {
  409. [self playOrPause];
  410. }
  411. /// 根据当前播放状态取反
  412. - (void)playOrPause {
  413. self.playOrPauseBtn.selected = !self.playOrPauseBtn.isSelected;
  414. self.playOrPauseBtn.isSelected? [self.player.currentPlayerManager play]: [self.player.currentPlayerManager pause];
  415. }
  416. - (void)playBtnSelectedState:(BOOL)selected {
  417. self.playOrPauseBtn.selected = selected;
  418. }
  419. - (void)lockButtonClickAction:(UIButton *)sender {
  420. sender.selected = !sender.selected;
  421. self.player.lockedScreen = sender.selected;
  422. }
  423. #pragma mark - ZFSliderViewDelegate
  424. - (void)sliderTouchBegan:(float)value {
  425. self.slider.isdragging = YES;
  426. }
  427. - (void)sliderTouchEnded:(float)value {
  428. if (self.player.totalTime > 0) {
  429. self.slider.isdragging = YES;
  430. if (self.sliderValueChanging) self.sliderValueChanging(value, self.slider.isForward);
  431. @zf_weakify(self)
  432. [self.player seekToTime:self.player.totalTime*value completionHandler:^(BOOL finished) {
  433. @zf_strongify(self)
  434. self.slider.isdragging = NO;
  435. if (finished) {
  436. if (self.sliderValueChanged) self.sliderValueChanged(value);
  437. if (self.seekToPlay) {
  438. [self.player.currentPlayerManager play];
  439. }
  440. }
  441. }];
  442. } else {
  443. self.slider.isdragging = NO;
  444. self.slider.value = 0;
  445. }
  446. }
  447. - (void)sliderValueChanged:(float)value {
  448. if (self.player.totalTime == 0) {
  449. self.slider.value = 0;
  450. return;
  451. }
  452. self.slider.isdragging = YES;
  453. NSString *currentTimeString = [ZFUtilities convertTimeSecond:self.player.totalTime*value];
  454. self.currentTimeLabel.text = currentTimeString;
  455. self.currentTime = self.player.totalTime*value;
  456. if (self.sliderValueChanging) self.sliderValueChanging(value,self.slider.isForward);
  457. }
  458. - (void)sliderTapped:(float)value {
  459. [self sliderTouchEnded:value];
  460. NSString *currentTimeString = [ZFUtilities convertTimeSecond:self.player.totalTime*value];
  461. self.currentTimeLabel.text = currentTimeString;
  462. self.currentTime = self.player.totalTime*value;
  463. }
  464. #pragma mark - public method
  465. /// 重置ControlView
  466. - (void)resetControlView {
  467. self.slider.value = 0;
  468. self.slider.bufferValue = 0;
  469. self.currentTimeLabel.text = @"00:00";
  470. self.totalTimeLabel.text = @"00:00";
  471. self.backgroundColor = [UIColor clearColor];
  472. self.playOrPauseBtn.selected = YES;
  473. self.titleLabel.text = @"";
  474. self.topToolView.alpha = 1;
  475. self.bottomToolView.alpha = 1;
  476. self.isShow = NO;
  477. self.lockBtn.selected = self.player.isLockedScreen;
  478. }
  479. - (void)showControlView {
  480. self.changeStateImageView.hidden = true;
  481. self.lockBtn.alpha = 1;
  482. self.isShow = YES;
  483. if (self.player.isLockedScreen) {
  484. self.topToolView.zf_y = -self.topToolView.zf_height;
  485. self.bottomToolView.zf_y = self.zf_height;
  486. } else {
  487. self.topToolView.zf_y = 0;
  488. self.bottomToolView.zf_y = self.zf_height - self.bottomToolView.zf_height;
  489. }
  490. self.lockBtn.zf_left = iPhoneX ? 50: 18;
  491. self.player.statusBarHidden = NO;
  492. if (self.player.isLockedScreen) {
  493. self.topToolView.alpha = 0;
  494. self.bottomToolView.alpha = 0;
  495. } else {
  496. self.topToolView.alpha = 1;
  497. self.bottomToolView.alpha = 1;
  498. }
  499. }
  500. - (void)hideControlView {
  501. self.isShow = NO;
  502. self.topToolView.zf_y = -self.topToolView.zf_height;
  503. self.bottomToolView.zf_y = self.zf_height;
  504. self.lockBtn.zf_left = iPhoneX ? -82: -47;
  505. self.player.statusBarHidden = YES;
  506. self.topToolView.alpha = 0;
  507. self.bottomToolView.alpha = 0;
  508. self.lockBtn.alpha = 0;
  509. }
  510. - (BOOL)shouldResponseGestureWithPoint:(CGPoint)point withGestureType:(ZFPlayerGestureType)type touch:(nonnull UITouch *)touch {
  511. if(self.changeStateImageView.isHidden == false){
  512. CGRect rectx = [self.changeStateImageView convertRect:self.changeStateTableView.frame toView:self];
  513. if (CGRectContainsPoint(rectx, point)) {
  514. return YES;
  515. }
  516. }
  517. CGRect sliderRect = [self.bottomToolView convertRect:self.slider.frame toView:self];
  518. if (CGRectContainsPoint(sliderRect, point)) {
  519. return NO;
  520. }
  521. if (self.player.isLockedScreen && type != ZFPlayerGestureTypeSingleTap) { // 锁定屏幕方向后只相应tap手势
  522. return NO;
  523. }
  524. return YES;
  525. }
  526. - (void)videoPlayer:(ZFPlayerController *)videoPlayer presentationSizeChanged:(CGSize)size {
  527. self.lockBtn.hidden = self.player.orientationObserver.fullScreenMode == ZFFullScreenModePortrait;
  528. }
  529. /// 视频view即将旋转
  530. - (void)videoPlayer:(ZFPlayerController *)videoPlayer orientationWillChange:(ZFOrientationObserver *)observer {
  531. if (self.showCustomStatusBar) {
  532. if (self.hidden) {
  533. [self.statusBarView destoryTimer];
  534. } else {
  535. [self.statusBarView startTimer];
  536. }
  537. }
  538. }
  539. - (void)videoPlayer:(ZFPlayerController *)videoPlayer currentTime:(NSTimeInterval)currentTime totalTime:(NSTimeInterval)totalTime {
  540. if (!self.slider.isdragging) {
  541. NSString *currentTimeString = [ZFUtilities convertTimeSecond:currentTime];
  542. self.currentTimeLabel.text = currentTimeString;
  543. self.currentTime = currentTime;
  544. NSString *totalTimeString = [ZFUtilities convertTimeSecond:totalTime];
  545. self.totalTimeLabel.text = totalTimeString;
  546. self.slider.value = videoPlayer.progress;
  547. }
  548. }
  549. - (void)videoPlayer:(ZFPlayerController *)videoPlayer bufferTime:(NSTimeInterval)bufferTime {
  550. self.slider.bufferValue = videoPlayer.bufferProgress;
  551. }
  552. - (void)showTitle:(NSString *)title fullScreenMode:(ZFFullScreenMode)fullScreenMode {
  553. self.titleLabel.text = title;
  554. self.player.orientationObserver.fullScreenMode = fullScreenMode;
  555. self.lockBtn.hidden = fullScreenMode == ZFFullScreenModePortrait;
  556. }
  557. /// 调节播放进度slider和当前时间更新
  558. - (void)sliderValueChanged:(CGFloat)value currentTimeString:(NSString *)timeString {
  559. self.slider.value = value;
  560. self.currentTimeLabel.text = timeString;
  561. self.slider.isdragging = YES;
  562. [UIView animateWithDuration:0.3 animations:^{
  563. self.slider.sliderBtn.transform = CGAffineTransformMakeScale(1.2, 1.2);
  564. }];
  565. }
  566. /// 滑杆结束滑动
  567. - (void)sliderChangeEnded {
  568. self.slider.isdragging = NO;
  569. [UIView animateWithDuration:0.3 animations:^{
  570. self.slider.sliderBtn.transform = CGAffineTransformIdentity;
  571. }];
  572. }
  573. #pragma mark - setter
  574. - (void)setFullScreenMode:(ZFFullScreenMode)fullScreenMode {
  575. _fullScreenMode = fullScreenMode;
  576. self.player.orientationObserver.fullScreenMode = fullScreenMode;
  577. self.lockBtn.hidden = fullScreenMode == ZFFullScreenModePortrait;
  578. }
  579. - (void)setShowCustomStatusBar:(BOOL)showCustomStatusBar {
  580. _showCustomStatusBar = showCustomStatusBar;
  581. self.statusBarView.hidden = !showCustomStatusBar;
  582. }
  583. #pragma mark - getter
  584. - (ZFPlayerStatusBar *)statusBarView {
  585. if (!_statusBarView) {
  586. _statusBarView = [[ZFPlayerStatusBar alloc] init];
  587. _statusBarView.hidden = YES;
  588. }
  589. return _statusBarView;
  590. }
  591. - (UIView *)topToolView {
  592. if (!_topToolView) {
  593. _topToolView = [[UIView alloc] init];
  594. UIImage *image = ZFPlayer_Image(@"ZFPlayer_top_shadow");
  595. _topToolView.layer.contents = (id)image.CGImage;
  596. }
  597. return _topToolView;
  598. }
  599. - (UIButton *)backBtn {
  600. if (!_backBtn) {
  601. _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  602. [_backBtn setImage:ZFPlayer_Image(@"ZFPlayer_back_full") forState:UIControlStateNormal];
  603. }
  604. return _backBtn;
  605. }
  606. - (UILabel *)titleLabel {
  607. if (!_titleLabel) {
  608. _titleLabel = [[UILabel alloc] init];
  609. _titleLabel.textColor = [UIColor whiteColor];
  610. _titleLabel.font = [UIFont systemFontOfSize:15.0];
  611. }
  612. return _titleLabel;
  613. }
  614. - (UIView *)bottomToolView {
  615. if (!_bottomToolView) {
  616. _bottomToolView = [[UIView alloc] init];
  617. UIImage *image = ZFPlayer_Image(@"ZFPlayer_bottom_shadow");
  618. _bottomToolView.layer.contents = (id)image.CGImage;
  619. }
  620. return _bottomToolView;
  621. }
  622. -(UILabel *)playOrPauseBtn_temp{
  623. if (!_playOrPauseBtn_temp) {
  624. _playOrPauseBtn_temp = [UILabel new];
  625. }
  626. return _playOrPauseBtn_temp;
  627. }
  628. - (UIButton *)playOrPauseBtn {
  629. if (!_playOrPauseBtn) {
  630. _playOrPauseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  631. [_playOrPauseBtn setImage:ZFPlayer_Image(@"ZFPlayer_play") forState:UIControlStateNormal];
  632. [_playOrPauseBtn setImage:ZFPlayer_Image(@"ZFPlayer_pause") forState:UIControlStateSelected];
  633. }
  634. return _playOrPauseBtn;
  635. }
  636. - (UIButton *)nextBtn {
  637. if (!_nextBtn) {
  638. _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  639. [_nextBtn setImage:ZFPlayer_Image(@"zf_next_ic") forState:UIControlStateNormal];
  640. [_nextBtn setImage:ZFPlayer_Image(@"zf_next_ic") forState:UIControlStateSelected];
  641. }
  642. return _nextBtn;
  643. }
  644. - (UIButton *)speedBtn {
  645. if (!_speedBtn) {
  646. _speedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  647. [_speedBtn setTitle:@"倍速" forState:UIControlStateNormal];
  648. _speedBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  649. [_speedBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  650. }
  651. return _speedBtn;
  652. }
  653. - (UIButton *)pBtn {
  654. if (!_pBtn) {
  655. _pBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  656. [_pBtn setTitle:@"480P" forState:UIControlStateNormal];
  657. _pBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  658. [_pBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  659. }
  660. return _pBtn;
  661. }
  662. - (UILabel *)currentTimeLabel {
  663. if (!_currentTimeLabel) {
  664. _currentTimeLabel = [[UILabel alloc] init];
  665. _currentTimeLabel.textColor = [UIColor whiteColor];
  666. _currentTimeLabel.font = [UIFont systemFontOfSize:14.0f];
  667. _currentTimeLabel.textAlignment = NSTextAlignmentCenter;
  668. }
  669. return _currentTimeLabel;
  670. }
  671. - (ZFSliderView *)slider {
  672. if (!_slider) {
  673. _slider = [[ZFSliderView alloc] init];
  674. _slider.delegate = self;
  675. _slider.maximumTrackTintColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.8];
  676. _slider.bufferTrackTintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];
  677. _slider.minimumTrackTintColor = [UIColor whiteColor];
  678. [_slider setThumbImage:ZFPlayer_Image(@"ZFPlayer_slider") forState:UIControlStateNormal];
  679. _slider.sliderHeight = 2;
  680. }
  681. return _slider;
  682. }
  683. - (UILabel *)totalTimeLabel {
  684. if (!_totalTimeLabel) {
  685. _totalTimeLabel = [[UILabel alloc] init];
  686. _totalTimeLabel.textColor = [UIColor whiteColor];
  687. _totalTimeLabel.font = [UIFont systemFontOfSize:14.0f];
  688. _totalTimeLabel.textAlignment = NSTextAlignmentCenter;
  689. }
  690. return _totalTimeLabel;
  691. }
  692. - (UIButton *)lockBtn {
  693. if (!_lockBtn) {
  694. _lockBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  695. [_lockBtn setImage:ZFPlayer_Image(@"ZFPlayer_unlock-nor") forState:UIControlStateNormal];
  696. [_lockBtn setImage:ZFPlayer_Image(@"ZFPlayer_lock-nor") forState:UIControlStateSelected];
  697. }
  698. return _lockBtn;
  699. }
  700. @end
  701. @interface pcell1 ()
  702. @property(nonatomic,strong)UILabel *lab;
  703. @property(nonatomic,strong)UILabel *lab2;
  704. @property(nonatomic,strong)UIImageView *iv;
  705. @end
  706. @implementation pcell1
  707. + (instancetype)cellWithTableView:(UITableView *)tableView{
  708. static NSString *identifier = @"pcell1";
  709. pcell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  710. if (cell == nil) {
  711. cell = [[pcell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  712. }
  713. return cell;
  714. }
  715. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  716. {
  717. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  718. if (self) {
  719. [self creatView];
  720. }
  721. return self;
  722. }
  723. -(void)setIsSel:(BOOL)isSel{
  724. _isSel = isSel;
  725. if(isSel){
  726. self.lab.textColor = rgba(255, 212, 0, 1);
  727. self.lab2.textColor = rgba(255, 212, 0, 1);
  728. }else{
  729. self.lab.textColor = rgba(255, 255, 255, 1);
  730. self.lab2.textColor = rgba(255, 255, 255, 0.6);
  731. }
  732. }
  733. -(void)setIsNeedVip:(BOOL)isNeedVip{
  734. _isNeedVip = isNeedVip;
  735. if(isNeedVip){
  736. self.iv.hidden = false;
  737. }else{
  738. self.iv.hidden = true;
  739. }
  740. }
  741. -(void)setStrArr:(NSArray *)strArr{
  742. _strArr = strArr;
  743. self.lab.text = strArr[0];
  744. self.lab2.text = strArr[1];
  745. }
  746. -(void)creatView{
  747. self.selectionStyle = UITableViewCellSelectionStyleNone;
  748. self.backgroundColor = [UIColor clearColor];
  749. UIView *v = [UIView new];
  750. [self.contentView addSubview:v];
  751. [v mas_makeConstraints:^(MASConstraintMaker *make) {
  752. make.edges.equalTo(self.contentView);
  753. }];
  754. UILabel *lab =[UILabel new];
  755. lab.text = @"1080P";
  756. lab.textColor = rgba(255, 255, 255, 1);
  757. lab.font = [UIFont systemFontOfSize:18];
  758. self.lab = lab;
  759. [v addSubview:lab];
  760. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  761. make.top.equalTo(v).offset(12);
  762. make.centerX.equalTo(v).offset(iphoneX?20:0);
  763. }];
  764. UIImageView *vicon = [UIImageView new];
  765. vicon.image = [UIImage imageNamed:@""];
  766. self.iv = vicon;
  767. [v addSubview:vicon];
  768. [vicon mas_makeConstraints:^(MASConstraintMaker *make) {
  769. make.centerY.equalTo(lab);
  770. make.left.equalTo(lab.mas_right).offset(4);
  771. make.size.mas_equalTo(CGSizeMake(25, 14));
  772. }];
  773. UILabel *lab2 =[UILabel new];
  774. lab2.text = @"高清 SDR";
  775. lab2.textColor = rgba(255, 255, 255, 0.6);
  776. lab2.font = [UIFont systemFontOfSize:11];
  777. self.lab2 = lab2;
  778. [v addSubview:lab2];
  779. [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
  780. make.top.equalTo(lab.mas_bottom).offset(12);
  781. make.left.equalTo(lab);
  782. }];
  783. UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  784. [v addGestureRecognizer:gest];
  785. }
  786. -(void)tapAction{
  787. @zf_weakify(self)
  788. if(self.tapBlock){
  789. @zf_strongify(self)
  790. self.tapBlock(self.index);
  791. }
  792. }
  793. @end
  794. @interface pcell2 ()
  795. @property(nonatomic,strong)UILabel *lab;
  796. @end
  797. @implementation pcell2
  798. + (instancetype)cellWithTableView:(UITableView *)tableView{
  799. static NSString *identifier = @"pcell2";
  800. pcell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  801. if (cell == nil) {
  802. cell = [[pcell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  803. }
  804. return cell;
  805. }
  806. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  807. {
  808. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  809. if (self) {
  810. [self creatView];
  811. }
  812. return self;
  813. }
  814. -(void)setIsSel:(BOOL)isSel{
  815. _isSel = isSel;
  816. if(isSel){
  817. // [self.lab setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal] ;
  818. self.lab.textColor = rgba(255, 212, 0, 1);
  819. }else{
  820. // [self.lab setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal] ;
  821. self.lab.textColor = rgba(255, 255, 255, 1);
  822. }
  823. }
  824. -(void)setStr:(NSString *)str{
  825. _str = str;
  826. // [self.lab setTitle:str forState:UIControlStateNormal];
  827. self.lab.text = str;
  828. }
  829. -(void)creatView{
  830. self.selectionStyle = UITableViewCellSelectionStyleNone;
  831. self.backgroundColor = [UIColor clearColor];
  832. UIView *v = [UIView new];
  833. [self.contentView addSubview:v];
  834. [v mas_makeConstraints:^(MASConstraintMaker *make) {
  835. make.edges.equalTo(self.contentView);
  836. }];
  837. UILabel *lab =[UILabel new];
  838. lab.text = @"2X";
  839. lab.textColor = rgba(255, 255, 255, 1);
  840. // [lab setTitle:@"2X" forState:UIControlStateNormal];
  841. // [lab setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal] ;
  842. lab.font = [UIFont boldSystemFontOfSize:18];
  843. self.lab = lab;
  844. // [lab addTarget:self action:@selector(labAction) forControlEvents:UIControlEventTouchUpInside];
  845. [v addSubview:lab];
  846. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  847. make.top.equalTo(v).offset(12);
  848. make.centerX.equalTo(v).offset(iphoneX?20:0);
  849. }];
  850. UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labAction)];
  851. [v addGestureRecognizer:gest];
  852. }
  853. -(void)labAction{
  854. @zf_weakify(self)
  855. if(self.tapBlock){
  856. @zf_strongify(self)
  857. self.tapBlock(self.index);
  858. }
  859. }
  860. @end