| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969 |
- //
- // ZFLandScapeControlView.m
- // ZFPlayer
- //
- // Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- #import "ZFLandScapeControlView2.h"
- #import "ZFAVPlayerManager.h"
- #import "UIView+ZFFrame.h"
- #import "ZFUtilities.h"
- #import "ZFPlayerStatusBar.h"
- #if __has_include(<ZFPlayer/ZFPlayer.h>)
- #import <ZFPlayer/ZFPlayerConst.h>
- #else
- #import "ZFPlayerConst.h"
- #endif
- @interface ZFLandScapeControlView2 () <ZFSliderViewDelegate,UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) ZFPlayerStatusBar *statusBarView;
- /// 顶部工具栏
- @property (nonatomic, strong) UIView *topToolView;
- /// 返回按钮
- @property (nonatomic, strong) UIButton *backBtn;
- /// 标题
- @property (nonatomic, strong) UILabel *titleLabel;
- /// 底部工具栏
- @property (nonatomic, strong) UIView *bottomToolView;
- /// 播放或暂停按钮
- @property (nonatomic, strong) UIButton *playOrPauseBtn;
- @property (nonatomic, strong) UILabel *playOrPauseBtn_temp;
- @property (nonatomic, strong) UIButton *nextBtn;
- @property (nonatomic, strong) UIButton *speedBtn;
- @property (nonatomic, strong) UIButton *pBtn;
- /// 播放的当前时间
- @property (nonatomic, strong) UILabel *currentTimeLabel;
- /// 滑杆
- @property (nonatomic, strong) ZFSliderView *slider;
- /// 视频总时间
- @property (nonatomic, strong) UILabel *totalTimeLabel;
- /// 锁定屏幕按钮
- @property (nonatomic, strong) UIButton *lockBtn;
- @property (nonatomic, assign) BOOL isShow;
- @property (nonatomic, strong) UITableView *changeStateTableView;
- //0倍速、1清晰度
- @property (nonatomic, assign) int stateType;
- @property (nonatomic, strong) NSArray* speedArr;
- @property (nonatomic, strong) NSArray* speedValArr;
- @property (nonatomic, assign) NSInteger defaultSpeedIndex;
- @property (nonatomic, assign)NSTimeInterval currentTime;
- @end
- @implementation ZFLandScapeControlView2
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
- }
- -(void)setPArr:(NSArray *)pArr{
- _pArr = pArr;
- }
- -(void)setDefaultPIndex:(NSInteger)defaultPIndex{
- _defaultPIndex = defaultPIndex;
- NSArray *pa= self.pArr[defaultPIndex];
- [self.pBtn setTitle:pa[0] forState:UIControlStateNormal];
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.defaultSpeedIndex = 3;
- self.defaultPIndex = 2;
- self.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
- self.speedArr = @[@"2X",@"1.5X",@"1.25X",@"正常",@"0.5X"];
- self.speedValArr = @[@"2",@"1.5",@"1.25",@"1.0",@"0.5"];
- [self addSubview:self.topToolView];
- [self.topToolView addSubview:self.statusBarView];
- [self.topToolView addSubview:self.backBtn];
- [self.topToolView addSubview:self.titleLabel];
- [self addSubview:self.bottomToolView];
- [self.bottomToolView addSubview:self.playOrPauseBtn_temp];
- [self.bottomToolView addSubview:self.playOrPauseBtn];
- [self.bottomToolView addSubview:self.currentTimeLabel];
-
- [self.bottomToolView addSubview:self.slider];
- [self.bottomToolView addSubview:self.totalTimeLabel];
- [self.bottomToolView addSubview:self.nextBtn];
- [self.bottomToolView addSubview:self.speedBtn];
- [self.bottomToolView addSubview:self.pBtn];
- [self addSubview:self.lockBtn];
-
-
- UIImageView *iv= [UIImageView new];
- iv.backgroundColor = rgba(0, 0, 0, 0.5);
- self.changeStateImageView = iv;
- iv.image = [UIImage imageNamed:@""];
- iv.userInteractionEnabled = true;
- [self addSubview:iv];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.right.equalTo(self);
- make.width.mas_equalTo(@(440));
- make.height.mas_equalTo(@(kScreenWidth));
- }];
-
- [iv addSubview:self.changeStateTableView];
- [self.changeStateTableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(iv);
- }];
-
- iv.hidden = true;
-
- // 设置子控件的响应事件
- [self makeSubViewsAction];
- [self resetControlView];
-
- /// statusBarFrame changed
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutControllerViews) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
- }
- return self;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- //倍速
- @zf_weakify(self);
- if(self.stateType == 0){
- pcell2 *cell = [pcell2 cellWithTableView:tableView];
- cell.str = self.speedArr[indexPath.row];
- if(self.defaultSpeedIndex == indexPath.row){
- cell.isSel = true;
- }else{
- cell.isSel = false;
- }
- cell.tapBlock = ^(NSInteger index) {
- @zf_strongify(self);
- if(self.defaultSpeedIndex == indexPath.row){
- return;
- }
- self.defaultSpeedIndex = indexPath.row;
- [self.changeStateTableView reloadData];
- self.changeStateImageView.hidden = true;
- if(self.speedBtnClickCallback){
- self.speedBtnClickCallback([self.speedValArr[indexPath.row] floatValue]);
- }
- [self->_speedBtn setTitle:self.speedArr[indexPath.row] forState:UIControlStateNormal];
- };
- return cell;
- //清晰度
- }else{
- pcell1 *cell = [pcell1 cellWithTableView:tableView];
- cell.strArr = self.pArr[indexPath.row];
- if(self.defaultPIndex == indexPath.row){
- cell.isSel = true;
- }else{
- cell.isSel = false;
- }
- cell.tapBlock = ^(NSInteger index) {
- @zf_strongify(self);
- // ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager;
- // manager.rate = [self.speedValArr[indexPath.row] floatValue];
- if(self.defaultPIndex == indexPath.row){
- return;
- }
- self.defaultPIndex = indexPath.row;
- [self.changeStateTableView reloadData];
- if(self.pBtnClickCallback){
- NSString *t = self.currentTimeLabel.text;
- int ti = 0;
- NSArray *arr = [t componentsSeparatedByString:@":"];
- if(arr.count == 3){
- ti = [arr[0] intValue] *3600 + [arr[1] intValue]*60 + [arr[2] intValue];
- }else if(arr.count == 2){
- ti = [arr[0] intValue]*60 + [arr[1] intValue];
- }else if(arr.count == 1){
- ti = [arr[0] intValue];;
- }
-
- self.pBtnClickCallback(indexPath.row,ti);
- }
- self.changeStateImageView.hidden = true;
- NSArray *pa= self.pArr[indexPath.row];
- [self->_pBtn setTitle:pa[0] forState:UIControlStateNormal];
- };
- return cell;
- }
-
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- if(self.stateType == 0){
- return self.speedArr.count;
- }else{
- return self.pArr.count;
- }
-
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- if(self.stateType == 0){
- return 48;
- }else{
- return 66;
- }
-
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- // if(self.stateType == 0){
- // }
- }
- -(UITableView *)changeStateTableView{
- if(!_changeStateTableView){
- _changeStateTableView =[[UITableView alloc] initWithFrame:self.bounds style:UITableViewStyleGrouped];
- _changeStateTableView.delegate = self;
- _changeStateTableView.dataSource = self;
- _changeStateTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _changeStateTableView.showsVerticalScrollIndicator = false;
- _changeStateTableView.showsHorizontalScrollIndicator = false;
- _changeStateTableView.backgroundColor = [UIColor clearColor];
- // _tableView.backgroundColor = [UIColor redColor];
- if (@available(iOS 11, *)) {
- _changeStateTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- _changeStateTableView.estimatedRowHeight = 0;
- _changeStateTableView.estimatedSectionFooterHeight = 0;
- _changeStateTableView.estimatedSectionHeaderHeight = 0;
-
- UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
- UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
- CGFloat topSafeArea = safeAreaInsets.top;
- _changeStateTableView.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, 0, 0);
- // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
- }
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
- if (@available(iOS 15.0, *)) {
- _changeStateTableView.sectionHeaderTopPadding = 0;
- }
- #endif
- }
- return _changeStateTableView;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- CGFloat min_x = 0;
- CGFloat min_y = 0;
- CGFloat min_w = 0;
- CGFloat min_h = 0;
- CGFloat min_view_w = self.bounds.size.width;
- CGFloat min_view_h = self.bounds.size.height;
-
- CGFloat min_margin = 9;
-
- min_x = 0;
- min_y = 0;
- min_w = min_view_w;
- min_h = iPhoneX ? 110 : 80;
- self.topToolView.frame = CGRectMake(min_x, min_y, min_w, min_h);
-
- min_x = 0;
- min_y = 0;
- min_w = min_view_w;
- min_h = 20;
- self.statusBarView.frame = CGRectMake(min_x, min_y, min_w, min_h);
- min_x = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: 15;
- if (@available(iOS 13.0, *)) {
- if (self.showCustomStatusBar) {
- min_y = self.statusBarView.zf_bottom;
- } else {
- min_y = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ? 10 : (iPhoneX ? 40 : 20);
- }
- } else {
- min_y = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 10: (iPhoneX ? 40 : 20);
- }
- min_w = 40;
- min_h = 40;
- self.backBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
-
- min_x = self.backBtn.zf_right + 5;
- min_y = 0;
- min_w = min_view_w - min_x - 15 ;
- min_h = 30;
- self.titleLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.titleLabel.zf_centerY = self.backBtn.zf_centerY;
-
- min_h = iPhoneX ? 100 : 100;
- min_x = 0;
- min_y = min_view_h - min_h;
- min_w = min_view_w;
- self.bottomToolView.frame = CGRectMake(min_x, min_y, min_w, min_h);
-
- min_x = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: 15;
- min_y = 32;
- min_w = 30;
- min_h = 30;
- self.playOrPauseBtn_temp.frame = CGRectMake(min_x, min_y, min_w, min_h);
- // self.playOrPauseBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
-
- // min_x = self.playOrPauseBtn_temp.zf_right;
- min_y = 0;
- min_w = 62;
- min_h = 30;
- self.currentTimeLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.currentTimeLabel.zf_centerY = self.playOrPauseBtn_temp.zf_centerY;
-
- min_w = 62;
- min_x = self.bottomToolView.zf_width - min_w - ((iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 44: min_margin);
- min_y = 0;
- min_h = 30;
- self.totalTimeLabel.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.totalTimeLabel.zf_centerY = self.playOrPauseBtn_temp.zf_centerY;
-
- min_x = self.currentTimeLabel.zf_right + 4;
- min_y = 0;
- min_w = self.totalTimeLabel.zf_left - min_x - 4;
- min_h = 30;
- self.slider.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.slider.zf_centerY = self.playOrPauseBtn_temp.zf_centerY;
-
- min_x = 0;
- min_y = self.currentTimeLabel.zf_bottom+6;
- min_w = 24;
- min_h = 24;
- self.playOrPauseBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.playOrPauseBtn.zf_centerX = self.currentTimeLabel.zf_centerX;
-
- min_x = self.playOrPauseBtn.zf_right+12;
- min_y = 0;
- min_w = 24;
- min_h = 24;
- self.nextBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.nextBtn.zf_centerY = self.playOrPauseBtn.zf_centerY;
-
-
- min_x = 0;
- min_y = 0;
- min_w = 50;
- min_h = 20;
- self.pBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.pBtn.zf_centerY = self.playOrPauseBtn.zf_centerY;
- self.pBtn.zf_centerX = self.totalTimeLabel.zf_centerX;
-
- min_x = 0;
- min_y = 0;
- min_w = 30;
- min_h = 20;
- self.speedBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.speedBtn.zf_centerY = self.playOrPauseBtn.zf_centerY;
- self.speedBtn.zf_right = self.pBtn.zf_left-20;
-
-
- min_x = (iPhoneX && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) ? 50: 18;
- min_y = 0;
- min_w = 40;
- min_h = 40;
- self.lockBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
- self.lockBtn.zf_centerY = self.zf_centerY;
-
- if (!self.isShow) {
- self.topToolView.zf_y = -self.topToolView.zf_height;
- self.bottomToolView.zf_y = self.zf_height;
- self.lockBtn.zf_left = iPhoneX ? -82: -47;
- } else {
- self.lockBtn.zf_left = iPhoneX ? 50: 18;
- if (self.player.isLockedScreen) {
- self.topToolView.zf_y = -self.topToolView.zf_height;
- self.bottomToolView.zf_y = self.zf_height;
- } else {
- self.topToolView.zf_y = 0;
- self.bottomToolView.zf_y = self.zf_height - self.bottomToolView.zf_height;
- }
- }
- }
- - (void)makeSubViewsAction {
- [self.backBtn addTarget:self action:@selector(backBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.playOrPauseBtn addTarget:self action:@selector(playPauseButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.lockBtn addTarget:self action:@selector(lockButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.speedBtn addTarget:self action:@selector(speedButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
- [self.pBtn addTarget:self action:@selector(pButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
- [self.nextBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
- }
- -(void)nextAction{
- if(self.nextBtnClickCallback){
- self.nextBtnClickCallback();
- }
- }
- - (void)hideControlDetailView{
- self.changeStateImageView.hidden = true;
- }
- #pragma mark - action
- - (void)layoutControllerViews {
- [self layoutIfNeeded];
- [self setNeedsLayout];
- }
- -(void)speedButtonClickAction{
- [self hideControlView];
- self.stateType = 0;
- // UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
- // UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
- // CGFloat topSafeArea = safeAreaInsets.top;
- self.changeStateTableView.contentInset = UIEdgeInsetsMake((kScreenHeight - 48*self.speedArr.count)/2-20, 0, 0, 0);
- //
- [self.changeStateTableView reloadData];
- self.changeStateImageView.hidden = false;
- // if(self.speedBtnClickCallback){
- // self.speedBtnClickCallback();
- // }
- }
- -(void)pButtonClickAction{
- [self hideControlView];
- self.stateType = 1;
- // UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
- // UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
- // CGFloat topSafeArea = safeAreaInsets.top;
- self.changeStateTableView.contentInset = UIEdgeInsetsMake((kScreenHeight - 66*self.pArr.count)/2-20, 0, 0, 0);
- //(SCREEN_WIDTH - 66*self.pArr.count)/2
- [self.changeStateTableView reloadData];
- self.changeStateImageView.hidden = false;
- // if(self.pBtnClickCallback){
- // self.pBtnClickCallback();
- // }
- }
- - (void)backBtnClickAction:(UIButton *)sender {
- self.lockBtn.selected = NO;
- self.player.lockedScreen = NO;
- self.lockBtn.selected = NO;
- if (self.player.orientationObserver.supportInterfaceOrientation & ZFInterfaceOrientationMaskPortrait) {
- [self.player enterFullScreen:NO animated:YES];
- }
- if (self.backBtnClickCallback) {
- self.backBtnClickCallback();
- }
- }
- - (void)playPauseButtonClickAction:(UIButton *)sender {
- [self playOrPause];
- }
- /// 根据当前播放状态取反
- - (void)playOrPause {
- self.playOrPauseBtn.selected = !self.playOrPauseBtn.isSelected;
- self.playOrPauseBtn.isSelected? [self.player.currentPlayerManager play]: [self.player.currentPlayerManager pause];
- }
- - (void)playBtnSelectedState:(BOOL)selected {
- self.playOrPauseBtn.selected = selected;
- }
- - (void)lockButtonClickAction:(UIButton *)sender {
- sender.selected = !sender.selected;
- self.player.lockedScreen = sender.selected;
- }
- #pragma mark - ZFSliderViewDelegate
- - (void)sliderTouchBegan:(float)value {
- self.slider.isdragging = YES;
- }
- - (void)sliderTouchEnded:(float)value {
- if (self.player.totalTime > 0) {
- self.slider.isdragging = YES;
- if (self.sliderValueChanging) self.sliderValueChanging(value, self.slider.isForward);
- @zf_weakify(self)
- [self.player seekToTime:self.player.totalTime*value completionHandler:^(BOOL finished) {
- @zf_strongify(self)
- self.slider.isdragging = NO;
- if (finished) {
- if (self.sliderValueChanged) self.sliderValueChanged(value);
- if (self.seekToPlay) {
- [self.player.currentPlayerManager play];
- }
- }
- }];
- } else {
- self.slider.isdragging = NO;
- self.slider.value = 0;
- }
- }
- - (void)sliderValueChanged:(float)value {
- if (self.player.totalTime == 0) {
- self.slider.value = 0;
- return;
- }
- self.slider.isdragging = YES;
- NSString *currentTimeString = [ZFUtilities convertTimeSecond:self.player.totalTime*value];
- self.currentTimeLabel.text = currentTimeString;
- self.currentTime = self.player.totalTime*value;
- if (self.sliderValueChanging) self.sliderValueChanging(value,self.slider.isForward);
- }
- - (void)sliderTapped:(float)value {
- [self sliderTouchEnded:value];
- NSString *currentTimeString = [ZFUtilities convertTimeSecond:self.player.totalTime*value];
- self.currentTimeLabel.text = currentTimeString;
- self.currentTime = self.player.totalTime*value;
- }
- #pragma mark - public method
- /// 重置ControlView
- - (void)resetControlView {
- self.slider.value = 0;
- self.slider.bufferValue = 0;
- self.currentTimeLabel.text = @"00:00";
- self.totalTimeLabel.text = @"00:00";
- self.backgroundColor = [UIColor clearColor];
- self.playOrPauseBtn.selected = YES;
- self.titleLabel.text = @"";
- self.topToolView.alpha = 1;
- self.bottomToolView.alpha = 1;
- self.isShow = NO;
- self.lockBtn.selected = self.player.isLockedScreen;
- }
- - (void)showControlView {
- self.changeStateImageView.hidden = true;
- self.lockBtn.alpha = 1;
- self.isShow = YES;
- if (self.player.isLockedScreen) {
- self.topToolView.zf_y = -self.topToolView.zf_height;
- self.bottomToolView.zf_y = self.zf_height;
- } else {
- self.topToolView.zf_y = 0;
- self.bottomToolView.zf_y = self.zf_height - self.bottomToolView.zf_height;
- }
- self.lockBtn.zf_left = iPhoneX ? 50: 18;
- self.player.statusBarHidden = NO;
- if (self.player.isLockedScreen) {
- self.topToolView.alpha = 0;
- self.bottomToolView.alpha = 0;
- } else {
- self.topToolView.alpha = 1;
- self.bottomToolView.alpha = 1;
- }
- }
- - (void)hideControlView {
- self.isShow = NO;
- self.topToolView.zf_y = -self.topToolView.zf_height;
- self.bottomToolView.zf_y = self.zf_height;
- self.lockBtn.zf_left = iPhoneX ? -82: -47;
- self.player.statusBarHidden = YES;
- self.topToolView.alpha = 0;
- self.bottomToolView.alpha = 0;
- self.lockBtn.alpha = 0;
- }
- - (BOOL)shouldResponseGestureWithPoint:(CGPoint)point withGestureType:(ZFPlayerGestureType)type touch:(nonnull UITouch *)touch {
- if(self.changeStateImageView.isHidden == false){
- CGRect rectx = [self.changeStateImageView convertRect:self.changeStateTableView.frame toView:self];
- if (CGRectContainsPoint(rectx, point)) {
- return YES;
- }
- }
- CGRect sliderRect = [self.bottomToolView convertRect:self.slider.frame toView:self];
- if (CGRectContainsPoint(sliderRect, point)) {
- return NO;
- }
- if (self.player.isLockedScreen && type != ZFPlayerGestureTypeSingleTap) { // 锁定屏幕方向后只相应tap手势
- return NO;
- }
- return YES;
- }
- - (void)videoPlayer:(ZFPlayerController *)videoPlayer presentationSizeChanged:(CGSize)size {
- self.lockBtn.hidden = self.player.orientationObserver.fullScreenMode == ZFFullScreenModePortrait;
- }
- /// 视频view即将旋转
- - (void)videoPlayer:(ZFPlayerController *)videoPlayer orientationWillChange:(ZFOrientationObserver *)observer {
- if (self.showCustomStatusBar) {
- if (self.hidden) {
- [self.statusBarView destoryTimer];
- } else {
- [self.statusBarView startTimer];
- }
- }
- }
- - (void)videoPlayer:(ZFPlayerController *)videoPlayer currentTime:(NSTimeInterval)currentTime totalTime:(NSTimeInterval)totalTime {
- if (!self.slider.isdragging) {
- NSString *currentTimeString = [ZFUtilities convertTimeSecond:currentTime];
- self.currentTimeLabel.text = currentTimeString;
- self.currentTime = currentTime;
- NSString *totalTimeString = [ZFUtilities convertTimeSecond:totalTime];
- self.totalTimeLabel.text = totalTimeString;
- self.slider.value = videoPlayer.progress;
- }
- }
- - (void)videoPlayer:(ZFPlayerController *)videoPlayer bufferTime:(NSTimeInterval)bufferTime {
- self.slider.bufferValue = videoPlayer.bufferProgress;
- }
- - (void)showTitle:(NSString *)title fullScreenMode:(ZFFullScreenMode)fullScreenMode {
- self.titleLabel.text = title;
- self.player.orientationObserver.fullScreenMode = fullScreenMode;
- self.lockBtn.hidden = fullScreenMode == ZFFullScreenModePortrait;
- }
- /// 调节播放进度slider和当前时间更新
- - (void)sliderValueChanged:(CGFloat)value currentTimeString:(NSString *)timeString {
- self.slider.value = value;
- self.currentTimeLabel.text = timeString;
- self.slider.isdragging = YES;
- [UIView animateWithDuration:0.3 animations:^{
- self.slider.sliderBtn.transform = CGAffineTransformMakeScale(1.2, 1.2);
- }];
- }
- /// 滑杆结束滑动
- - (void)sliderChangeEnded {
- self.slider.isdragging = NO;
- [UIView animateWithDuration:0.3 animations:^{
- self.slider.sliderBtn.transform = CGAffineTransformIdentity;
- }];
- }
- #pragma mark - setter
- - (void)setFullScreenMode:(ZFFullScreenMode)fullScreenMode {
- _fullScreenMode = fullScreenMode;
- self.player.orientationObserver.fullScreenMode = fullScreenMode;
- self.lockBtn.hidden = fullScreenMode == ZFFullScreenModePortrait;
- }
- - (void)setShowCustomStatusBar:(BOOL)showCustomStatusBar {
- _showCustomStatusBar = showCustomStatusBar;
- self.statusBarView.hidden = !showCustomStatusBar;
- }
- #pragma mark - getter
- - (ZFPlayerStatusBar *)statusBarView {
- if (!_statusBarView) {
- _statusBarView = [[ZFPlayerStatusBar alloc] init];
- _statusBarView.hidden = YES;
- }
- return _statusBarView;
- }
- - (UIView *)topToolView {
- if (!_topToolView) {
- _topToolView = [[UIView alloc] init];
- UIImage *image = ZFPlayer_Image(@"ZFPlayer_top_shadow");
- _topToolView.layer.contents = (id)image.CGImage;
- }
- return _topToolView;
- }
- - (UIButton *)backBtn {
- if (!_backBtn) {
- _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_backBtn setImage:ZFPlayer_Image(@"ZFPlayer_back_full") forState:UIControlStateNormal];
- }
- return _backBtn;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.textColor = [UIColor whiteColor];
- _titleLabel.font = [UIFont systemFontOfSize:15.0];
- }
- return _titleLabel;
- }
- - (UIView *)bottomToolView {
- if (!_bottomToolView) {
- _bottomToolView = [[UIView alloc] init];
- UIImage *image = ZFPlayer_Image(@"ZFPlayer_bottom_shadow");
- _bottomToolView.layer.contents = (id)image.CGImage;
- }
- return _bottomToolView;
- }
- -(UILabel *)playOrPauseBtn_temp{
- if (!_playOrPauseBtn_temp) {
- _playOrPauseBtn_temp = [UILabel new];
- }
- return _playOrPauseBtn_temp;
- }
- - (UIButton *)playOrPauseBtn {
- if (!_playOrPauseBtn) {
- _playOrPauseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_playOrPauseBtn setImage:ZFPlayer_Image(@"ZFPlayer_play") forState:UIControlStateNormal];
- [_playOrPauseBtn setImage:ZFPlayer_Image(@"ZFPlayer_pause") forState:UIControlStateSelected];
- }
- return _playOrPauseBtn;
- }
- - (UIButton *)nextBtn {
- if (!_nextBtn) {
- _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_nextBtn setImage:ZFPlayer_Image(@"zf_next_ic") forState:UIControlStateNormal];
- [_nextBtn setImage:ZFPlayer_Image(@"zf_next_ic") forState:UIControlStateSelected];
- }
- return _nextBtn;
- }
- - (UIButton *)speedBtn {
- if (!_speedBtn) {
- _speedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_speedBtn setTitle:@"倍速" forState:UIControlStateNormal];
- _speedBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
- [_speedBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- }
- return _speedBtn;
- }
- - (UIButton *)pBtn {
- if (!_pBtn) {
- _pBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_pBtn setTitle:@"480P" forState:UIControlStateNormal];
- _pBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
- [_pBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- }
- return _pBtn;
- }
- - (UILabel *)currentTimeLabel {
- if (!_currentTimeLabel) {
- _currentTimeLabel = [[UILabel alloc] init];
- _currentTimeLabel.textColor = [UIColor whiteColor];
- _currentTimeLabel.font = [UIFont systemFontOfSize:14.0f];
- _currentTimeLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _currentTimeLabel;
- }
- - (ZFSliderView *)slider {
- if (!_slider) {
- _slider = [[ZFSliderView alloc] init];
- _slider.delegate = self;
- _slider.maximumTrackTintColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.8];
- _slider.bufferTrackTintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];
- _slider.minimumTrackTintColor = [UIColor whiteColor];
- [_slider setThumbImage:ZFPlayer_Image(@"ZFPlayer_slider") forState:UIControlStateNormal];
- _slider.sliderHeight = 2;
- }
- return _slider;
- }
- - (UILabel *)totalTimeLabel {
- if (!_totalTimeLabel) {
- _totalTimeLabel = [[UILabel alloc] init];
- _totalTimeLabel.textColor = [UIColor whiteColor];
- _totalTimeLabel.font = [UIFont systemFontOfSize:14.0f];
- _totalTimeLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _totalTimeLabel;
- }
- - (UIButton *)lockBtn {
- if (!_lockBtn) {
- _lockBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_lockBtn setImage:ZFPlayer_Image(@"ZFPlayer_unlock-nor") forState:UIControlStateNormal];
- [_lockBtn setImage:ZFPlayer_Image(@"ZFPlayer_lock-nor") forState:UIControlStateSelected];
- }
- return _lockBtn;
- }
- @end
- @interface pcell1 ()
- @property(nonatomic,strong)UILabel *lab;
- @property(nonatomic,strong)UILabel *lab2;
- @property(nonatomic,strong)UIImageView *iv;
- @end
- @implementation pcell1
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"pcell1";
- pcell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[pcell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
-
- return cell;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self creatView];
- }
- return self;
- }
- -(void)setIsSel:(BOOL)isSel{
- _isSel = isSel;
- if(isSel){
- self.lab.textColor = rgba(255, 212, 0, 1);
- self.lab2.textColor = rgba(255, 212, 0, 1);
- }else{
- self.lab.textColor = rgba(255, 255, 255, 1);
- self.lab2.textColor = rgba(255, 255, 255, 0.6);
- }
- }
- -(void)setIsNeedVip:(BOOL)isNeedVip{
- _isNeedVip = isNeedVip;
- if(isNeedVip){
- self.iv.hidden = false;
- }else{
- self.iv.hidden = true;
- }
- }
- -(void)setStrArr:(NSArray *)strArr{
- _strArr = strArr;
- self.lab.text = strArr[0];
- self.lab2.text = strArr[1];
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
-
-
- UIView *v = [UIView new];
- [self.contentView addSubview:v];
- [v mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView);
- }];
-
- UILabel *lab =[UILabel new];
- lab.text = @"1080P";
- lab.textColor = rgba(255, 255, 255, 1);
- lab.font = [UIFont systemFontOfSize:18];
- self.lab = lab;
- [v addSubview:lab];
- [lab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(v).offset(12);
- make.centerX.equalTo(v).offset(iphoneX?20:0);
- }];
-
- UIImageView *vicon = [UIImageView new];
- vicon.image = [UIImage imageNamed:@""];
- self.iv = vicon;
- [v addSubview:vicon];
- [vicon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(lab);
- make.left.equalTo(lab.mas_right).offset(4);
- make.size.mas_equalTo(CGSizeMake(25, 14));
- }];
-
-
- UILabel *lab2 =[UILabel new];
- lab2.text = @"高清 SDR";
- lab2.textColor = rgba(255, 255, 255, 0.6);
- lab2.font = [UIFont systemFontOfSize:11];
- self.lab2 = lab2;
- [v addSubview:lab2];
- [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(lab.mas_bottom).offset(12);
- make.left.equalTo(lab);
- }];
-
-
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
- [v addGestureRecognizer:gest];
- }
- -(void)tapAction{
- @zf_weakify(self)
- if(self.tapBlock){
- @zf_strongify(self)
- self.tapBlock(self.index);
- }
- }
- @end
- @interface pcell2 ()
- @property(nonatomic,strong)UILabel *lab;
- @end
- @implementation pcell2
- + (instancetype)cellWithTableView:(UITableView *)tableView{
- static NSString *identifier = @"pcell2";
- pcell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- if (cell == nil) {
- cell = [[pcell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
- }
-
- return cell;
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self creatView];
- }
- return self;
- }
- -(void)setIsSel:(BOOL)isSel{
- _isSel = isSel;
- if(isSel){
- // [self.lab setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal] ;
- self.lab.textColor = rgba(255, 212, 0, 1);
- }else{
- // [self.lab setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal] ;
- self.lab.textColor = rgba(255, 255, 255, 1);
- }
- }
- -(void)setStr:(NSString *)str{
- _str = str;
- // [self.lab setTitle:str forState:UIControlStateNormal];
- self.lab.text = str;
- }
- -(void)creatView{
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
-
- UIView *v = [UIView new];
- [self.contentView addSubview:v];
- [v mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView);
- }];
-
- UILabel *lab =[UILabel new];
- lab.text = @"2X";
- lab.textColor = rgba(255, 255, 255, 1);
- // [lab setTitle:@"2X" forState:UIControlStateNormal];
- // [lab setTitleColor:rgba(255, 255, 255, 1) forState:UIControlStateNormal] ;
- lab.font = [UIFont boldSystemFontOfSize:18];
- self.lab = lab;
- // [lab addTarget:self action:@selector(labAction) forControlEvents:UIControlEventTouchUpInside];
- [v addSubview:lab];
- [lab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(v).offset(12);
- make.centerX.equalTo(v).offset(iphoneX?20:0);
- }];
-
- UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labAction)];
- [v addGestureRecognizer:gest];
- }
- -(void)labAction{
- @zf_weakify(self)
- if(self.tapBlock){
- @zf_strongify(self)
- self.tapBlock(self.index);
- }
- }
- @end
|