//
//  NvDouyinCaptureView.m
//  SDKDemo
//
//  Created by shizhouhu on 2018/8/30.
 //
//

#import "NvDouyinCaptureView.h"
#import "NvsRecordingButton.h"
#import "NvUtils.h"
#import "UIColor+NvColor.h"
#import "Masonry.h"
#import "NvWeakTimer.h"

@interface NvDouyinCaptureView ()<NvsRecordingButtonDelegate>

@property (nonatomic, strong) UIButton *shootingBtn;     //拍摄
@property (nonatomic, strong) UIImageView *focusImageView;     //聚焦
@property (nonatomic, strong) NvWeakTimer *weakTimer;
@property (nonatomic, strong) NvGraphicBtn *propsBtn;       //道具

@end

@implementation NvDouyinCaptureView {
    
    UIButton *backBtn;
    NvGraphicBtn *cameraBtn;
    NvGraphicBtn *filterBtn;
    
    UILabel *cameraLabel;
    UILabel *flashLabel;
    UILabel *cutMusicLabel;
    UILabel *faceLabel;
    UILabel *filterLabel;
    
    UIView *_speedPanelView;
    UIButton *_speed13Btn;      // 极慢，1/3倍速按钮
    UIButton *_speed12Btn;      // 慢，1/2倍速按钮
    UIButton *_speed1Btn;       // 正常，1倍速按钮
    UIButton *_speed32Btn;      // 快，3/2倍速按钮
    UIButton *_speed3Btn;       // 极快，3倍速按钮
    float _currentSpeed;
    NSString *speedStr;//表示录制倍速
    UIImageView *selectView;
    
    NvsRecordingButton *recordingButton;
    bool isRecording;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];

    [self initProgressView];
    
    [self initBackBtn];
    [self initRightView];
    [self initFocusImageView];
    [self initBottomView];
    
    self.selectMusic = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.selectMusic setTitle:@"选音乐" forState:UIControlStateNormal];
    self.selectMusic.titleLabel.font = [NvUtils regularFontWithSize:12];
    [self.selectMusic setImage:[NvUtils imageWithName:@"NvSelectMusic"] forState:UIControlStateNormal];
    [self.selectMusic addTarget:self action:@selector(selectMusicClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.selectMusic];
    [self.selectMusic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self->backBtn.mas_centerY);
        make.width.equalTo(@(150*SCREANSCALE));
    }];
    self.selectMusic.alpha = 0.7;
    self.selectMusic.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -5);
    
    
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapFocus:)]];
    
    return self;
}
#pragma mark - 创建子视图
- (void)initProgressView {
    recordingProgress = [[NvsRecordingProgress alloc] initWithFrame:CGRectMake(12*SCREANSCALE,
                                                                               30*SCREANSCALE,
                                                                               SCREANWIDTH-24*SCREANSCALE,
                                                                               6*SCREANSCALE)];
    [self addSubview:recordingProgress];
}

