// // BuguLive // // Created by xgh on 2017/8/24. // Copyright © 2017年 xfg. All rights reserved. // #import "VoiceLiveCustomView.h" #import #import #import #import #import "BGTLiveBeautyView.h" #import "JCTagListView.h" //#import "RoomPasswordView.h" @interface VoiceLiveCustomView() { AVCaptureSession *_captureSession; AVCaptureVideoPreviewLayer *_customLayer;//自定义layer展示层 } @property (nonatomic, retain) AVCaptureSession *captureSession; @property (nonatomic, strong) AVCaptureVideoPreviewLayer *customLayer; @property(nonatomic, strong) UIView *lineView; @property (nonatomic, strong) TXLivePush *pusher; //@property (nonatomic, strong) TXLivePush *pusher; @property (nonatomic, strong) UIImageView *preViewContainer; @property (nonatomic, strong) TXLivePushConfig *txLivePushonfig; @property (nonatomic, strong) TXLivePlayer *txLivePlayer; @property (nonatomic, strong) TXLivePlayConfig *txLivePlayConfig; @property(nonatomic, strong) UILabel *titleL; @property(nonatomic, strong) UIView *buttonLineView; @property(nonatomic, strong) JCTagListView *tagListView; @property(nonatomic, strong) JCTagListView *tagListViewPeople; @property(nonatomic, strong) UIView *s2; @property(nonatomic, strong) UIView *s3; //@property(nonatomic, strong) RoomPasswordView *passwordView; @end @implementation VoiceLiveCustomView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // self.topView = [[VoiceLiveTopView alloc]initWithFrame:CGRectMake(0, 10, self.width, 0.01)]; // self.topView.delegate = self; // // [self initCapture]; //// [self backGroundImageview]; // [self addSubview:self.topView]; self.people_count = @"5"; UIView *middleView = [[UIView alloc]initWithFrame:CGRectMake(0, kRealValue(55) + kStatusBarHeight, kScreenW, kScreenH - self.topView.height)]; // middleView.backgroundColor = [[UIColor colorWithHexString:@"#000000"] colorWithAlphaComponent:0.15]; self.middleView = middleView; [self addSubview:middleView]; UIButton *back = [[UIButton alloc] initWithFrame:CGRectMake(kScreenW - 10 - kRealValue(35),kStatusBarHeight + kRealValue(10), kRealValue(35), kRealValue(35))]; [back setImage:[UIImage imageNamed:@"publishlive_close"] forState:UIControlStateNormal]; [back addTarget:self action:@selector(handleBackEvent) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:back]; _liveBtn = [[QMUIButton alloc] init]; _liveBtn.spacingBetweenImageAndTitle = kRealValue(5); // [_liveBtn setImage:[UIImage imageNamed:@"habibi_live2"] forState:UIControlStateNormal]; [_liveBtn setTitle:@"直播" forState:UIControlStateNormal]; _liveBtn.imagePosition = QMUIButtonImagePositionTop; _liveBtn.titleLabel.font = [UIFont systemFontOfSize:16]; [_liveBtn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal]; [self addSubview:_liveBtn]; [_liveBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.startButton.mas_bottom).offset(kRealValue(20)); make.height.equalTo(@(33+10)); make.width.equalTo(@(80)); make.centerX.equalTo(self).offset(-kRealValue(50)); make.centerY.mas_equalTo(back); }]; _voiceBtn = [[QMUIButton alloc] init]; _voiceBtn.spacingBetweenImageAndTitle = kRealValue(5); _voiceBtn.titleLabel.font = [UIFont systemFontOfSize:16]; // [_voiceBtn setImage:[UIImage imageNamed:@"chatparty222"] forState:UIControlStateNormal]; [_voiceBtn setTitle:@"房间" forState:UIControlStateNormal]; _voiceBtn.imagePosition = QMUIButtonImagePositionTop; [_voiceBtn setTitleColor:kWhiteColor forState:UIControlStateNormal]; [self addSubview:_voiceBtn]; [_voiceBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.startButton.mas_bottom).offset(kRealValue(20)); make.height.equalTo(@(33+10)); make.width.equalTo(@(120)); make.centerX.equalTo(self).offset(kRealValue(50)); make.centerY.mas_equalTo(back); }]; [self setNeedsLayout]; [self layoutIfNeeded]; dispatch_async(dispatch_get_main_queue(), ^{ [self addSubview:self.lineView]; }); UIView *s1 = [[UIView alloc] initWithFrame:CGRectMake(kRealValue(15), 0, self.width-kRealValue(30), kRealValue(202))]; [middleView addSubview:s1]; ViewRadius(s1, kRealValue(10)); s1.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2]; _coverBgView = [[UIView alloc] initWithFrame:CGRectMake((s1.width - kRealValue(140))/2, kRealValue(47), kRealValue(140), kRealValue(140))]; self.coverBgView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2]; ViewRadius(self.coverBgView, kRealValue(10)); [s1 addSubview:self.coverBgView]; self.selectedImageView = [[UIImageView alloc]initWithFrame:CGRectMake((self.coverBgView.width - kRealValue(47))/2, kRealValue(35), kRealValue(47), kRealValue(40))]; // ViewRadius(self.selectedImageView, kRealValue(5)); // self.selectedImageView.centerX = kScreenW / 2; self.selectedImageView.image = [UIImage imageNamed:@"pl_publishlive_cover"]; [self.coverBgView addSubview:self.selectedImageView]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = self.coverBgView.bounds; [button addTarget:self action:@selector(selectedImageViewAction:) forControlEvents:UIControlEventTouchUpInside]; self.selectedImageView.userInteractionEnabled = YES; [self.selectedImageView addSubview:button]; UIImageView * coverBottomDarkImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.coverBgView.height - kRealValue(50), self.coverBgView.width, kRealValue(50))]; coverBottomDarkImgV.image = [UIImage imageNamed:@"live_preview_cover_dark_bg"]; [self.coverBgView addSubview:coverBottomDarkImgV]; UILabel * selectCoverImgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kRealValue(22), coverBottomDarkImgV.width, 15)]; selectCoverImgLabel.text = ASLocalizedString(@"选择封面"); selectCoverImgLabel.font = [UIFont systemFontOfSize:14]; selectCoverImgLabel.textColor = UIColor.whiteColor; selectCoverImgLabel.textAlignment = NSTextAlignmentCenter; [coverBottomDarkImgV addSubview:selectCoverImgLabel]; self.textView =[[QMUITextView alloc] initWithFrame:CGRectMake(kRealValue(15), 0, self.width - kRealValue(60),kRealValue(45))]; self.textView.backgroundColor =[UIColor clearColor]; self.textView.keyboardType =UIKeyboardTypeDefault; self.textView.layoutManager.allowsNonContiguousLayout =NO; self.textView.textAlignment =NSTextAlignmentCenter; self.textView.textColor = RGBA(255, 255, 255, 1); self.textView.placeholderColor = RGBA(255, 255, 255, 1); self.textView.placeholder = ASLocalizedString(@"请输入直播标题"); self.textView.font =[UIFont systemFontOfSize:15]; // self.textView.text = ASLocalizedString(@"请输入直播标题"); // self.textView.qmui_borderPosition = QMUIViewBorderPositionBottom; // self.textView.qmui_borderWidth = kRealValue(0.5); // self.textView.qmui_borderColor = RGBA(255, 255, 255, 0.4); // self.textView.hidden = YES; self.textView.delegate = self; self.autoresizingMask =UIViewAutoresizingFlexibleHeight; [s1 addSubview:self.textView]; //房间分类 self.s2 = [[UIView alloc] initWithFrame:CGRectMake(s1.left, s1.bottom + kRealValue(10), self.width-kRealValue(30), kRealValue(120))]; [middleView addSubview:self.s2]; ViewRadius(self.s2, kRealValue(10)); self.s2.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2]; UILabel *labRoomTag = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))]; labRoomTag.text = ASLocalizedString(@"房间分类"); labRoomTag.font = [UIFont systemFontOfSize:15]; labRoomTag.textColor = kWhiteColor; [self.s2 addSubview:labRoomTag]; self.tagListView = [[JCTagListView alloc] initWithFrame:CGRectMake(kRealValue(20), kRealValue(40), self.width - kRealValue(30), 100)]; [self.s2 addSubview:self.tagListView]; self.tagListView.supportSelected = YES; self.tagListView.supportMultipleSelected = NO; self.tagListView.tagSelectedBackgroundColor = UIColor.whiteColor; self.tagListView.tagBackgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4]; self.tagListView.tagSelectedTextColor = [UIColor redColor]; self.tagListView.tagTextColor = kWhiteColor; self.tagListView.tagCornerRadius = kRealValue(10); self.tagListView.tagSelectedBorderColor = kClearColor; self.tagListView.tagBorderColor = kClearColor; NSMutableArray *video_classified = [NSMutableArray array]; for (int i = 0; i < self.BuguLive.appModel.video_classified.count; i++) { VideoClassifiedModel * model = self.BuguLive.appModel.video_classified[i]; [video_classified addObject:model.title]; } self.tagListView.tags = video_classified; self.cid = [NSString stringWithFormat:@"%ld",(long)((VideoClassifiedModel *)self.BuguLive.appModel.video_classified.firstObject).classified_id]; self.tagListView.selectedTags = @[video_classified.firstObject]; [self.tagListView didSelectItem:^(NSInteger index) { VideoClassifiedModel * model = self.BuguLive.appModel.video_classified[index]; self.cid = [NSString stringWithFormat:@"%ld",(long)model.classified_id]; NSLog(@"%@", @(index)); }]; [self.tagListView reloadData]; self.tagListView.height = self.tagListView.contentHeight; self.s2.height = CGRectGetMaxY(self.tagListView.frame) + kRealValue(10); if(self.s2.height < kRealValue(60)) { // self.s2.height = kRealValue(60); } // 创建s3 view self.s3 = [[UIView alloc] initWithFrame:CGRectMake(self.s2.left, self.s2.bottom + kRealValue(10), self.width-kRealValue(20), 120)]; [self.middleView addSubview:self.s3]; ViewRadius(self.s3, kRealValue(5)); self.s3.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2]; // _passwordView = [RoomPasswordView getView]; // [self addSubview:_passwordView]; // [_passwordView mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self); // make.right.equalTo(self); // make.top.equalTo(self.s3.mas_bottom).offset(20); // make.height.equalTo(@40); // }]; // 添加标题 UILabel *labPeople = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))]; labPeople.text = ASLocalizedString(@"房间麦位"); labPeople.font = [UIFont systemFontOfSize:15]; labPeople.textColor = UIColor.whiteColor; [self.s3 addSubview:labPeople]; // 创建tagListView self.tagListViewPeople = [[JCTagListView alloc] initWithFrame:CGRectMake(kRealValue(20), kRealValue(40), self.width - kRealValue(20), 0)]; [self.s3 addSubview:self.tagListViewPeople]; self.tagListViewPeople.supportSelected = YES; self.tagListViewPeople.supportMultipleSelected = NO; self.tagListViewPeople.tagSelectedBackgroundColor = UIColor.whiteColor; self.tagListViewPeople.tagBackgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4]; self.tagListViewPeople.tagSelectedTextColor = [UIColor redColor]; self.tagListViewPeople.tagTextColor = kWhiteColor; self.tagListViewPeople.tagCornerRadius = kRealValue(10); self.tagListViewPeople.tagSelectedBorderColor = kClearColor; self.tagListViewPeople.tagBorderColor = kClearColor; self.tagListViewPeople.tags = @[ASLocalizedString(@"5人房"), ASLocalizedString(@"10人房"),ASLocalizedString(@"15人房"),ASLocalizedString(@"20人房")]; [self.tagListViewPeople didSelectItem:^(NSInteger index) { NSLog(@"%@", @(index)); if(index == 0) { self.people_count = @"5"; } else if(index == 1) { self.people_count = @"10"; } else if(index == 2) { self.people_count = @"15"; } else { self.people_count = @"20"; } }]; [self.tagListViewPeople reloadData]; self.tagListViewPeople.height = self.tagListViewPeople.contentHeight; self.s3.height = CGRectGetMaxY(self.tagListViewPeople.frame) + kRealValue(10); // if(self.s3.height < kRealValue(120)) // { // self.s3.height = kRealValue(120); // } //房间密码 UIView * passwordView = [[UIView alloc] initWithFrame:CGRectMake(s1.left, self.s3.bottom + kRealValue(10), self.width-kRealValue(30), kRealValue(60))]; [middleView addSubview:passwordView]; ViewRadius(passwordView, kRealValue(10)); passwordView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2]; UILabel *passwordTitle = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))]; passwordTitle.text = ASLocalizedString(@"房间密码"); passwordTitle.font = [UIFont systemFontOfSize:15]; passwordTitle.textColor = kWhiteColor; [passwordView addSubview:passwordTitle]; UIView * passwordBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(10, passwordView.height -9, passwordView.width - 20, 1)]; passwordBottomLineView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4]; [passwordView addSubview:passwordBottomLineView]; _passWordButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self.passWordButton setImage:[UIImage imageNamed:@"live_switch_off"] forState:UIControlStateNormal]; [self.passWordButton setImage:[UIImage imageNamed:@"live_switch_on"] forState:UIControlStateSelected]; self.passWordButton.frame = CGRectMake(passwordView.width - 10 - 30, 10, 30, 14); [passwordView addSubview:self.passWordButton]; [self.passWordButton addTarget:self action:@selector(passWordButtonClick) forControlEvents:UIControlEventTouchUpInside]; _passTF = [[UITextField alloc] initWithFrame:CGRectMake(10, passwordTitle.bottom + 5, passwordView.width - 20, 20)]; self.passTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入4-8位数字密码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#999999"]}]; self.passTF.textColor = UIColor.whiteColor; self.passTF.font = [UIFont systemFontOfSize:12]; self.passTF.keyboardType = UIKeyboardTypeNumberPad; [passwordView addSubview:_passTF]; //进入门票 UIView * ticketView = [[UIView alloc] initWithFrame:CGRectMake(s1.left, passwordView.bottom + kRealValue(10), self.width-kRealValue(30), kRealValue(60))]; [middleView addSubview:ticketView]; ViewRadius(ticketView, kRealValue(10)); ticketView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.2]; UILabel *ticketTitle = [[UILabel alloc] initWithFrame:CGRectMake(kRealValue(15), kRealValue(10.5), 100, kRealValue(16))]; ticketTitle.text = ASLocalizedString(@"进入门票"); ticketTitle.font = [UIFont systemFontOfSize:15]; ticketTitle.textColor = kWhiteColor; [ticketView addSubview:ticketTitle]; UIView * ticketBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(10, ticketView.height -9, ticketView.width - 20, 1)]; ticketBottomLineView.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4]; [ticketView addSubview:ticketBottomLineView]; _enterTicketButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self.enterTicketButton setImage:[UIImage imageNamed:@"live_switch_off"] forState:UIControlStateNormal]; [self.enterTicketButton setImage:[UIImage imageNamed:@"live_switch_on"] forState:UIControlStateSelected]; self.enterTicketButton.frame = CGRectMake(ticketView.width - 10 - 30, 10, 30, 14); [ticketView addSubview:self.enterTicketButton]; [self.enterTicketButton addTarget:self action:@selector(enterTicketButtonClick) forControlEvents:UIControlEventTouchUpInside]; _ticketTF = [[UITextField alloc] initWithFrame:CGRectMake(10, ticketTitle.bottom + 5, ticketView.width - 20, 20)]; self.ticketTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"最低设置为1钻石" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#999999"]}]; self.ticketTF.textColor = UIColor.whiteColor; self.ticketTF.font = [UIFont systemFontOfSize:12]; self.ticketTF.keyboardType = UIKeyboardTypeNumberPad; [ticketView addSubview:self.ticketTF]; UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(self.width / 2 - 50, self.selectedImageView.bottom + 15, 100, 20)]; lab.text = ASLocalizedString(@"选择封面"); lab.textColor = kWhiteColor; lab.font = [UIFont systemFontOfSize:15]; lab.textAlignment = NSTextAlignmentCenter; lab.hidden = YES; self.titleL = lab; [self.middleView addSubview:lab]; self.beautyBtn = [QMUIButton buttonWithType:UIButtonTypeCustom]; [self.beautyBtn setImage:[UIImage imageNamed:@"ic_live_beauty"] forState:UIControlStateNormal]; [self.beautyBtn setTitle:ASLocalizedString(@"美颜")forState:UIControlStateNormal]; [self.beautyBtn setTitleColor:kWhiteColor forState:UIControlStateNormal]; self.beautyBtn.imagePosition = QMUIButtonImagePositionTop; self.beautyBtn.spacingBetweenImageAndTitle = 2; self.beautyBtn.titleLabel.font = [UIFont systemFontOfSize:14]; self.beautyBtn.frame = CGRectMake(kRealValue(40) , self.height - kRealValue(120), kRealValue(40), kRealValue(50)); self.beautyBtn.hidden = YES; [self.beautyBtn addTarget:self action:@selector(clickBeauty:) forControlEvents:UIControlEventTouchUpInside]; NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key; self.beautyBtn.hidden = [BGUtils isBlankString:key]; [self addSubview:self.beautyBtn]; self.beautyBtn.hidden = YES; // self.textView.top = lab.bottom + 30; self.startButton = [UIButton buttonWithType:UIButtonTypeCustom]; // self.startButton.frame = CGRectMake(self.beautyBtn.right + kRealValue(25), self.height - 120, kRealValue(220), kRealValue(45)); self.startButton.frame = CGRectMake((self.width - 200)/2, self.height - kRealValue(55) - SafeAreaBottomHeight - 10, 200, kRealValue(55)); // self.startButton.centerY = self.beautyBtn.centerY; self.startButton.titleLabel.font = [UIFont systemFontOfSize:14]; [self.startButton addTarget:self action:@selector(startbuttonAction) forControlEvents:UIControlEventTouchUpInside]; [self.startButton setTitle:ASLocalizedString(@"开始直播")forState:UIControlStateNormal]; // [self.startButton setBackgroundImage:[UIImage imageWithColor:[UIColor qmui_colorWithHexString:@"#AE2CF1"]] forState:UIControlStateNormal]; [self.startButton setBackgroundImage:[UIImage imageNamed:@"live_beginLiveBg"] forState:UIControlStateNormal]; [self.startButton setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal]; self.startButton.titleLabel.font = [UIFont systemFontOfSize:16]; self.startButton.layer.masksToBounds = YES; self.startButton.layer.cornerRadius = kRealValue(22.5); [self addSubview:self.startButton]; [self setUpBeautyView]; [self setTxPreview]; [self resetViewWithTitleTop:kRealValue(23) + kStatusBarHeight]; if (0) { [self addSubview:self.videoPushBtn]; [self addSubview:self.otherPushBtn]; [self addSubview:self.lineView]; } } return self; } - (void)passWordButtonClick { self.passWordButton.selected = !self.passWordButton.isSelected; } - (void)enterTicketButtonClick { self.enterTicketButton.selected = !self.enterTicketButton.isSelected; } - (void)handleBackEvent { if (self.delegate && [self.delegate respondsToSelector:@selector(closeThestartLiveViewDelegate)]) { [self.delegate closeThestartLiveViewDelegate]; } } -(void)resetViewWithTitleTop:(CGFloat)top{ top = kRealValue(55) + kStatusBarHeight; self.middleView.top = top; // self.selectedImageView.top = top; self.titleL.top = self.selectedImageView.bottom + kRealValue(15); // self.textView.top = top; } -(void)setUpBeautyView{ // ///////////// TiSDK 添加 开始 //////////// // self.tiSDKManager = [[TiSDKManager alloc]init]; NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key; // NSString* key = @""; [TiSDK init:key CallBack:^(InitStatus initStatus) { [[NSNotificationCenter defaultCenter] postNotificationName:@"TiSDKInitStatusNotification" object:nil]; }]; // [TiSDKManager shareManager] // [[TiUIManager shareManager] loadToSuperview:self.view]; [TiUIManager shareManager].showsDefaultUI = YES; [[TiUIManager shareManager]loadToWindowDelegate:nil]; } -(void)setTxPreview{ [self setBackgroundColor:kBlackColor]; _txLivePushonfig = [[TXLivePushConfig alloc] init]; _txLivePushonfig.frontCamera = YES; _txLivePushonfig.enableAEC = YES; _txLivePushonfig.enableHWAcceleration = YES; _txLivePushonfig.enableAutoBitrate = NO; _txLivePushonfig.audioChannels = 1; // 单声道 GlobalVariables *BuguLive = [GlobalVariables sharedInstance]; // 0:标清(360*640) 1:高清(540*960) 2:超清(720*1280) if (BuguLive.appModel.video_resolution_type == 0) { _txLivePushonfig.videoResolution = VIDEO_RESOLUTION_TYPE_360_640; _txLivePushonfig.videoBitratePIN = 700; } else if (BuguLive.appModel.video_resolution_type == 1) { _txLivePushonfig.videoResolution = VIDEO_RESOLUTION_TYPE_540_960; _txLivePushonfig.videoBitratePIN = 1000; } else if (BuguLive.appModel.video_resolution_type == 2) { _txLivePushonfig.videoResolution = VIDEO_RESOLUTION_TYPE_720_1280; _txLivePushonfig.videoBitratePIN = 1500; } _txLivePushonfig.autoAdjustStrategy = NO; _txLivePushonfig.videoFPS = 20; _txLivePushonfig.audioSampleRate = AUDIO_SAMPLE_RATE_48000; // 不要用其它的 _txLivePushonfig.pauseFps = 10; _txLivePushonfig.pauseTime = 300; _txLivePushonfig.pauseImg = [UIImage imageNamed:@"lr_bg_leave.png"]; // _pusher = [[TXLivePush alloc] initWithConfig:_txLivePushonfig]; // 设置日志级别 [TXLiveBase setLogLevel:LOGLEVEL_NULL]; // 初始化视频父视图 _preViewContainer = [[UIImageView alloc] initWithFrame:self.bounds]; _preViewContainer.image = [UIImage imageNamed:@"live_preview_bg"]; [self insertSubview:_preViewContainer atIndex:0]; _preViewContainer.center = self.center; // [_pusher startPreview:_preViewContainer]; // _pusher.videoProcessDelegate = self; // UITapGestureRecognizer *tapBgView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBgView:)]; // tapBgView.delegate = self; // [_preViewContainer addGestureRecognizer:tapBgView]; // [self addGestureRecognizer:tapBgView]; } //#pragma mark ---------美颜增加------------- //- (GLuint)onPreProcessTexture:(GLuint)texture width:(CGFloat)width height:(CGFloat)height{ // return [[TiSDKManager shareManager] renderTexture2D:texture Width:width Height:height Rotation:CLOCKWISE_0 Mirror:_pusher.config.frontCamera]; //} -(void)clickBgView:(UITapGestureRecognizer *)sender{ [self.textView resignFirstResponder]; _beautyPanel.hidden = YES; } - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ [self.textView resignFirstResponder]; return YES; } - (void)selectedTheClassirmAction { //选择分类 } - (void)startbuttonAction { if (self.otherPushBtn.isSelected) { [_pusher stopPreview]; } if (self.delegate && [self.delegate respondsToSelector:@selector(startThePublishLiveDelegate)]) { [self.delegate startThePublishLiveDelegate]; } } -(void)clickPasswordActionDelegate:(BOOL)password{ if (self.delegate && [self.delegate respondsToSelector:@selector(clickPasswordActionDelegate:)]) { [self.delegate clickPasswordActionDelegate:password]; } } -(void)clickShopActionDelegate:(BOOL)shop{ if (self.delegate && [self.delegate respondsToSelector:@selector(clickShopActionDelegate:)]) { [self.delegate clickShopActionDelegate:shop]; } } - (void)closeThePublishLive:(PublishLiveTopView *)topView { //关闭开始直播界面 if(self.delegate && [self.delegate respondsToSelector:@selector(closeThestartLiveViewDelegate)]) { [self.delegate closeThestartLiveViewDelegate]; } } - (void)ispracychangeActionDelegate:(BOOL)ispraicy { self.shareView.hidden = ispraicy; } - (UIImageView *)backGroundImageview { if (_backGroundImageview == nil) { _backGroundImageview = [[UIImageView alloc]initWithFrame:self.bounds]; [self addSubview:_backGroundImageview]; UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; UIVisualEffectView *view = [[UIVisualEffectView alloc]initWithEffect:beffect]; view.frame = _backGroundImageview.bounds; [_backGroundImageview addSubview:view]; [_backGroundImageview sd_setImageWithURL:[NSURL URLWithString:[[IMAPlatform sharedInstance].host imUserIconUrl]]]; } return _backGroundImageview; } /** 初始化摄像头 */ - (void) initCapture { self.captureSession = [[AVCaptureSession alloc] init]; for (AVCaptureDevice *d in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) { if ([d position] == AVCaptureDevicePositionFront) { [self.captureSession beginConfiguration]; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:d error:nil]; for (AVCaptureInput *oldInput in self.captureSession.inputs) { [self.captureSession removeInput:oldInput]; } [self.captureSession addInput:input]; [self.captureSession commitConfiguration]; break; } } [self.captureSession startRunning]; self.customLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];; CGRect frame = self.bounds; self.customLayer.frame = frame; self.customLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.layer addSublayer:self.customLayer]; } - (void)selectedImageViewAction:(UIButton *)sender { if(self.delegate && [self.delegate respondsToSelector:@selector(selectedTheImageDelegate)]) { [self.delegate selectedTheImageDelegate]; } } -(void)clickBeauty:(UIButton *)sender{ [[TiUIManager shareManager]showMainMenuView]; } #pragma mark - BeautySettingPanelDelegate - (void)onSetBeautyStyle:(NSUInteger)beautyStyle beautyLevel:(float)beautyLevel whitenessLevel:(float)whitenessLevel ruddinessLevel:(float)ruddinessLevel { [_pusher setBeautyStyle:beautyStyle beautyLevel:beautyLevel whitenessLevel:whitenessLevel ruddinessLevel:ruddinessLevel]; } - (void)onSetMixLevel:(float)mixLevel { [_pusher setSpecialRatio:mixLevel / 10.0]; } - (void)onSetEyeScaleLevel:(float)eyeScaleLevel { [_pusher setEyeScaleLevel:eyeScaleLevel]; } - (void)onSetFaceScaleLevel:(float)faceScaleLevel { [_pusher setFaceScaleLevel:faceScaleLevel]; } - (void)onSetFaceBeautyLevel:(float)beautyLevel { } - (void)onSetFaceVLevel:(float)vLevel { [_pusher setFaceVLevel:vLevel]; } - (void)onSetChinLevel:(float)chinLevel { [_pusher setChinLevel:chinLevel]; } - (void)onSetFaceShortLevel:(float)shortLevel { [_pusher setFaceShortLevel:shortLevel]; } - (void)onSetNoseSlimLevel:(float)slimLevel { [_pusher setNoseSlimLevel:slimLevel]; } - (void)onSetFilter:(UIImage*)filterImage { [_pusher setFilter:filterImage]; } - (void)onSetGreenScreenFile:(NSURL *)file { [_pusher setGreenScreenFile:file]; } - (void)onSelectMotionTmpl:(NSString *)tmplName inDir:(NSString *)tmplDir { [_pusher selectMotionTmpl:tmplName inDir:tmplDir]; } - (void)classifyButtonActionDelegate { if (self.delegate && [self.delegate respondsToSelector:@selector(selectedTheClassifyDelegate)]) { [self.delegate selectedTheClassifyDelegate]; } } #pragma mark - UITextViewDelegate - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { if ([self.textView.text isEqualToString:ASLocalizedString(@"#添加标题上热门更轻松")]) { self.textView.text = @""; [self resetViewWithTitleTop:kRealValue(23) + kStatusBarHeight]; } return YES; } - (BOOL)textViewShouldEndEditing:(UITextView *)textView { if ([self.textView.text isEqualToString:@""]) { self.textView.text = ASLocalizedString(@"#添加标题上热门更轻松"); } [self resetViewWithTitleTop:kRealValue(23) + kStatusBarHeight]; return YES; } - (UIButton *)videoPushBtn{ if (!_videoPushBtn){ _videoPushBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, self.startButton.bottom + 10, (self.width - 40 ) / 2, 35)]; [_videoPushBtn setTitleColor:kWhiteColor forState:UIControlStateSelected]; _videoPushBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; [_videoPushBtn setTitleColor:[kWhiteColor colorWithAlphaComponent:0.8] forState:UIControlStateNormal]; [_videoPushBtn setTitle:ASLocalizedString(@"视频直播") forState:UIControlStateNormal]; [_videoPushBtn addTarget:self action:@selector(videoPushBtnAction:) forControlEvents:UIControlEventTouchUpInside]; _videoPushBtn.selected = YES; } return _videoPushBtn; } - (UIButton *)otherPushBtn{ if (!_otherPushBtn){ _otherPushBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.width / 2, self.startButton.bottom + 10, (self.width - 40 ) / 2, 35)]; [_otherPushBtn setTitleColor:kWhiteColor forState:UIControlStateSelected]; _otherPushBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; [_otherPushBtn setTitleColor:[kWhiteColor colorWithAlphaComponent:0.8] forState:UIControlStateNormal]; [_otherPushBtn setTitle:ASLocalizedString(@"外设直播") forState:UIControlStateNormal]; [_otherPushBtn addTarget:self action:@selector(otherPushBtnAction:) forControlEvents:UIControlEventTouchUpInside]; } return _otherPushBtn; } - (void)videoPushBtnAction:(UIButton *)sender{ [self.pusher startPreview:_preViewContainer]; sender.selected = YES; self.otherPushBtn.selected = NO; self.lineView.centerX = sender.centerX; self.beautyBtn.hidden = YES; self.startButton.frame = CGRectMake(self.beautyBtn.right + kRealValue(25), self.height - 120, kRealValue(220), kRealValue(45)); [self.startButton setTitle:@"开始直播" forState:UIControlStateNormal]; } - (void)otherPushBtnAction:(UIButton *)sender{ [self.pusher stopPreview]; sender.selected = YES; self.videoPushBtn.selected = NO; self.lineView.centerX = sender.centerX; self.beautyBtn.hidden = YES; self.startButton.frame = CGRectMake(kRealValue(50), self.height - 120, kScreenW - kRealValue(100), kRealValue(45)); [self.startButton setTitle:@"创建外设直播" forState:UIControlStateNormal]; } - (UIView *)lineView{ if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 4)]; _lineView.backgroundColor = kWhiteColor; _lineView.layer.cornerRadius = 2; _lineView.clipsToBounds = YES; _lineView.top = self.liveBtn.bottom; _lineView.centerX = self.voiceBtn.centerX; } return _lineView; } //// 创建推流器,并使用本地配置初始化它 //- (TXLivePush *)createPusher { // // config初始化 // TXLivePushConfig *config = [[TXLivePushConfig alloc] init]; // config.pauseFps = 10; // config.pauseTime = 300; // config.pauseImg = [UIImage imageNamed:@"pause_publish"]; //// config.touchFocus = [PushMoreSettingViewController isEnableTouchFocus]; //// config.enableZoom = [PushMoreSettingViewController isEnableVideoZoom]; //// config.enableAudioPreview = [PushSettingViewController getEnableAudioPreview]; //// config.frontCamera = _btnCamera.tag == 0 ? YES : NO; // if ([PushMoreSettingViewController isEnableWaterMark]) { // config.watermark = [UIImage imageNamed:@"watermark"]; // config.watermarkPos = CGPointMake(10, 10); // } // // // 推流器初始化 // TXLivePush *pusher = [[TXLivePush alloc] initWithConfig:config]; //// [pusher setReverbType:[PushSettingViewController getReverbType]]; //// [pusher setVoiceChangerType:[PushSettingViewController getVoiceChangerType]]; //// [pusher toggleTorch:[PushMoreSettingViewController isOpenTorch]]; //// [pusher setMirror:[PushMoreSettingViewController isMirrorVideo]]; //// [pusher setMute:[PushMoreSettingViewController isMuteAudio]]; //// [pusher setVideoQuality:[PushSettingViewController getVideoQuality] adjustBitrate:[PushSettingViewController getBandWidthAdjust] adjustResolution:NO]; // // // 修改软硬编需要在setVideoQuality之后设置config.enableHWAcceleration // config.enableHWAcceleration = [PushSettingViewController getEnableHWAcceleration]; // // // 横屏推流需要先设置config.homeOrientation = HOME_ORIENTATION_RIGHT,然后再[pusher setRenderRotation:90] // config.homeOrientation = ([PushMoreSettingViewController isHorizontalPush] ? HOME_ORIENTATION_RIGHT : HOME_ORIENTATION_DOWN); // if ([PushMoreSettingViewController isHorizontalPush]) { // [pusher setRenderRotation:90]; // } else { // [pusher setRenderRotation:0]; // } // // [pusher setLogViewMargin:UIEdgeInsetsMake(120, 10, 60, 10)]; // [pusher showVideoDebugLog:[PushMoreSettingViewController isShowDebugLog]]; // [pusher setEnableClockOverlay:[PushMoreSettingViewController isEnableDelayCheck]]; // // [pusher setVideoProcessDelegate:self]; // // [pusher setConfig:config]; // // return pusher; //} //lineView 懒加载 - (UIView *)buttonLineView{ if (!_buttonLineView) { _buttonLineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 15, 4)]; _buttonLineView.backgroundColor = kWhiteColor; _buttonLineView.layer.cornerRadius = 1.5; _buttonLineView.clipsToBounds = YES; // _buttonLineView.top = self.videoPushBtn.bottom - 4; _buttonLineView.centerX = self.videoPushBtn.centerX; _buttonLineView.top = self.videoPushBtn.bottom + 4; } return _buttonLineView; } @end