// // YOUPAILZLiveAnchorVC.m // TIANYAN // // Created by CY on 2021/5/8. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZLiveAnchorVC.h" #import "FUAPIDemoBar.h" #import "FUManager.h" #import "YOUPAILZStartLiveView.h" #import "YOUPAILZAnchorMenuView.h" #import "LZAlertWindow.h" #import "UIViewController+TFPresent.h" #import "YOUPAILZAnchorLiveCloseVC.h" #import "YOUPAILZLiveInviteVC.h" #import "YOUPAILZLiveCallWindow.h" #import "YOUPAILZLiveStartPKModel.h" #import "YOUPAILZLiveMemberListVC.h" #import "YOUPAILZLiveMusicListWindow.h" #import "YOUPAILZMusicModel.h" #import "YOUPAILZMusicPlayerView.h" #import "SDCycleScrollView.h" #import "YOUPAILZLiveBoardCycleViewCell.h" #import "YOUPAILZLiveMemberButton.h" #import "YOUPAILZLiveAnchorHotWindow.h" #import "YOUPAILZCommonGiftView.h" @interface YOUPAILZLiveAnchorVC () @property (nonatomic, strong) FUAPIDemoBar *youpaipdemoBar; //Tool Bar @property (nonatomic, weak) UIView *youpaipdemoBarBgV; @property (nonatomic, weak) UIButton *youpaipsendMessageBtn; // 发送消息按钮 @property (nonatomic, weak) UIButton *youpaipvoiceBtn; // 喇叭按钮 @property (nonatomic, weak) UIButton *youpaipbeautyBtn; // 美颜按钮 @property (nonatomic, weak) UIButton *youpaipchangeCameraBtn; // 切换摄像头 @property (nonatomic, weak) YOUPAILZStartLiveView *youpaipstartLiveView; // 开始直播页面 @property (nonatomic, weak) UILabel *youpaipliveMemberCountL; // 直播人数 @property (nonatomic, strong) NSMutableArray *youpaipmemberBtns; ///直播榜单人数 @property (nonatomic, weak) UIView *youpaiprankBgV; // 排行背景View @property (nonatomic, weak) SDCycleScrollView *youpaipboardCycleView; // 当前直播间上榜信息View @property (nonatomic, weak) UILabel *youpaipfansCountL; // 粉丝数 @property (nonatomic, weak) UIButton *youpaiplianmaiBtn; // 连麦按钮 @property (nonatomic, weak) UIButton *youpaippkBtn; // pk按钮 @property (nonatomic, weak) UIButton *youpaiprePKBtn; // 重新PK按钮 @property (nonatomic, strong)YOUPAILZLiveStartPKModel *youpaipstartPKModel; @property (nonatomic, assign)LZLiveInviteType youpaipinviteType; @property (nonatomic, strong) YOUPAILZAnchorMenuView *youpaipmenuView; @property (nonatomic, assign) LZLivePKState youpaippkState; @property (nonatomic, strong) NSMutableArray *youpaipmusicList; // 歌单 @property (nonatomic, strong) YOUPAILZMusicListItemModel *currentMusic; // 当前音乐 //@property (nonatomic, assign) AgoraAudioMixingStateCode youpaipmusicPlayState; // 音乐播放状态 @property (nonatomic, weak) YOUPAILZMusicPlayerView *youpaipmusicPlayerView; // 音乐-歌词展示 @property (nonatomic, assign) CGFloat youpaipmusicPlayerViewY; @end @implementation YOUPAILZLiveAnchorVC - (void)dealloc{ NSString *cls = NSStringFromClass([self class]); NSLog(@"销毁:--%@ dealloc",cls); } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; // [IQKeyboardManager sharedManager].enable = NO; // [IQKeyboardManager sharedManager].enableAutoToolbar = NO; [LCSaveData saveIsVideo:YES]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; // [IQKeyboardManager sharedManager].enable = YES; // [IQKeyboardManager sharedManager].enableAutoToolbar = YES; } - (void)viewDidDisappear:(BOOL)animated{ [super viewDidDisappear:animated]; [self youpaifstopMusicPlayer]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)youpaifstopMusicPlayer{ [self.youpaipmusicPlayerView youpaifstopTimer]; [self.youpaipmusicPlayerView removeFromSuperview]; self.youpaipmusicPlayerView = nil; } - (void)viewDidLoad { [self youpaifsetupBeautyBar]; [super viewDidLoad]; [self demoBarSetBeautyDefultParams]; [self youpaifsetupStartLiveView]; [self youpaifhandleBlock]; } /// 女神直播回调 - (void)youpaifhandleBlock{ @weakify(self); [self setYoupaipliveCloseBlock:^{ @strongify(self); [self youpaifrequestCloseLiveData]; }]; [self setYoupaippkBlock:^(YOUPAILZLivePKAttachment * _Nonnull pkAttachment) { @strongify(self); [self youpaifhandlePKOrLianMaiWithTypeStr:pkAttachment.type pkid:pkAttachment.id type:LZLiveInviteTypePK OperateUid:pkAttachment.operate_uid]; }]; [self setYoupaiplianmaiBlock:^(YOUPAILZLiveLianMaiAttachment * _Nonnull lianmaiAttachment) { @strongify(self); [self youpaifhandlePKOrLianMaiWithTypeStr:lianmaiAttachment.type pkid:lianmaiAttachment.id type:LZLiveInviteTypeLianMai OperateUid:lianmaiAttachment.operate_uid]; }]; [self.youpaippkdataView setCurrentPKStateBlock:^(LZLivePKState state) { @strongify(self); self.youpaippkState = state; }]; [self.youpaippkdataView setShowRePKBlock:^(BOOL show) { @strongify(self); self.youpaiprePKBtn.hidden = !show; }]; [self setYoupaipremoteVideoCloseBlock:^{ @strongify(self); self.youpaippkdataView.youpaipisStartPK = NO; self.youpaiprePKBtn.hidden = YES; }]; [self setYoupaipresetPKDataBlock:^(YOUPAILZLivePKDataAttachment * _Nonnull attachment) { @strongify(self); self.youpaipstartPKModel.youpaippk_id = attachment.id; }]; [self setYoupaipmusicPlayFinishBlock:^{ @strongify(self); [self youpaifnextMusic]; }]; // [self setYoupaipmusicPlayStateBlock:^(AgoraAudioMixingStateCode stateCode) { // @strongify(self); // self.youpaipmusicPlayState = stateCode; // [[NSNotificationCenter defaultCenter] postNotificationName:@"MusicPlayStateChangeNotification" object:@(self.youpaipmusicPlayState) userInfo:nil]; // }]; [self setYoupaipclickRemoteVideoViewBlock:^(NSString * _Nonnull uid, NSString * _Nonnull room_id) { @strongify(self); if (uid.length != 0) { [self youpaifshowUserInfoWithUserId:uid]; } }]; } /// 根据类型处理PK、连麦 - (void)youpaifhandlePKOrLianMaiWithTypeStr:(NSString *)typeStr pkid:(NSString *)pkid type:(LZLiveInviteType)type OperateUid:(NSString *)operateUid{ if ([typeStr isEqual:@"call"]) { [self youpaifrequestObtainInteractWithPkId:pkid type:type]; }else if ([typeStr isEqual:@"timeout"]){ [ZCHUDHelper showTitle:@"已超时"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil]; }else if ([typeStr isEqual:@"cancel"]){ [ZCHUDHelper showTitle:@"对方已取消"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil]; }else if ([typeStr isEqual:@"hangup"]){ self.youpaipstartPKModel = nil; if ([self.youpaipliveModel.youpaipuser_info.youpaipuser_id isEqual:operateUid]) { [ZCHUDHelper showTitle:@"已挂断"]; }else{ [ZCHUDHelper showTitle:@"对方已挂断"]; } [self.youpaipagoraKit stopChannelMediaRelay]; if (self.youpaipinviteType == LZLiveInviteTypePK) { [self.youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateNormal]; [self.youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateHighlighted]; self.youpaippkBtn.selected = NO; }else{ [self.youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateNormal]; [self.youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateHighlighted]; self.youpaiplianmaiBtn.selected = NO; } }else if ([typeStr isEqual:@"refuse"]){ [ZCHUDHelper showTitle:@"对方已拒绝"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil]; }else if ([typeStr isEqual:@"agree"]){ self.youpaipinviteType = type; [self youpaifforwardChannel]; [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil]; } } /// 设置默认美颜属性 - (void)demoBarSetBeautyDefultParams { [_youpaipdemoBar reloadSkinView:[FUManager shareManager].skinParams]; [_youpaipdemoBar reloadShapView:[FUManager shareManager].shapeParams]; [_youpaipdemoBar reloadFilterView:[FUManager shareManager].filters]; } /// 设置开始直播页面 - (void)youpaifsetupStartLiveView{ YOUPAILZStartLiveView *youpaipstartLiveView = [[YOUPAILZStartLiveView alloc] initWithFrame:self.view.bounds shareModel:self.youpaipshareModel youpaipcover:self.youpaipcover]; [self.view addSubview:youpaipstartLiveView]; self.youpaipstartLiveView = youpaipstartLiveView; @weakify(self); [youpaipstartLiveView setYoupaipcloseClickBlock:^{ @strongify(self); [self.youpaipmCamera stopCapture]; [LCSaveData saveIsVideo:NO]; self.youpaipagoraKit.delegate = nil; self.youpaipagoraKit = nil; [self.navigationController popViewControllerAnimated:YES]; }]; [youpaipstartLiveView setYoupaipchangeCameraClickBlock:^{ @strongify(self); [self youpaifchangeCamera]; }]; [youpaipstartLiveView setYoupaipbeautyClickBlock:^{ @strongify(self); [self youpaifshowDemoBar]; }]; [youpaipstartLiveView setYoupaipstartLiveClickBlock:^(YOUPAILZLiveModel * _Nonnull youpaipliveModel) { @strongify(self); self.youpaipliveModel = youpaipliveModel; self.youpaippkdataView.youpaipmodel = youpaipliveModel; [self youpaifjoin]; [self.youpaipstartLiveView removeFromSuperview]; [self youpaifsetupChatMessageView]; [self youpaifsetupHeaderView]; [self youpaifsetupFooterView]; [self youpaifsetupMusicPlayerView]; [self youpaifloadAdvertRecharge]; }]; } /// 音乐-歌词展示 - (void)youpaifsetupMusicPlayerView{ @weakify(self); YOUPAILZMusicPlayerView *youpaipmusicPlayerView = [[YOUPAILZMusicPlayerView alloc]initWithFrame:CGRectMake(self.youpaipchatBgView.mj_w * 0.4f, KScreenHeight / 2.0f, self.youpaipchatBgView.mj_w * 0.6f, 68.0f)]; youpaipmusicPlayerView.hidden = YES; youpaipmusicPlayerView.showLyric = YES; [youpaipmusicPlayerView setGetPlayPositionBlock:^NSInteger{ @strongify(self); return [self.youpaipagoraKit getAudioMixingCurrentPosition]; }]; // 暂停or播放 [youpaipmusicPlayerView setYoupaipsuspendMusicBlock:^{ @strongify(self); // if (self.youpaipmusicPlayState == AgoraAudioMixingStatePlaying) { // [self.youpaipagoraKit pauseAudioMixing]; // }else{ // [self.youpaipagoraKit resumeAudioMixing]; // } }]; [self.youpaipchatBgView addSubview:youpaipmusicPlayerView]; self.youpaipmusicPlayerView = youpaipmusicPlayerView; UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifmusicHandlePan:)]; [youpaipmusicPlayerView addGestureRecognizer:panGestureRecognizer]; } - (void)youpaifmusicHandlePan:(UIPanGestureRecognizer*)recognizer{ CGPoint translation = [recognizer translationInView:self.view]; if(recognizer.state == UIViewAnimatingPositionStart){ self.youpaipmusicPlayerViewY = self.youpaipmusicPlayerView.mj_y; }else if (recognizer.state == UIGestureRecognizerStateChanged) { self.youpaipmusicPlayerView.mj_y = self.youpaipmusicPlayerViewY + translation.y; }else if(recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) { [UIView animateWithDuration:0.25f animations:^{ if (self.youpaipmusicPlayerView.mj_y < NavBarHeight) { self.youpaipmusicPlayerView.mj_y = NavBarHeight; }else if (self.youpaipmusicPlayerView.mj_y > KScreenHeight - TabbarHeight - self.youpaipmusicPlayerView.mj_h){ self.youpaipmusicPlayerView.mj_y = KScreenHeight - TabbarHeight - self.youpaipmusicPlayerView.mj_h; } }]; } } /// 设置美颜工具 - (void)youpaifsetupBeautyBar{ // 美颜工具 [self.view layoutIfNeeded]; UIView *youpaipdemoBarBgV = [[UIView alloc] initWithFrame:self.view.bounds]; youpaipdemoBarBgV.hidden = YES; [self.view addSubview:youpaipdemoBarBgV]; self.youpaipdemoBarBgV = youpaipdemoBarBgV; [self.youpaipdemoBarBgV addSubview:self.youpaipdemoBar]; self.youpaipdemoBar.frame = CGRectMake(0, KScreenHeight - SafeHeight - 182.0f , KScreenWidth, 182.0f); } /// 设置headerView - (void)youpaifsetupHeaderView{ UIView *headerView = [[UIView alloc] init]; [self.view addSubview:headerView]; [headerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(0.0f); make.height.offset(70.0f); make.top.offset(StatusBarHeight); }]; UIButton *anchorInfoBgBtn = [UIButton buttonWithType:UIButtonTypeCustom]; anchorInfoBgBtn.layer.cornerRadius = 17.5f; anchorInfoBgBtn.clipsToBounds = YES; anchorInfoBgBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f]; anchorInfoBgBtn.tag = [self.youpaipliveModel.youpaipuser_info.youpaipuser_id integerValue]; [anchorInfoBgBtn addTarget:self action:@selector(youpaifshowUserInfoClick:) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:anchorInfoBgBtn]; [anchorInfoBgBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(12.0f); make.top.offset(5.0f); make.height.offset(35.0f); make.width.lessThanOrEqualTo(140.0f); make.right.offset(0.0f); }]; UIImageView *youpaipavatarImgV = [[UIImageView alloc] init]; youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill; youpaipavatarImgV.layer.cornerRadius = 16.5f; youpaipavatarImgV.clipsToBounds = YES; [youpaipavatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipliveModel.youpaipuser_info.youpaipavatar]]; [anchorInfoBgBtn addSubview:youpaipavatarImgV]; [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.offset(1.0f); make.size.mas_offset(CGSizeMake(33.0f, 33.0f)); }]; UIImageView *anchorTagImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_anchor_vlog"]]; [anchorInfoBgBtn addSubview:anchorTagImgV]; [anchorTagImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(youpaipavatarImgV.mas_right).offset(0.0f); make.bottom.equalTo(youpaipavatarImgV.mas_bottom).offset(0.0f); make.size.mas_offset(CGSizeMake(10.0f, 10.0f)); }]; UILabel *youpaipnicknameL = [[UILabel alloc] init]; youpaipnicknameL.font = LCBoldFont(11.0f); youpaipnicknameL.textColor = [UIColor whiteColor]; youpaipnicknameL.text = self.youpaipliveModel.youpaipuser_info.youpaipnickname; [anchorInfoBgBtn addSubview:youpaipnicknameL]; [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipavatarImgV.mas_right).offset(4.0f); make.right.offset(-12.0f); make.top.offset(5.0f); // make.height.offset(17.5f); }]; UILabel *youpaipfansCountL = [[UILabel alloc] init]; youpaipfansCountL.font = LCFont(8.0f); youpaipfansCountL.textColor = [UIColor whiteColor]; youpaipfansCountL.text = [NSString stringWithFormat:@"粉丝:%@",self.youpaipliveModel.youpaipfans_count]; [anchorInfoBgBtn addSubview:youpaipfansCountL]; self.youpaipfansCountL = youpaipfansCountL; [youpaipfansCountL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipavatarImgV.mas_right).offset(4.0f); make.right.offset(-12.0f); make.bottom.offset(-5.0f); // make.height.offset(17.5f); }]; UIButton *closeLiveBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [closeLiveBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_close"] forState:UIControlStateNormal]; [closeLiveBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_close"] forState:UIControlStateHighlighted]; [closeLiveBtn addTarget:self action:@selector(youpaifendLive) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:closeLiveBtn]; [closeLiveBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-12.0f); make.top.offset(7.0f + StatusBarHeight); make.height.offset(31.0f); make.width.offset(19.0f); }]; UIButton *liveMemberCountBtn = [UIButton buttonWithType:UIButtonTypeCustom]; liveMemberCountBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f]; liveMemberCountBtn.layer.cornerRadius = 15.5f; liveMemberCountBtn.clipsToBounds = YES; [liveMemberCountBtn addTarget:self action:@selector(youpaifliveMemberCountBtnClick) forControlEvents:UIControlEventTouchUpInside]; [self.youpaipchatBgView addSubview:liveMemberCountBtn]; [liveMemberCountBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-1.0f-19.0f-12.0f); make.top.offset(7.0f + StatusBarHeight); make.height.offset(31.0f); make.width.greaterThanOrEqualTo(31.0f); }]; UILabel *youpaipliveMemberCountL = [[UILabel alloc] init]; youpaipliveMemberCountL.font = LCFont(12.0f); youpaipliveMemberCountL.textColor = [UIColor whiteColor]; youpaipliveMemberCountL.textAlignment = NSTextAlignmentCenter; youpaipliveMemberCountL.text = @"0"; [liveMemberCountBtn addSubview:youpaipliveMemberCountL]; self.youpaipliveMemberCountL = youpaipliveMemberCountL; [youpaipliveMemberCountL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(7.0f); make.top.bottom.offset(0.0f); make.right.offset(-7.0f); }]; @weakify(self); [self setYoupaipliveMemberCountChangeBlock:^(NSInteger memberCount) { @strongify(self); self.youpaipliveMemberCountL.text = [NSString stringWithFormat:@"%@",@(memberCount)]; }]; UIView *youpaiprankBgV = [[UIView alloc] init];//WithFrame:CGRectMake(liveMemberCountBtn.mj_x - 4.0f, 7.0f, 0.0f, 31.0f) [self.youpaipchatBgView addSubview:youpaiprankBgV]; self.youpaiprankBgV = youpaiprankBgV; [youpaiprankBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(liveMemberCountBtn.mas_left).offset(-4.0f); make.top.offset(7.0f + StatusBarHeight); make.height.offset(31.0f); make.width.offset(0.0f); }]; [self youpaifupdateMemberInfo]; [self setYoupaipliveMemberListChangeBlock:^(NSArray * _Nonnull members) { @strongify(self); self.youpaipliveModel.youpaiplive_top_three = [LZLiveTopThreeModel mj_objectArrayWithKeyValuesArray:members]; [self youpaifupdateMemberInfo]; }]; NSMutableArray *arr = [NSMutableArray array]; if (self.youpaipliveModel.youpaipanchor_rank_info.youpaiptotalMoney.youpaipval.length != 0) { [arr addObject:@"totalMoney"]; } if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipgapMoney.youpaipval.length != 0) { [arr addObject:@"gapMoney"]; } if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipno.youpaipval.length != 0) { [arr addObject:@"no"]; } SDCycleScrollView *youpaipboardCycleView = [[SDCycleScrollView alloc] init]; youpaipboardCycleView.backgroundColor = [UIColor clearColor]; youpaipboardCycleView.scrollDirection = UICollectionViewScrollDirectionVertical; youpaipboardCycleView.autoScrollTimeInterval = 5.0f/arr.count; youpaipboardCycleView.autoScroll = YES; youpaipboardCycleView.imageURLStringsGroup = arr.copy; youpaipboardCycleView.titleLabelTextColor = [UIColor redColor]; youpaipboardCycleView.showPageControl = NO; youpaipboardCycleView.delegate = self; [headerView addSubview:youpaipboardCycleView]; self.youpaipboardCycleView = youpaipboardCycleView; [youpaipboardCycleView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(14.0f); make.top.equalTo(anchorInfoBgBtn.mas_bottom).offset(10.0f); make.height.offset(20.0f); make.width.offset(150.0f); }]; [self setYoupaipliveInfoUpdateBlock:^(NSString * _Nonnull anchor_charm, NSString * _Nonnull fans, NSDictionary * _Nonnull anchor_rank_info) { @strongify(self); self.youpaipfansCountL.text = [NSString stringWithFormat:@"粉丝:%@",fans]; self.youpaipliveModel.youpaipanchor_rank_info = [LZLiveAnchorRankInfoModel mj_objectWithKeyValues:anchor_rank_info]; NSMutableArray *arr = [NSMutableArray array]; if (self.youpaipliveModel.youpaipanchor_rank_info.youpaiptotalMoney.youpaipval.length != 0) { [arr addObject:@"totalMoney"]; } if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipgapMoney.youpaipval.length != 0) { [arr addObject:@"gapMoney"]; } if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipno.youpaipval.length != 0) { [arr addObject:@"no"]; } self.youpaipboardCycleView.imageURLStringsGroup = arr.copy; self.youpaipboardCycleView.autoScrollTimeInterval = 5.0f/arr.count; }]; // UIView *userIdBgV = [[UIView alloc] init]; // userIdBgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f]; // userIdBgV.layer.cornerRadius = 8.5f; // userIdBgV.clipsToBounds = YES; // [self.youpaipchatBgView addSubview:userIdBgV]; // [userIdBgV mas_makeConstraints:^(MASConstraintMaker *make) { // make.right.offset(-12.0f); // make.top.equalTo(anchorInfoBgBtn.mas_bottom).offset(8.0f); // make.height.offset(17.0f); // }]; // // UILabel *userIdL = [[UILabel alloc] init]; // userIdL.font = LCFont(12.0f); // userIdL.textColor = HexColorFromRGB(0xDDDDDD); // userIdL.text = [NSString stringWithFormat:@"花舞号 %@",self.youpaipliveModel.user_info.usercode]; // [userIdBgV addSubview:userIdL]; // [userIdL mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.offset(7.0f); // make.right.offset(-7.0f); // make.top.bottom.offset(0.0f); // }]; UIButton *youpaiprePKBtn = [UIButton buttonWithType:UIButtonTypeCustom]; // youpaiprePKBtn.layer.cornerRadius = 12.0f; // youpaiprePKBtn.clipsToBounds = YES; youpaiprePKBtn.frame = CGRectMake(0, 0, 56.0f, 22.0f); [LCTools clipCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight View:youpaiprePKBtn size:CGSizeMake(5.0f, 5.0f)]; [youpaiprePKBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(56.0f, 22.0f) FromColors:@[HexColorFromRGB(0x69BCF8),HexColorFromRGB(0x274BE8)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; [youpaiprePKBtn setTitle:@"重新PK" forState:UIControlStateNormal]; [youpaiprePKBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; youpaiprePKBtn.titleLabel.font = LCFont12; youpaiprePKBtn.hidden = YES; [youpaiprePKBtn addTarget:self action:@selector(youpaifrePKBtnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:youpaiprePKBtn]; self.youpaiprePKBtn = youpaiprePKBtn; [youpaiprePKBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view); make.top.equalTo(headerView.mas_bottom).offset(8.0f); make.size.mas_offset(CGSizeMake(56.0f, 22.0f)); }]; } - (void)youpaifupdateMemberInfo{ [self youpaifeditBtnCountWithCount:self.youpaipliveModel.youpaiplive_top_three.count > 3 ? 3 : self.youpaipliveModel.youpaiplive_top_three.count]; [self.youpaiprankBgV updateConstraints:^(MASConstraintMaker *make) { make.width.offset(self.youpaipmemberBtns.count * 31.0f + (self.youpaipmemberBtns.count - 1.0f) * 4.0f); }]; NSArray *borderColors = @[[HexColorFromRGB(0xFF0000) colorWithAlphaComponent:0.47f],[HexColorFromRGB(0xFFD043) colorWithAlphaComponent:0.47f],[HexColorFromRGB(0x6EF467) colorWithAlphaComponent:0.47f]]; NSArray *titleBgColors = @[[HexColorFromRGB(0xF46767) colorWithAlphaComponent:0.41f],[HexColorFromRGB(0xFFC104) colorWithAlphaComponent:0.41f],[HexColorFromRGB(0x6EF467) colorWithAlphaComponent:0.41f]]; // for (NSInteger i = 0; i < self.youpaipmemberBtns.count; i ++) { // YOUPAILZLiveMemberButton *imgBtn = self.youpaipmemberBtns[i]; // imgBtn.layer.cornerRadius = 15.5f; // imgBtn.clipsToBounds = YES; // imgBtn.tag = [self.youpaipliveModel.youpaiplive_top_three[i].youpaipid integerValue]; // [imgBtn addTarget:self action:@selector(youpaifshowUserInfoClick:) forControlEvents:UIControlEventTouchUpInside]; // [imgBtn sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipliveModel.youpaiplive_top_three[i].youpaipavatar] forState:UIControlStateNormal]; // imgBtn.frame = CGRectMake(i * 31.0f + i * 4.0f, 0, 31.0f, 31.0f); // imgBtn.youpaipcountL.text = self.youpaipliveModel.youpaiplive_top_three[i].youpaipscore; // imgBtn.layer.borderColor = borderColors[i].CGColor; // imgBtn.layer.borderWidth = 1.0f; // imgBtn.youpaipcountL.mj_w = 31.0f; // imgBtn.youpaipcountL.backgroundColor = titleBgColors[i]; // [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:imgBtn.youpaipcountL size:CGSizeMake(6.0f, 6.0f)]; // } } /// 设置FooterView - (void)youpaifsetupFooterView{ UIView *youpaipfooterView = [[UIView alloc] init]; [self.youpaipchatBgView addSubview:youpaipfooterView]; [youpaipfooterView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.left.offset(0.0f); make.height.offset(40.0f); make.bottom.offset(-SafeHeight - 10.0f); }]; UIButton *sendMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom]; sendMessageBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f]; sendMessageBtn.layer.cornerRadius = 20.0f; sendMessageBtn.clipsToBounds = YES; [sendMessageBtn addTarget:self action:@selector(youpaifsendMessageBtnClick) forControlEvents:UIControlEventTouchUpInside]; [youpaipfooterView addSubview:sendMessageBtn]; self.youpaipsendMessageBtn = sendMessageBtn; [sendMessageBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(0.0f); make.height.offset(40.0f); make.bottom.offset(0.0f); make.width.offset(103.0f); }]; UILabel *youpaiptextL = [[UILabel alloc] init]; youpaiptextL.font = LCFont16; youpaiptextL.textColor = HexColorFromRGB(0xDDDDDD); youpaiptextL.text = @"聊聊天…"; [sendMessageBtn addSubview:youpaiptextL]; [youpaiptextL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(16.0f); make.top.bottom.offset(0.0f); }]; UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [moreBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_audience_more"] forState:UIControlStateNormal]; [moreBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_audience_more"] forState:UIControlStateHighlighted]; [moreBtn addTarget:self action:@selector(youpaifmoreBtnClick) forControlEvents:UIControlEventTouchUpInside]; [youpaipfooterView addSubview:moreBtn]; [moreBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-16.0f); make.top.offset(0.0f); make.size.mas_offset(CGSizeMake(40.0f, 40.0f)); }]; // 连麦 UIButton *youpaiplianmaiBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateNormal]; [youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateHighlighted]; [youpaiplianmaiBtn addTarget:self action:@selector(youpaiflianmaiBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [youpaipfooterView addSubview:youpaiplianmaiBtn]; self.youpaiplianmaiBtn = youpaiplianmaiBtn; [youpaiplianmaiBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(moreBtn.mas_left).offset(-16.0f); make.top.offset(0.0f); make.size.mas_offset(CGSizeMake(40.0f, 40.0f)); }]; // pk UIButton *youpaippkBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateNormal]; [youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateHighlighted]; [youpaippkBtn addTarget:self action:@selector(youpaifpkBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [youpaipfooterView addSubview:youpaippkBtn]; self.youpaippkBtn = youpaippkBtn; [youpaippkBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(youpaiplianmaiBtn.mas_left).offset(-16.0f); make.top.offset(0.0f); make.size.mas_offset(CGSizeMake(40.0f, 40.0f)); }]; // 礼物 UIButton *giftBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [giftBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_gift"] forState:UIControlStateNormal]; [giftBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_gift"] forState:UIControlStateHighlighted]; [giftBtn addTarget:self action:@selector(youpaifgiftBtnClick) forControlEvents:UIControlEventTouchUpInside]; [youpaipfooterView addSubview:giftBtn]; [giftBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(youpaippkBtn.mas_left).offset(-9.0f); make.top.offset(0.0f); make.size.mas_offset(CGSizeMake(40.0f, 40.0f)); }]; } #pragma mark - Click - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self youpaifhideKayboard]; UITouch* touch = [touches anyObject]; UIView* view = [touch view]; if (view == self.youpaipdemoBarBgV) { [self youpaifhideDemoBar]; } } /// 发送消息按钮点击事件 - (void)youpaifsendMessageBtnClick{ [self youpaifsendMessageBecomeFirstResponder]; } /// 喇叭 - (void)youpaifvoice:(BOOL)isOpen{ if (isOpen) { [self.youpaipagoraKit muteLocalAudioStream:YES]; }else{ [self.youpaipagoraKit muteLocalAudioStream:NO]; } } /// 查看在线人员列表 - (void)youpaifliveMemberCountBtnClick{ YOUPAILZLiveMemberListVC *memberVc = [[YOUPAILZLiveMemberListVC alloc] init]; memberVc.youpaiplive_id = self.youpaipliveModel.youpaiplive_id; memberVc.isTouchDismiss = YES; memberVc.youpaipisAnchor = YES; @weakify(self); [memberVc setSelectedMemberBlock:^(YOUPAILZLiveMemberModel * _Nonnull member) { @strongify(self); [self youpaifshowUserInfoWithUserId:member.youpaipid]; }]; [self TFPresentVC:memberVc completion:^{}]; } /// 切换摄像头 - (void)youpaifchangeCamera{ [self.youpaipmCamera changeCameraInputDeviceisFront:!self.youpaipmCamera.isFrontCamera]; [self.youpaipagoraKit switchCamera]; [[FUManager shareManager] onCameraChange]; } /// 连麦事件 - (void)youpaifforwardChannel{ AgoraChannelMediaRelayConfiguration *config = [[AgoraChannelMediaRelayConfiguration alloc] init]; AgoraChannelMediaRelayInfo *fromRelayInfo = [[AgoraChannelMediaRelayInfo alloc] init]; fromRelayInfo.channelName = self.youpaipliveModel.youpaiproomid; fromRelayInfo.uid = [self.youpaipliveModel.youpaipuser_info.youpaipuser_id integerValue]; config.sourceInfo = fromRelayInfo; NSString *roomid = self.youpaipstartPKModel.youpaipto_roomid; if (roomid.length == 0) { roomid = self.youpaipstartPKModel.youpaipfrom_roomid; } [config setDestinationInfo:fromRelayInfo forChannelName:roomid]; // [self.youpaipagoraKit startChannelMediaRelay:config]; [self.youpaipagoraKit startOrUpdateChannelMediaRelay:config]; UIButton *btn = nil; if (self.youpaipinviteType == LZLiveInviteTypePK) { btn = self.youpaippkBtn; }else{ btn = self.youpaiplianmaiBtn; } btn.selected = YES; [btn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_close_pk_lianmai"] forState:UIControlStateNormal]; [btn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_close_pk_lianmai"] forState:UIControlStateHighlighted]; } /// 更多菜单点击 - (void)youpaifmoreBtnClick{ [self.youpaipmenuView youpaifshowAnimation]; } // 连麦按钮点击事件 - (void)youpaiflianmaiBtnClick:(UIButton *)sender{ if (sender.isSelected == NO) { YOUPAILZLiveInviteVC *vc = [[YOUPAILZLiveInviteVC alloc] initWithType:LZLiveInviteTypeLianMai]; @weakify(self); [vc setYoupaipinviteBlock:^(LZLiveInviteType type, YOUPAILZLiveInviteModel * _Nonnull model) { @strongify(self); [self youpaifrequestLianMaiOrPKWithType:type model:model]; }]; [self TFPresentViewController:vc presentSize:CGSizeMake(KScreenWidth, ScaleSize(343.0f)) direction:TFDirectionBottom completion:^{}]; }else{ @weakify(self); LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"结束连麦" handler:^(LZAlertAction *action) { @strongify(self); [self youpaifhangupLianMaiOrPK]; }]; cancelAction.cornerRadius = 24.0f; cancelAction.bgColor = HexColorFromRGB(0x9F9DA5); LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"继续连麦" handler:^(LZAlertAction *action) { }]; confimAction.cornerRadius = 24.0f; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"当前处于连麦状态,是否确认结束连麦?" action:@[cancelAction,confimAction]]; [self TFPresentVC:alert completion:^{}]; } } /// 赠送礼物按钮点击事件 - (void)youpaifgiftBtnClick{ YOUPAILZCommonGiftView *view = [YOUPAILZCommonGiftView new]; view.isTouchDismiss = YES; view.youpaipisAnchor = YES; [view setYoupaiplzgiftblock:^(YOUPAILCGiftModel * _Nonnull model, NSInteger count,NSString*categoryID) { [ZCHUDHelper showTitle:@"你在直播中,暂时不可以送礼物"]; }]; [self TFPresentVC:view completion:^{ }]; } // pk按钮点击事件 - (void)youpaifpkBtnClick:(UIButton *)sender{ if (sender.isSelected == NO) { YOUPAILZLiveInviteVC *vc = [[YOUPAILZLiveInviteVC alloc] initWithType:LZLiveInviteTypePK]; @weakify(self); [vc setYoupaipinviteBlock:^(LZLiveInviteType type, YOUPAILZLiveInviteModel * _Nonnull model) { @strongify(self); [self youpaifrequestLianMaiOrPKWithType:type model:model]; }]; [self TFPresentViewController:vc presentSize:CGSizeMake(KScreenWidth, ScaleSize(343.0f)) direction:TFDirectionBottom completion:^{}]; }else{ NSString *cancelT = @""; NSString *confimT = @""; NSString *contentT = @""; if (self.youpaippkState == LZLivePKStatePK) { cancelT = @"结束PK"; confimT = @"继续PK"; contentT = @"当前处于PK状态,是否确认结束PK?"; }else if(self.youpaippkState == LZLivePKStatePunishment){ cancelT = @"断开PK"; confimT = @"继续PK"; contentT = @"当前处于惩罚时间,是否断开PK?"; }else if(self.youpaippkState == LZLivePKStateEnd){ cancelT = @"结束PK"; confimT = @"继续PK"; contentT = @"当前处于PK连线状态,是否确认结束PK?"; } @weakify(self); LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:cancelT handler:^(LZAlertAction *action) { @strongify(self); [self youpaifhangupLianMaiOrPK]; }]; cancelAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[HexColorFromRGB(0x9F9DA5),HexColorFromRGB(0x9F9DA5)] ByGradientType:GradientLeftToRight]];; cancelAction.cornerRadius = 24.0f; LZAlertAction *confimAction = [LZAlertAction actionWithTitle:confimT handler:^(LZAlertAction *action) { }]; confimAction.cornerRadius = 24.0f; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:contentT action:@[cancelAction,confimAction]]; [self TFPresentVC:alert completion:^{}]; } } /// 重新pk事件 - (void)youpaifrePKBtnClick{ NSString *roomid = self.youpaipstartPKModel.youpaipto_roomid; if (roomid.length == 0) { roomid = self.youpaipstartPKModel.youpaipfrom_roomid; } [LCHttpHelper requestWithURLString:ReStartPK parameters:@{@"room_id":roomid} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } /// 获取用户信息 - (void)youpaifshowUserInfoClick:(UIButton *)sender{ [self youpaifshowUserInfoWithUserId:[NSString stringWithFormat:@"%@",@(sender.tag)]]; } /// 隐藏demoBar - (void)youpaifhideDemoBar{ self.youpaipdemoBar.frame = CGRectMake(0, KScreenHeight - SafeHeight - 182.0f , KScreenWidth, 182.0f); [UIView animateWithDuration:0.25f animations:^{ self.youpaipdemoBar.frame = CGRectMake(0, KScreenHeight , KScreenWidth, 182.0f); } completion:^(BOOL finished) { self.youpaipdemoBarBgV.hidden = YES; }]; } /// 显示demoBar - (void)youpaifshowDemoBar{ [self.view bringSubviewToFront:self.youpaipdemoBarBgV]; self.youpaipdemoBarBgV.hidden = NO; self.youpaipdemoBar.frame = CGRectMake(0, KScreenHeight , KScreenWidth, 182.0f); [UIView animateWithDuration:0.25f animations:^{ self.youpaipdemoBar.frame = CGRectMake(0, KScreenHeight - SafeHeight - 182.0f , KScreenWidth, 182.0f); }]; } #pragma mark - SDCycleScrollViewDelegate //- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{ // //} - (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view{ return [YOUPAILZLiveBoardCycleViewCell class]; } - (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view{ YOUPAILZLiveBoardCycleViewCell *boardCell = (YOUPAILZLiveBoardCycleViewCell *)cell; NSString *type = view.imageURLStringsGroup[index]; [boardCell youpaifreloadWithModel:[self.youpaipliveModel.youpaipanchor_rank_info valueForKey:type] type:type]; @weakify(self); [boardCell setYoupaipclickBlock:^{ @strongify(self); YOUPAILZLiveAnchorHotWindow *memberVc = [[YOUPAILZLiveAnchorHotWindow alloc] init]; memberVc.youpaiplive_id = self.youpaipliveModel.youpaiplive_id; memberVc.isTouchDismiss = YES; memberVc.youpaipisAnchor = YES; [memberVc setSelectedMemberBlock:^(YOUPAILZLiveMemberModel * _Nonnull member) { @strongify(self); [self youpaifshowUserInfoWithUserId:member.youpaipid]; }]; [self TFPresentVC:memberVc completion:^{}]; }]; } #pragma mark - FUAPIDemoBarDelegate -(void)restDefaultValue:(int)type{ if (type == 1) {//美肤 [[FUManager shareManager] setBeautyDefaultParameters:FUBeautyModuleTypeSkin]; } if (type == 2) { [[FUManager shareManager] setBeautyDefaultParameters:FUBeautyModuleTypeShape]; } } /// 滤镜发生变化 -(void)filterValueChange:(FUBeautyParam *)param{ int youpaiphandle = [[FUManager shareManager] getHandleAboutType:FUNamaHandleTypeBeauty]; [FURenderer itemSetParam:youpaiphandle withName:@"filter_name" value:[param.mParam lowercaseString]]; [FURenderer itemSetParam:youpaiphandle withName:@"filter_level" value:@(param.mValue)]; //滤镜程度 [FUManager shareManager].seletedFliter = param; } /// 美颜发生变化 -(void)beautyParamValueChange:(FUBeautyParam *)param{ if (_youpaipdemoBar.selBottomIndex == 3) {//风格栏 if (param.beautyAllparams) { [[FUManager shareManager] setStyleBeautyParams:param.beautyAllparams]; [FUManager shareManager].currentStyle = param; }else{// 点击无 [FUManager shareManager].currentStyle = param; [[FUManager shareManager] loadFilter]; } return; } if ([param.mParam isEqualToString:@"cheek_narrow"] || [param.mParam isEqualToString:@"cheek_small"]){//程度值 只去一半 [[FUManager shareManager] setParamItemAboutType:FUNamaHandleTypeBeauty name:param.mParam value:param.mValue * 0.5]; }else if([param.mParam isEqualToString:@"blur_level"]) {//磨皮 0~6 [[FUManager shareManager] setParamItemAboutType:FUNamaHandleTypeBeauty name:param.mParam value:param.mValue * 6]; }else{ [[FUManager shareManager] setParamItemAboutType:FUNamaHandleTypeBeauty name:param.mParam value:param.mValue]; } } #pragma mark - getter and setter - (FUAPIDemoBar*)youpaipdemoBar{ if (!_youpaipdemoBar) { _youpaipdemoBar = [[FUAPIDemoBar alloc] init]; _youpaipdemoBar.mDelegate = self; } return _youpaipdemoBar; } - (YOUPAILZAnchorMenuView *)youpaipmenuView{ if (!_youpaipmenuView) { _youpaipmenuView = [[YOUPAILZAnchorMenuView alloc] initWithSupView:self.view]; @weakify(self); // 隐藏聊天记录 [_youpaipmenuView setYoupaiphideChatMessageBlock:^{ @strongify(self); [self youpaifhiddenChatList]; }]; // // 更换字体大小 // [_youpaipmenuView setYoupaipreplaceChatMessageFontSizeBlock:^{ // @strongify(self); // self.youpaipliveModel.isMaxFont = !self.youpaipliveModel.isMaxFont; // [self youpaifreloadChatList]; // }]; // 静音 [_youpaipmenuView setYoupaipcloseVoiceBlock:^(BOOL open) { @strongify(self); [self youpaifvoice:open]; }]; // 点击切换摄像头 [_youpaipmenuView setYoupaipchangeCameraBlock:^{ @strongify(self); [self youpaifchangeCamera]; }]; // 点击美颜 [_youpaipmenuView setYoupaipbeautyBlock:^{ @strongify(self); [self youpaifshowDemoBar]; }]; // 结束直播 [_youpaipmenuView setYoupaipcloseBlock:^{ @strongify(self); [self youpaifendLive]; }]; // 背景音乐 [_youpaipmenuView setShowMusicBlock:^{ @strongify(self); YOUPAILZLiveMusicListWindow *vc = [[YOUPAILZLiveMusicListWindow alloc] init]; vc.youpaipcurrentMusic = self.currentMusic; vc.showLyric = self.youpaipmusicPlayerView.showLyric; vc.youpaipmusicList = self.youpaipmusicList; // vc.youpaipmusicPlayState = self.youpaipmusicPlayState; // 播放音乐 [vc setYoupaipplayMusicBlock:^(YOUPAILZMusicListItemModel * _Nonnull model) { @strongify(self); if (![model.youpaipsongCode isEqual: self.currentMusic.youpaipsongCode]) { self.currentMusic = model; [self youpaifloadMusicInfoWithModel:self.currentMusic]; } }]; // 暂停or播放 [vc setYoupaipsuspendMusicBlock:^{ @strongify(self); // if (self.youpaipmusicPlayState == AgoraAudioMixingStatePlaying) { // [self.youpaipagoraKit pauseAudioMixing]; // }else{ // [self.youpaipagoraKit resumeAudioMixing]; // } }]; // 下一首 [vc setYoupaipnextMusicBlock:^{ @strongify(self); [self youpaifnextMusic]; }]; // 是否展示歌词 [vc setShowLyricBlock:^(BOOL show) { @strongify(self); self.youpaipmusicPlayerView.showLyric = show; }]; // 退出 [vc setYoupaipcloseBlock:^{ @strongify(self); self.youpaipmusicPlayerView.hidden = YES; [self.youpaipagoraKit stopAudioMixing]; }]; ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc] initWithRootViewController:vc]; [self TFPresentViewController:nav presentSize:CGSizeMake(KScreenWidth, KScreenHeight * 0.6f) direction:TFDirectionBottom completion:^{}]; }]; // 成员管理 [_youpaipmenuView setShowMemberManage:^{ @strongify(self); [self youpaifshowMemberManageAlert]; }]; } return _youpaipmenuView; } /// 下一首音乐 - (void)youpaifnextMusic{ if (self.youpaipmusicList.count == 0) { return; } if ([self.youpaipmusicList containsObject:self.currentMusic]) { NSInteger index = [self.youpaipmusicList indexOfObject:self.currentMusic]; if (index + 1 < self.youpaipmusicList.count) { self.currentMusic = self.youpaipmusicList[index + 1]; [self youpaifloadMusicInfoWithModel:self.currentMusic]; }else{ self.currentMusic = self.youpaipmusicList[0]; [self youpaifloadMusicInfoWithModel:self.currentMusic]; } }else{ self.currentMusic = self.youpaipmusicList[0]; [self youpaifloadMusicInfoWithModel:self.currentMusic]; } } /// 获取音乐信息 - (void)youpaifloadMusicInfoWithModel:(YOUPAILZMusicListItemModel *)model{ /* [[NSNotificationCenter defaultCenter] postNotificationName:@"CurrentMusicChangeNotification" object:model userInfo:nil]; @weakify(self); [LCHttpHelper requestWithURLString:MusicInfo parameters:@{@"musicId":model.youpaipsongCode} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSLog(@"-----%@",[dict objectForKey:@"data"]); YOUPAILZMusicModel *youpaipmusicModel = [YOUPAILZMusicModel mj_objectWithKeyValues:[dict objectForKey:@"data"]]; youpaipmusicModel.youpaipmusicName = model.youpaipname; if (model.youpaipposter.length != 0) { youpaipmusicModel.youpaipcover = model.youpaipposter; } if (youpaipmusicModel.youpaipdynamicLyricUrl.length != 0) { dispatch_queue_t queue = dispatch_get_global_queue(0, 0); dispatch_async(queue, ^{ NSString *lrcStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:youpaipmusicModel.youpaipdynamicLyricUrl] encoding:NSUTF8StringEncoding error:nil]; [youpaipmusicModel youpaifparseLrc:lrcStr]; dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self); self.youpaipmusicPlayerView.hidden = NO; [self.youpaipmusicPlayerView youpaifreloadMusicModel:youpaipmusicModel]; [self youpaifstartPlayMusicWithPath:youpaipmusicModel.youpaipfileUrl]; }); }); }else{ self.youpaipmusicPlayerView.hidden = NO; youpaipmusicModel.youpaipwordArray = @[youpaipmusicModel.youpaipmusicName,@""].mutableCopy; [self.youpaipmusicPlayerView youpaifreloadMusicModel:youpaipmusicModel]; [self youpaifstartPlayMusicWithPath:youpaipmusicModel.youpaipfileUrl]; } }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; */ } /// 播放音乐 - (void)youpaifstartPlayMusicWithPath:(NSString *)path{ // 设置是否只在本地播放音乐文件。true 表示只有本地用户能听到音乐;false 表示本地用户和远端用户都能听到音乐。 BOOL youpaiploopback = NO; // 设置是否用音乐文件替换麦克风采集的音频。true 表示用户只能听到音乐;false 表示用户可以听到音乐和麦克风采集的音频。 BOOL youpaipreplace = NO; // 设置音乐文件的播放次数。1 表示播放 1 次。 NSInteger cycle = 1; // [self.youpaipagoraKit startAudioMixing:path loopback:youpaiploopback replace:youpaipreplace cycle:cycle]; // 调节音乐文件的播放音量 [self.youpaipagoraKit adjustAudioMixingVolume:50]; } /// 设置用户角色 - (AgoraClientRole)youpaifclientRole{ return AgoraClientRoleBroadcaster; } /// 结束直播 - (void)youpaifendLive{ @weakify(self); LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) { }]; cancelAction.cornerRadius = 24.0f; cancelAction.bgColor = HexColorFromRGB(0x9F9DA5); LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确认" handler:^(LZAlertAction *action) { @strongify(self); [self youpaifrequestCloseLiveData]; }]; confimAction.cornerRadius = 24.0f; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"是否要结束直播" action:@[cancelAction,confimAction]]; alert.contentTextAlignment = NSTextAlignmentCenter; [self TFPresentVC:alert completion:^{}]; } bool youpaipisShowRePKAlert = NO; /// 被连麦者获取连麦或pk信息 - (void)youpaifrequestObtainInteractWithPkId:(NSString *)pkId type:(LZLiveInviteType)type{ @weakify(self); [LCHttpHelper requestWithURLString:ObtainInteract parameters:@{@"pk_id":pkId} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { YOUPAILZLiveStartPKModel *model = [YOUPAILZLiveStartPKModel mj_objectWithKeyValues:[dict objectForKey:@"data"]]; if (self.youpaipstartPKModel != nil && ![self.youpaipstartPKModel.youpaippk_id isEqual:model.youpaippk_id]) { if (youpaipisShowRePKAlert == NO) { youpaipisShowRePKAlert = YES; LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"拒绝" handler:^(LZAlertAction *action) { youpaipisShowRePKAlert = NO; [LCHttpHelper requestWithURLString:ReFusePK parameters:@{@"pk_id":model.youpaippk_id} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; }]; cancelAction.cornerRadius = 24.0f; cancelAction.bgColor = HexColorFromRGB(0x9F9DA5); LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"接受" handler:^(LZAlertAction *action) { @strongify(self); youpaipisShowRePKAlert = NO; NSDictionary *params = @{@"pk_id":self.youpaipstartPKModel.youpaippk_id,@"new_pk_id":model.youpaippk_id}; self.youpaipstartPKModel = model; [LCHttpHelper requestWithURLString:ReceiveRestartPK parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; }]; confimAction.cornerRadius = 24.0f; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"对方邀请您重新PK" action:@[cancelAction,confimAction]]; alert.contentTextAlignment = NSTextAlignmentCenter; [self TFPresentVC:alert completion:^{}]; } }else{ YOUPAILZLiveCallWindow *vc = [[YOUPAILZLiveCallWindow alloc] initWithState:LZLiveInviteStateAnswer type:type model:model]; vc.isTouchDismiss = NO; [vc setYoupaipstartConnectBlock:^(YOUPAILZLiveStartPKModel * _Nonnull model) { @strongify(self); self.youpaipstartPKModel = model; self.youpaipinviteType = type; [self youpaifforwardChannel]; }]; [self TFPresentVC:vc completion:^{}]; } }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } /// 开始连麦/PK - (void)youpaifrequestLianMaiOrPKWithType:(LZLiveInviteType)type model:(YOUPAILZLiveInviteModel *)model{ NSDictionary *params = @{ @"room_id":model.youpaiproom_id, @"type":type == LZLiveInviteTypePK ? @"pk" : @"lianmai" }; @weakify(self); [LCHttpHelper requestWithURLString:StartInteract parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { YOUPAILZLiveStartPKModel *model = [YOUPAILZLiveStartPKModel mj_objectWithKeyValues:[dict objectForKey:@"data"]]; self.youpaipstartPKModel = model; YOUPAILZLiveCallWindow *vc = [[YOUPAILZLiveCallWindow alloc] initWithState:LZLiveInviteStateCall type:type model:model]; vc.isTouchDismiss = NO; [self TFPresentVC:vc completion:^{}]; }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } /// 挂断连麦/PK - (void)youpaifhangupLianMaiOrPK{ NSDictionary *params = @{ @"pk_id":self.youpaipstartPKModel.youpaippk_id, @"event":@"hangup" }; NSString *api = OperateFrom; if (self.youpaipstartPKModel.youpaipfrom_roomid.length != 0) { api = OperateTo; } [LCHttpHelper requestWithURLString:api parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)youpaifrequestCloseLiveData{ @weakify(self); [LCHttpHelper requestWithURLString:CloseLive parameters:@{@"id":self.youpaipliveModel.youpaiplive_id} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [LCSaveData saveIsVideo:NO]; YOUPAILZLiveCloseModel *model = [YOUPAILZLiveCloseModel mj_objectWithKeyValues:[dict objectForKey:@"data"]]; [self youpaifleaveChannel]; YOUPAILZAnchorLiveCloseVC *vc = [[YOUPAILZAnchorLiveCloseVC alloc] init]; vc.youpaipmodel = model; vc.hidesBottomBarWhenPushed = YES; NSArray *vcs = self.navigationController.viewControllers; NSMutableArray *nVcs = [NSMutableArray array]; BOOL youpaipisContainsCloseVC = NO; for (UIViewController *fvc in vcs) { if ([fvc isKindOfClass:[YOUPAILZAnchorLiveCloseVC class]]) { youpaipisContainsCloseVC = YES; } } if (!youpaipisContainsCloseVC) { for (UIViewController *fvc in vcs) { if (!([fvc isKindOfClass:[YOUPAILZLiveAnchorVC class]] || [fvc isKindOfClass:[YOUPAILZAnchorLiveCloseVC class]])) { [nVcs addObject:fvc]; } } [nVcs addObject:vc]; [self.navigationController setViewControllers:nVcs.copy animated:YES]; } }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } /// 顶部榜单相关函数 - (void)youpaifeditBtnCountWithCount:(NSInteger)count{ if (count >= self.youpaipmemberBtns.count) { [self youpaifaddBtnWithCount:count - self.youpaipmemberBtns.count]; }else{ [self youpaifdeleteBtnWithCount:self.youpaipmemberBtns.count - count]; } } - (void)youpaifdeleteBtnWithCount:(NSInteger)count{ if (count != 0) { for (NSInteger i = 0; i < count; i ++) { YOUPAILZLiveMemberButton *btn = self.youpaipmemberBtns.lastObject; [self.youpaipmemberBtns removeLastObject]; [btn removeFromSuperview]; } } } - (void)youpaifaddBtnWithCount:(NSInteger)count{ for (NSInteger i = 0; i < count; i ++) { [self youpaifcreateBtn]; } } - (void)youpaifcreateBtn{ YOUPAILZLiveMemberButton *btn = [[YOUPAILZLiveMemberButton alloc] init]; btn.imageView.contentMode = UIViewContentModeScaleAspectFill; btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill; btn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill; // btn.layer.cornerRadius = 3.0f; // btn.clipsToBounds = YES; [self.youpaiprankBgV addSubview:btn]; [self.youpaipmemberBtns addObject:btn]; } - (NSMutableArray *)youpaipmemberBtns{ if (!_youpaipmemberBtns) { _youpaipmemberBtns = [NSMutableArray array]; } return _youpaipmemberBtns; } - (NSMutableArray *)youpaipmusicList{ if (!_youpaipmusicList) { _youpaipmusicList = [NSMutableArray array]; } return _youpaipmusicList; } @end