- (void)initRightView{
    cameraBtn = [NvGraphicBtn buttonWithType:UIButtonTypeCustom withTitle:@"切换" withImageNormal:@"Nvdevice" withImageSelected:nil];
    [cameraBtn addTarget:self action:@selector(caremaButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:cameraBtn];
    [cameraBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(33*SCREANSCALE));
        make.right.equalTo(@(-13*SCREANSCALE));
        make.top.equalTo(@(self->recordingProgress.frame.origin.y + self->recordingProgress.frame.size.height + 27*SCREANSCALE));
    }];
    
    faceBtn = [NvGraphicBtn buttonWithType:UIButtonTypeCustom withTitle:@"美化" withImageNormal:@"Nvbeauty" withImageSelected:nil];
    [faceBtn addTarget:self action:@selector(faceBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:faceBtn];
    [faceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(33*SCREANSCALE));
        make.right.equalTo(@(-13*SCREANSCALE));
        make.top.equalTo(self->cameraBtn.mas_bottom).offset(12*SCREANSCALE);
    }];
    
    filterBtn = [NvGraphicBtn buttonWithType:UIButtonTypeCustom withTitle:@"滤镜" withImageNormal:@"Nvfilter" withImageSelected:nil];
    [filterBtn addTarget:self action:@selector(filterBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [filterBtn.layer setBorderWidth:.0];
    [filterBtn.layer setBorderColor:[UIColor whiteColor].CGColor];
    [self addSubview:filterBtn];
    [filterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(33*SCREANSCALE));
        make.right.equalTo(@(-13*SCREANSCALE));
        make.top.equalTo(self->faceBtn.mas_bottom).offset(12*SCREANSCALE);
    }];
    
    self.countDownBtn = [NvGraphicBtn buttonWithType:UIButtonTypeCustom withTitle:@"倒计时" withImageNormal:@"NvcountDown" withImageSelected:nil];
    [self.countDownBtn addTarget:self action:@selector(countDownBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.countDownBtn];
    [self.countDownBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(33*SCREANSCALE));
        make.right.equalTo(@(-13*SCREANSCALE));
        make.top.equalTo(self->filterBtn.mas_bottom).offset(12*SCREANSCALE);
    }];

    self.propsBtn = [NvGraphicBtn buttonWithType:UIButtonTypeCustom withTitle:@"道具" withImageNormal:@"Nvprops" withImageSelected:nil];
    [self.propsBtn addTarget:self action:@selector(propsBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.propsBtn];
    [self.propsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(33*SCREANSCALE));
        make.right.equalTo(@(-13*SCREANSCALE));
        make.top.equalTo(self.countDownBtn.mas_bottom).offset(12*SCREANSCALE);
    }];
}

- (void)initBottomView {
    self.shootingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.shootingBtn setImage:[NvUtils imageWithName:@"NvDouyinRecording"] forState:UIControlStateNormal];
    [self.shootingBtn setImage:[NvUtils imageWithName:@"Nvsuspended"] forState:UIControlStateSelected];
    [self.shootingBtn addTarget:self action:@selector(shootingBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.shootingBtn];
    [self.shootingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.mas_safeAreaLayoutGuideBottom).offset(- 20 * SCREANSCALE);
        } else {
            // Fallback on earlier versions
            make.bottom.equalTo(self.mas_bottom).offset(- 20 * SCREANSCALE);
        }
        make.centerX.equalTo(self.mas_centerX);
        make.width.offset(64 * SCREANSCALE);
        make.height.offset(64 * SCREANSCALE);
    }];
    deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(25*SCREANSCALE,
                                                           SCREANHEIGHT - 95*SCREANSCALE,
                                                           44*SCREANSCALE,
                                                           30*SCREANSCALE)];
    [deleteBtn setBackgroundImage:[NvUtils imageWithName:@"Nvdelete"] forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteBtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:deleteBtn];
    deleteBtn.enabled = NO;
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.shootingBtn.mas_left).offset(-28*SCREANSCALE);
        make.centerY.equalTo(self.shootingBtn.mas_centerY);
        make.width.offset(44 * SCREANSCALE);
        make.height.offset(30 * SCREANSCALE);
    }];
    nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREANWIDTH - 69*SCREANSCALE,
                                                         SCREANHEIGHT - 95*SCREANSCALE,
                                                         44*SCREANSCALE,
                                                         44*SCREANSCALE)];
    [nextBtn setBackgroundImage:[NvUtils imageWithName:@"Nvfinish"] forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(nextBtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:nextBtn];
    nextBtn.enabled = NO;
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shootingBtn.mas_right).offset(28*SCREANSCALE);
        make.centerY.equalTo(self.shootingBtn.mas_centerY);
        make.width.offset(44 * SCREANSCALE);
        make.height.offset(44 * SCREANSCALE);
    }];
    
    self.album = [NvGraphicBtn buttonWithType:UIButtonTypeCustom withTitle:@"相册" withImageNormal:@"NvDouyinAlbum" withImageSelected:nil];
    [self.album addTarget:self action:@selector(albumClick) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:self.album];
    [self.album mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shootingBtn.mas_right).offset(28*SCREANSCALE);
        make.centerY.equalTo(self.shootingBtn.mas_centerY);
        make.width.offset(33 * SCREANSCALE);
        make.height.offset(47 * SCREANSCALE);
    }];
    
    _currentSpeed = 1;
    int buttonWidth = 56.6*SCREANSCALE;
    int buttonHeight = 40*SCREANSCALE;
    int poxY = SCREANHEIGHT - 170*SCREANSCALE;
    _speedPanelView = [[UIView alloc] initWithFrame:CGRectMake(46*SCREANSCALE, poxY, buttonWidth*5, buttonHeight)];
    _speedPanelView.layer.cornerRadius = 2;
    _speedPanelView.layer.masksToBounds = YES;
    _speedPanelView.backgroundColor = [UIColor nv_colorWithHexARGB:@"#4D000000"];
    [self addSubview:_speedPanelView];
    
    [_speedPanelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(46*SCREANSCALE));
        make.bottom.equalTo(self.shootingBtn.mas_top).offset(-18*SCREANSCALE);
        make.width.equalTo(@(5*buttonWidth));
        make.height.equalTo(@(buttonHeight));
    }];
    
    _speed13Btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonWidth, buttonHeight)];
    _speed12Btn = [[UIButton alloc] initWithFrame:CGRectMake(buttonWidth, 0, buttonWidth, buttonHeight)];
    _speed1Btn = [[UIButton alloc] initWithFrame:CGRectMake(2*buttonWidth, 0, buttonWidth, buttonHeight)];
    _speed32Btn = [[UIButton alloc] initWithFrame:CGRectMake(3*buttonWidth, 0, buttonWidth, buttonHeight)];
    _speed3Btn = [[UIButton alloc] initWithFrame:CGRectMake(4*buttonWidth, 0, buttonWidth, buttonHeight)];
    
    _speed13Btn.layer.cornerRadius = 2;
    _speed13Btn.layer.masksToBounds = YES;
    _speed12Btn.layer.cornerRadius = 2;
    _speed12Btn.layer.masksToBounds = YES;
    _speed1Btn.layer.cornerRadius = 2;
    _speed1Btn.layer.masksToBounds = YES;
    _speed32Btn.layer.cornerRadius = 2;
    _speed32Btn.layer.masksToBounds = YES;
    _speed3Btn.layer.cornerRadius = 2;
    _speed3Btn.layer.masksToBounds = YES;
    
    [self resetSpeedBtnColor];
    [_speed1Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FF4D4F51"] forState:UIControlStateNormal];
    _speed1Btn.backgroundColor = [UIColor nv_colorWithHexARGB:@"#FFD8D8D8"];
    
    [_speed13Btn setTitle:@"极慢" forState:UIControlStateNormal];
    [_speed12Btn setTitle:@"慢" forState:UIControlStateNormal];
    [_speed1Btn setTitle:@"标准" forState:UIControlStateNormal];
    [_speed32Btn setTitle:@"快" forState:UIControlStateNormal];
    [_speed3Btn setTitle:@"极快" forState:UIControlStateNormal];
    
    _speed13Btn.titleLabel.font = [NvUtils fontWithSize:12];
    _speed12Btn.titleLabel.font = [NvUtils fontWithSize:12];
    _speed1Btn.titleLabel.font = [NvUtils fontWithSize:12];
    _speed32Btn.titleLabel.font = [NvUtils fontWithSize:12];
    _speed3Btn.titleLabel.font = [NvUtils fontWithSize:12];
    
    selectView = [[UIImageView alloc] initWithFrame:CGRectMake(56.6*5/2*SCREANSCALE-5*SCREANSCALE, 32*SCREANSCALE, 10*SCREANSCALE, 8*SCREANSCALE)];
    selectView.image = [NvUtils imageWithName:@"Triangle"];
    [_speedPanelView addSubview:selectView];
    
    [_speed13Btn addTarget:self action:@selector(speed13BtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [_speed12Btn addTarget:self action:@selector(speed12BtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [_speed1Btn addTarget:self action:@selector(speed1BtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [_speed32Btn addTarget:self action:@selector(speed32BtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [_speed3Btn addTarget:self action:@selector(speed3BtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    
    [_speedPanelView addSubview:_speed13Btn];
    [_speedPanelView addSubview:_speed12Btn];
    [_speedPanelView addSubview:_speed1Btn];
    [_speedPanelView addSubview:_speed32Btn];
    [_speedPanelView addSubview:_speed3Btn];
    
    
    
}

- (void)initFocusImageView {
    self.focusImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50*SCREANSCALE, 50*SCREANSCALE)];
    self.focusImageView.image = [NvUtils imageWithName:@"NvsCaptureFocus"];
    self.focusImageView.center = self.center;
    [self addSubview:self.focusImageView];
    self.focusImageView.hidden = YES;
}

#pragma mark -按钮点击事件
- (void)countDownBtnClick {
    if ([self.delegate respondsToSelector:@selector(countDownBtnClick)]) {
        [self.delegate countDownBtnClick];
    }
}

- (void)selectMusicClick {
    if ([self.delegate respondsToSelector:@selector(selectMusicClick)]) {
        [self.delegate selectMusicClick];
    }
}

- (void)propsBtnClicked {
    if ([self.delegate respondsToSelector:@selector(propsBtnClicked)]) {
        [self.delegate propsBtnClicked];
    }
}

- (void)faceBtnClicked {
    if ([self.delegate respondsToSelector:@selector(faceBtnClicked)]) {
        [self.delegate faceBtnClicked];
    }
}

- (void)cutMusicClicked {
    if ([self.delegate respondsToSelector:@selector(cutMusicClicked)]) {
        [self.delegate cutMusicClicked];
    }
}

- (void)caremaButtonClicked {
    if ([self.delegate respondsToSelector:@selector(caremaButtonClicked)]) {
        [self.delegate caremaButtonClicked];
    }
}

- (void)initBackBtn {
    backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(13*SCREANSCALE,self->recordingProgress.frame.origin.y + self->recordingProgress.frame.size.height + 27*SCREANSCALE,33*SCREANSCALE,33*SCREANSCALE);
    [backBtn addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[NvUtils imageWithName:@"Nvback"] forState:UIControlStateNormal];
    [self addSubview:backBtn];
}

- (void)backButtonClicked {
    if ([self.delegate respondsToSelector:@selector(backButtonClicked)]) {
        [self.delegate backButtonClicked];
    }
}

- (void)albumClick {
    if ([self.delegate respondsToSelector:@selector(albumClick)]) {
        [self.delegate albumClick];
    }
}

- (void)speed13BtnClicked {
    _currentSpeed = 0.5;
    [self resetSpeedBtnColor];
    //    _speed13Btn.backgroundColor = [UIColor nv_colorWithHexString:NV_CAPTURE_SPEEDBAR_COLOR];
    [_speed13Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FF4D4F51"] forState:UIControlStateNormal];
    _speed13Btn.backgroundColor = [UIColor nv_colorWithHexARGB:@"#FFD8D8D8"];
    speedStr = @"0.5";
    selectView.center = CGPointMake(_speed13Btn.center.x, selectView.center.y);
    if ([self.delegate respondsToSelector:@selector(douyinCaptureView:selectSpeed:)]) {
        [self.delegate douyinCaptureView:self selectSpeed:_currentSpeed];
    }
}

- (void)speed12BtnClicked {
    _currentSpeed = 0.75;
    [self resetSpeedBtnColor];
    //    _speed12Btn.backgroundColor = [UIColor nv_colorWithHexString:NV_CAPTURE_SPEEDBAR_COLOR];
    [_speed12Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FF4D4F51"] forState:UIControlStateNormal];
    _speed12Btn.backgroundColor = [UIColor nv_colorWithHexARGB:@"#FFD8D8D8"];
    speedStr = @"0.75";
    selectView.center = CGPointMake(_speed12Btn.center.x, selectView.center.y);
    if ([self.delegate respondsToSelector:@selector(douyinCaptureView:selectSpeed:)]) {
        [self.delegate douyinCaptureView:self selectSpeed:_currentSpeed];
    }
}

- (void)speed1BtnClicked {
    _currentSpeed = 1;
    [self resetSpeedBtnColor];
    //    _speed1Btn.backgroundColor = [UIColor nv_colorWithHexString:NV_CAPTURE_SPEEDBAR_COLOR];
    [_speed1Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FF4D4F51"] forState:UIControlStateNormal];
    _speed1Btn.backgroundColor = [UIColor nv_colorWithHexARGB:@"#FFD8D8D8"];
    speedStr = @"1";
    selectView.center = CGPointMake(_speed1Btn.center.x, selectView.center.y);
    if ([self.delegate respondsToSelector:@selector(douyinCaptureView:selectSpeed:)]) {
        [self.delegate douyinCaptureView:self selectSpeed:_currentSpeed];
    }
}

- (void)speed32BtnClicked {
    _currentSpeed = 1.5;
    [self resetSpeedBtnColor];
    //    _speed32Btn.backgroundColor = [UIColor nv_colorWithHexString:NV_CAPTURE_SPEEDBAR_COLOR];
    [_speed32Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FF4D4F51"] forState:UIControlStateNormal];
    _speed32Btn.backgroundColor = [UIColor nv_colorWithHexARGB:@"#FFD8D8D8"];
    speedStr = @"1.5";
    selectView.center = CGPointMake(_speed32Btn.center.x, selectView.center.y);
    if ([self.delegate respondsToSelector:@selector(douyinCaptureView:selectSpeed:)]) {
        [self.delegate douyinCaptureView:self selectSpeed:_currentSpeed];
    }
}

- (void)speed3BtnClicked {
    _currentSpeed = 2;
    [self resetSpeedBtnColor];
    //    _speed3Btn.backgroundColor = [UIColor nv_colorWithHexString:NV_CAPTURE_SPEEDBAR_COLOR];
    [_speed3Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FF4D4F51"] forState:UIControlStateNormal];
    _speed3Btn.backgroundColor = [UIColor nv_colorWithHexARGB:@"#FFD8D8D8"];
    speedStr = @"2";
    selectView.center = CGPointMake(_speed3Btn.center.x, selectView.center.y);
    if ([self.delegate respondsToSelector:@selector(douyinCaptureView:selectSpeed:)]) {
        [self.delegate douyinCaptureView:self selectSpeed:_currentSpeed];
    }
}

- (void)deleteBtnClicked {
    
    [recordingProgress prepareDelete];
    
    [recordingProgress deleteProgress];
    
    int64_t recordDuration = [recordingProgress getValue];
    if (recordDuration < [recordingProgress getMinRecordTime]) {
        nextBtn.enabled = NO;
    }
    if ([recordingProgress getCount]==0) {
        deleteBtn.enabled = NO;
        nextBtn.enabled = NO;
    }
    if (recordingProgress.value<15000000) {
        self.countDownBtn.enabled = YES;
    }
    if ([self.delegate respondsToSelector:@selector(deleteBtnClicked)]) {
        [self.delegate deleteBtnClicked];
    }
}

- (void)nextBtnClicked {
    if ([self.delegate respondsToSelector:@selector(nextBtnClicked)]) {
        [self.delegate nextBtnClicked];
    }
}


- (void)filterBtnClicked {
    if ([self.delegate respondsToSelector:@selector(filterBtnClicked)]) {
        [self.delegate filterBtnClicked];
    }
}

- (void)shootingBtnClick:(UIButton *)button {
    if (isRecording) {
        [self toutchEnd];
        button.selected = NO;
        button.userInteractionEnabled = YES;
        button.alpha = 1;
    } else {
        //录制大于15秒不要再进行录制
        if ([recordingProgress value] >= TotalTime) {
            return;
        }
        button.selected = YES;
        button.userInteractionEnabled = NO;
        button.alpha = 0.6;
        [self toutchBegin];
        
    }
    
}

#pragma mark 点击livewindow
- (void)tapFocus:(UITapGestureRecognizer *)tap {
    CGPoint point = [tap locationInView:self];
    //是否支持聚焦
    if ([self.delegate respondsToSelector:@selector(supportAutoFocus)]) {
        if ([self.delegate supportAutoFocus]) {
            [self showFocusToPoint:point];
        }
    }
    //是否支持聚焦
    if ([self.delegate respondsToSelector:@selector(supportAutoExposure)]) {
        if ([self.delegate supportAutoExposure]) {
            if ([self.delegate respondsToSelector:@selector(exposureOnPoint:)]) {
                [self.delegate exposureOnPoint:point];
            }
        }
    }
}

- (void)showFocusToPoint:(CGPoint)point {
    [self.weakTimer invalidate];
    self.weakTimer = [NvWeakTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(hiddenFocusImage) userInfo:nil repeats:NO dispatchQueue:dispatch_get_main_queue()];
    self.focusImageView.frame = CGRectMake(0, 0, 70*SCREANSCALE, 70*SCREANSCALE);
    self.focusImageView.center = point;
    [UIView animateWithDuration:0.3 animations:^{
        self.focusImageView.frame = CGRectMake(0, 0, 50*SCREANSCALE, 50*SCREANSCALE);
        self.focusImageView.center = point;
    } completion:NULL];
    self.focusImageView.hidden = NO;
    if ([self.delegate respondsToSelector:@selector(focusOnPoint:)]) {
        [self.delegate focusOnPoint:point];
    }
}

- (void)hiddenFocusImage {
    self.focusImageView.hidden = YES;
}

- (void)resetSpeedBtnColor {
    _speed13Btn.backgroundColor = [UIColor clearColor];
    _speed12Btn.backgroundColor = [UIColor clearColor];
    _speed3Btn.backgroundColor = [UIColor clearColor];
    _speed32Btn.backgroundColor = [UIColor clearColor];
    _speed1Btn.backgroundColor = [UIColor clearColor];
    [_speed13Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FFEAEBEB"] forState:UIControlStateNormal];
    [_speed12Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FFEAEBEB"] forState:UIControlStateNormal];
    [_speed1Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FFEAEBEB"] forState:UIControlStateNormal];
    [_speed32Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FFEAEBEB"] forState:UIControlStateNormal];
    [_speed3Btn setTitleColor:[UIColor nv_colorWithHexARGB:@"#FFEAEBEB"] forState:UIControlStateNormal];
}

- (void)countDownStartRecording {
    [self shootingBtnClick:self.shootingBtn];
}

- (void)enableRecordingButton {
    self.shootingBtn.userInteractionEnabled = YES;
    self.shootingBtn.alpha = 1;
}

- (void)toutchBegin {
    isRecording = YES;
    if ([self.delegate respondsToSelector:@selector(startRecord)]) {
        [recordingProgress beginProgress];
        [self.delegate startRecord];
    }
}

- (void)toutchEnd {
    isRecording = NO;
    if ([self.delegate respondsToSelector:@selector(endRecord)]) {
        [recordingProgress endProgress];
        [self.delegate endRecord];
    }
}

- (void)recordingEnd {
    [self toutchEnd];
    self.shootingBtn.selected = NO;
    self.shootingBtn.userInteractionEnabled = YES;
    self.shootingBtn.alpha = 1;
    nextBtn.enabled = YES;
    deleteBtn.enabled = YES;
}

- (void)updateCaptureClipDuration:(int64_t)duration {
    if (!isRecording) {
        return;
    }
    
    [recordingProgress currentValue: [recordingProgress getValue] + duration/_currentSpeed];
    if ([recordingProgress getValue] + duration/_currentSpeed > [recordingProgress getMinRecordTime]) {
        nextBtn.enabled = YES;
    } else {
        nextBtn.enabled = NO;
    }
    deleteBtn.enabled = YES;

}

- (void)hiddenAllButtonExceptRecordingButton {
    backBtn.hidden = YES;
    cameraBtn.hidden = YES;
    flashBtn.hidden = YES;
//    cutMusicBtn.hidden = YES;
    faceBtn.hidden = YES;
    filterBtn.hidden = YES;
    _speedPanelView.hidden = YES;
    deleteBtn.hidden = YES;
    nextBtn.hidden = YES;
    self.countDownBtn.hidden = YES;
    self.propsBtn.hidden = YES;
    self.selectMusic.hidden = YES;
}

- (void)showAllButton {
    backBtn.hidden = NO;
    cameraBtn.hidden = NO;
    flashBtn.hidden = NO;
//    cutMusicBtn.hidden = NO;
    faceBtn.hidden = NO;
    filterBtn.hidden = NO;
    _speedPanelView.hidden = NO;
    deleteBtn.hidden = NO;
    nextBtn.hidden = NO;
    self.countDownBtn.hidden = NO;
    self.propsBtn.hidden = NO;
    self.selectMusic.hidden = NO;
}

@end
