YOUPAILZLiveAnchorVC.m 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  1. //
  2. // YOUPAILZLiveAnchorVC.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/5/8.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZLiveAnchorVC.h"
  9. //#import "FUAPIDemoBar.h"
  10. //#import "FUManager.h"
  11. #import "YOUPAILZStartLiveView.h"
  12. #import "YOUPAILZAnchorMenuView.h"
  13. #import "LZAlertWindow.h"
  14. #import "UIViewController+TFPresent.h"
  15. #import "YOUPAILZAnchorLiveCloseVC.h"
  16. #import "YOUPAILZLiveInviteVC.h"
  17. #import "YOUPAILZLiveCallWindow.h"
  18. #import "YOUPAILZLiveStartPKModel.h"
  19. #import "YOUPAILZLiveMemberListVC.h"
  20. #import "YOUPAILZLiveMusicListWindow.h"
  21. #import "YOUPAILZMusicModel.h"
  22. #import "YOUPAILZMusicPlayerView.h"
  23. #import "SDCycleScrollView.h"
  24. #import "YOUPAILZLiveBoardCycleViewCell.h"
  25. #import "YOUPAILZLiveMemberButton.h"
  26. #import "YOUPAILZLiveAnchorHotWindow.h"
  27. #import "YOUPAILZCommonGiftView.h"
  28. #import "PFAPIDemoBar.h"
  29. #import "PFDateHandle.h"
  30. #import <PixelFree/SMPixelFree.h>
  31. @interface YOUPAILZLiveAnchorVC ()<PFAPIDemoBarDelegate,SDCycleScrollViewDelegate>
  32. @property(nonatomic, strong) PFAPIDemoBar *beautyEditView;
  33. @property (nonatomic, strong) NSUserDefaults *def;
  34. @property (nonatomic,strong) SMPixelFree *mPixelFree;
  35. @property (nonatomic,assign)BOOL clickCompare;
  36. @property (nonatomic, weak) UIView *youpaipdemoBarBgV;
  37. @property (nonatomic, weak) UIButton *youpaipsendMessageBtn; // 发送消息按钮
  38. @property (nonatomic, weak) UIButton *youpaipvoiceBtn; // 喇叭按钮
  39. @property (nonatomic, weak) UIButton *youpaipbeautyBtn; // 美颜按钮
  40. @property (nonatomic, weak) UIButton *youpaipchangeCameraBtn; // 切换摄像头
  41. @property (nonatomic, weak) YOUPAILZStartLiveView *youpaipstartLiveView; // 开始直播页面
  42. @property (nonatomic, weak) UILabel *youpaipliveMemberCountL; // 直播人数
  43. @property (nonatomic, strong) NSMutableArray <YOUPAILZLiveMemberButton *> *youpaipmemberBtns; ///直播榜单人数
  44. @property (nonatomic, weak) UIView *youpaiprankBgV; // 排行背景View
  45. @property (nonatomic, weak) SDCycleScrollView *youpaipboardCycleView; // 当前直播间上榜信息View
  46. @property (nonatomic, weak) UILabel *youpaipfansCountL; // 粉丝数
  47. @property (nonatomic, weak) UIButton *youpaiplianmaiBtn; // 连麦按钮
  48. @property (nonatomic, weak) UIButton *youpaippkBtn; // pk按钮
  49. @property (nonatomic, weak) UIButton *youpaiprePKBtn; // 重新PK按钮
  50. @property (nonatomic, strong)YOUPAILZLiveStartPKModel *youpaipstartPKModel;
  51. @property (nonatomic, assign)LZLiveInviteType youpaipinviteType;
  52. @property (nonatomic, strong) YOUPAILZAnchorMenuView *youpaipmenuView;
  53. @property (nonatomic, assign) LZLivePKState youpaippkState;
  54. @property (nonatomic, strong) NSMutableArray <YOUPAILZMusicListItemModel *> *youpaipmusicList; // 歌单
  55. @property (nonatomic, strong) YOUPAILZMusicListItemModel *currentMusic; // 当前音乐
  56. //@property (nonatomic, assign) AgoraAudioMixingStateCode youpaipmusicPlayState; // 音乐播放状态
  57. @property (nonatomic, weak) YOUPAILZMusicPlayerView *youpaipmusicPlayerView; // 音乐-歌词展示
  58. @property (nonatomic, assign) CGFloat youpaipmusicPlayerViewY;
  59. @end
  60. @implementation YOUPAILZLiveAnchorVC
  61. - (void)dealloc{
  62. NSString *cls = NSStringFromClass([self class]);
  63. NSLog(@"销毁:--%@ dealloc",cls);
  64. }
  65. - (void)viewWillAppear:(BOOL)animated{
  66. [super viewWillAppear:animated];
  67. // [IQKeyboardManager sharedManager].enable = NO;
  68. // [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  69. [LCSaveData saveIsVideo:YES];
  70. }
  71. - (void)viewWillDisappear:(BOOL)animated{
  72. [super viewWillDisappear:animated];
  73. // [IQKeyboardManager sharedManager].enable = YES;
  74. // [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
  75. }
  76. - (void)viewDidDisappear:(BOOL)animated{
  77. [super viewDidDisappear:animated];
  78. [self youpaifstopMusicPlayer];
  79. [[NSNotificationCenter defaultCenter] removeObserver:self];
  80. }
  81. - (void)youpaifstopMusicPlayer{
  82. [self.youpaipmusicPlayerView youpaifstopTimer];
  83. [self.youpaipmusicPlayerView removeFromSuperview];
  84. self.youpaipmusicPlayerView = nil;
  85. }
  86. - (void)viewDidLoad {
  87. [self youpaifsetupBeautyBar];
  88. [super viewDidLoad];
  89. [self youpaifsetupStartLiveView];
  90. [self youpaifhandleBlock];
  91. }
  92. /// 女神直播回调
  93. - (void)youpaifhandleBlock{
  94. @weakify(self);
  95. [self setYoupaipliveCloseBlock:^{
  96. @strongify(self);
  97. [self youpaifrequestCloseLiveData];
  98. }];
  99. [self setYoupaippkBlock:^(YOUPAILZLivePKAttachment * _Nonnull pkAttachment) {
  100. @strongify(self);
  101. [self youpaifhandlePKOrLianMaiWithTypeStr:pkAttachment.type pkid:pkAttachment.id type:LZLiveInviteTypePK OperateUid:pkAttachment.operate_uid];
  102. }];
  103. [self setYoupaiplianmaiBlock:^(YOUPAILZLiveLianMaiAttachment * _Nonnull lianmaiAttachment) {
  104. @strongify(self);
  105. [self youpaifhandlePKOrLianMaiWithTypeStr:lianmaiAttachment.type pkid:lianmaiAttachment.id type:LZLiveInviteTypeLianMai OperateUid:lianmaiAttachment.operate_uid];
  106. }];
  107. [self.youpaippkdataView setCurrentPKStateBlock:^(LZLivePKState state) {
  108. @strongify(self);
  109. self.youpaippkState = state;
  110. }];
  111. [self.youpaippkdataView setShowRePKBlock:^(BOOL show) {
  112. @strongify(self);
  113. self.youpaiprePKBtn.hidden = !show;
  114. }];
  115. [self setYoupaipremoteVideoCloseBlock:^{
  116. @strongify(self);
  117. self.youpaippkdataView.youpaipisStartPK = NO;
  118. self.youpaiprePKBtn.hidden = YES;
  119. }];
  120. [self setYoupaipresetPKDataBlock:^(YOUPAILZLivePKDataAttachment * _Nonnull attachment) {
  121. @strongify(self);
  122. self.youpaipstartPKModel.youpaippk_id = attachment.id;
  123. }];
  124. [self setYoupaipmusicPlayFinishBlock:^{
  125. @strongify(self);
  126. [self youpaifnextMusic];
  127. }];
  128. // [self setYoupaipmusicPlayStateBlock:^(AgoraAudioMixingStateCode stateCode) {
  129. // @strongify(self);
  130. // self.youpaipmusicPlayState = stateCode;
  131. // [[NSNotificationCenter defaultCenter] postNotificationName:@"MusicPlayStateChangeNotification" object:@(self.youpaipmusicPlayState) userInfo:nil];
  132. // }];
  133. [self setYoupaipclickRemoteVideoViewBlock:^(NSString * _Nonnull uid, NSString * _Nonnull room_id) {
  134. @strongify(self);
  135. if (uid.length != 0) {
  136. [self youpaifshowUserInfoWithUserId:uid];
  137. }
  138. }];
  139. }
  140. /// 根据类型处理PK、连麦
  141. - (void)youpaifhandlePKOrLianMaiWithTypeStr:(NSString *)typeStr pkid:(NSString *)pkid type:(LZLiveInviteType)type OperateUid:(NSString *)operateUid{
  142. if ([typeStr isEqual:@"call"]) {
  143. [self youpaifrequestObtainInteractWithPkId:pkid type:type];
  144. }else if ([typeStr isEqual:@"timeout"]){
  145. [ZCHUDHelper showTitle:@"已超时"];
  146. [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil];
  147. }else if ([typeStr isEqual:@"cancel"]){
  148. [ZCHUDHelper showTitle:@"对方已取消"];
  149. [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil];
  150. }else if ([typeStr isEqual:@"hangup"]){
  151. self.youpaipstartPKModel = nil;
  152. if ([self.youpaipliveModel.youpaipuser_info.youpaipuser_id isEqual:operateUid]) {
  153. [ZCHUDHelper showTitle:@"已挂断"];
  154. }else{
  155. [ZCHUDHelper showTitle:@"对方已挂断"];
  156. }
  157. [self.youpaipagoraKit stopChannelMediaRelay];
  158. if (self.youpaipinviteType == LZLiveInviteTypePK) {
  159. [self.youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateNormal];
  160. [self.youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateHighlighted];
  161. self.youpaippkBtn.selected = NO;
  162. }else{
  163. [self.youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateNormal];
  164. [self.youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateHighlighted];
  165. self.youpaiplianmaiBtn.selected = NO;
  166. }
  167. }else if ([typeStr isEqual:@"refuse"]){
  168. [ZCHUDHelper showTitle:@"对方已拒绝"];
  169. [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil];
  170. }else if ([typeStr isEqual:@"agree"]){
  171. self.youpaipinviteType = type;
  172. [self youpaifforwardChannel];
  173. [[NSNotificationCenter defaultCenter] postNotificationName:@"RemoveLiveCallWindow" object:nil];
  174. }
  175. }
  176. /// 设置开始直播页面
  177. - (void)youpaifsetupStartLiveView{
  178. YOUPAILZStartLiveView *youpaipstartLiveView = [[YOUPAILZStartLiveView alloc] initWithFrame:self.view.bounds shareModel:self.youpaipshareModel youpaipcover:self.youpaipcover];
  179. [self.view addSubview:youpaipstartLiveView];
  180. self.youpaipstartLiveView = youpaipstartLiveView;
  181. @weakify(self);
  182. [youpaipstartLiveView setYoupaipcloseClickBlock:^{
  183. @strongify(self);
  184. [self.youpaipmCamera stopCapture];
  185. [LCSaveData saveIsVideo:NO];
  186. self.youpaipagoraKit.delegate = nil;
  187. self.youpaipagoraKit = nil;
  188. [self.navigationController popViewControllerAnimated:YES];
  189. }];
  190. [youpaipstartLiveView setYoupaipchangeCameraClickBlock:^{
  191. @strongify(self);
  192. [self youpaifchangeCamera];
  193. }];
  194. [youpaipstartLiveView setYoupaipbeautyClickBlock:^{
  195. @strongify(self);
  196. [self youpaifshowDemoBar];
  197. }];
  198. [youpaipstartLiveView setYoupaipstartLiveClickBlock:^(YOUPAILZLiveModel * _Nonnull youpaipliveModel) {
  199. @strongify(self);
  200. self.youpaipliveModel = youpaipliveModel;
  201. self.youpaippkdataView.youpaipmodel = youpaipliveModel;
  202. [self youpaifjoin];
  203. [self.youpaipstartLiveView removeFromSuperview];
  204. [self youpaifsetupChatMessageView];
  205. [self youpaifsetupHeaderView];
  206. [self youpaifsetupFooterView];
  207. [self youpaifsetupMusicPlayerView];
  208. [self youpaifloadAdvertRecharge];
  209. }];
  210. }
  211. /// 音乐-歌词展示
  212. - (void)youpaifsetupMusicPlayerView{
  213. @weakify(self);
  214. YOUPAILZMusicPlayerView *youpaipmusicPlayerView = [[YOUPAILZMusicPlayerView alloc]initWithFrame:CGRectMake(self.youpaipchatBgView.mj_w * 0.4f, KScreenHeight / 2.0f, self.youpaipchatBgView.mj_w * 0.6f, 68.0f)];
  215. youpaipmusicPlayerView.hidden = YES;
  216. youpaipmusicPlayerView.showLyric = YES;
  217. [youpaipmusicPlayerView setGetPlayPositionBlock:^NSInteger{
  218. @strongify(self);
  219. return [self.youpaipagoraKit getAudioMixingCurrentPosition];
  220. }];
  221. // 暂停or播放
  222. [youpaipmusicPlayerView setYoupaipsuspendMusicBlock:^{
  223. @strongify(self);
  224. // if (self.youpaipmusicPlayState == AgoraAudioMixingStatePlaying) {
  225. // [self.youpaipagoraKit pauseAudioMixing];
  226. // }else{
  227. // [self.youpaipagoraKit resumeAudioMixing];
  228. // }
  229. }];
  230. [self.youpaipchatBgView addSubview:youpaipmusicPlayerView];
  231. self.youpaipmusicPlayerView = youpaipmusicPlayerView;
  232. UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifmusicHandlePan:)];
  233. [youpaipmusicPlayerView addGestureRecognizer:panGestureRecognizer];
  234. }
  235. - (void)youpaifmusicHandlePan:(UIPanGestureRecognizer*)recognizer{
  236. CGPoint translation = [recognizer translationInView:self.view];
  237. if(recognizer.state == UIViewAnimatingPositionStart){
  238. self.youpaipmusicPlayerViewY = self.youpaipmusicPlayerView.mj_y;
  239. }else if (recognizer.state == UIGestureRecognizerStateChanged) {
  240. self.youpaipmusicPlayerView.mj_y = self.youpaipmusicPlayerViewY + translation.y;
  241. }else if(recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) {
  242. [UIView animateWithDuration:0.25f animations:^{
  243. if (self.youpaipmusicPlayerView.mj_y < NavBarHeight) {
  244. self.youpaipmusicPlayerView.mj_y = NavBarHeight;
  245. }else if (self.youpaipmusicPlayerView.mj_y > KScreenHeight - TabbarHeight - self.youpaipmusicPlayerView.mj_h){
  246. self.youpaipmusicPlayerView.mj_y = KScreenHeight - TabbarHeight - self.youpaipmusicPlayerView.mj_h;
  247. }
  248. }];
  249. }
  250. }
  251. /// 设置美颜工具
  252. - (void)youpaifsetupBeautyBar{
  253. // 美颜工具
  254. [self.view layoutIfNeeded];
  255. self.def = [NSUserDefaults standardUserDefaults];
  256. [self initPixelFree];
  257. [self setDefaultParam];
  258. }
  259. #pragma mark 澜极美颜--start
  260. -(PFAPIDemoBar *)beautyEditView {
  261. if (!_beautyEditView) {
  262. _beautyEditView = [[PFAPIDemoBar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 280, self.view.frame.size.width, 280)];
  263. _beautyEditView.mDelegate = self;
  264. }
  265. return _beautyEditView ;
  266. }
  267. -(void)comparisonButtonDidClick:(BOOL)state{
  268. self.clickCompare = state;
  269. }
  270. -(void)writeData:(NSData *)data fileName:(NSString *)fileName{
  271. NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  272. NSString *documentDirectory = [documentDirectories objectAtIndex:0];
  273. // 获取目标文件的完整路径
  274. NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
  275. // [[NSFileManager defaultManager] fileExistsAtPath:filePath];
  276. // 创建文件并覆盖写入数据
  277. BOOL success = [[NSFileManager defaultManager] createFileAtPath:filePath
  278. contents:data
  279. attributes:nil];
  280. if (success) {
  281. NSLog(@"数据写入成功");
  282. } else {
  283. NSLog(@"数据写入失败");
  284. }
  285. }
  286. -(NSData *)readDatafileName:(NSString *)fileName{
  287. NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  288. NSString *documentDirectory = [documentDirectories objectAtIndex:0];
  289. // 获取目标文件的完整路径
  290. NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
  291. NSData *data = [NSData dataWithContentsOfFile:filePath];
  292. return data;
  293. }
  294. -(void)initPixelFree{
  295. NSString *face_FiltePath = [[NSBundle mainBundle] pathForResource:@"filter_model.bundle" ofType:nil];
  296. NSString *authFile = [[NSBundle mainBundle] pathForResource:@"pixelfreeAuth.lic" ofType:nil];
  297. self.mPixelFree = [[SMPixelFree alloc] initWithProcessContext:nil srcFilterPath:face_FiltePath authFile:authFile];
  298. [self.view addSubview:self.beautyEditView];
  299. self.beautyEditView.hidden = YES;
  300. }
  301. -(void)setDefaultParam{
  302. NSArray<PFBeautyParam *>* defaultData = [PFDateHandle setupShapData];
  303. NSArray<PFBeautyParam *>* defaultSkinData = [PFDateHandle setupSkinData];
  304. NSArray<PFBeautyParam *>* defaultfiltersData = [PFDateHandle setupFilterData];
  305. NSArray<PFBeautyParam *>* defaultfaceData = [PFDateHandle setupFaceType];
  306. // 读本地缓存
  307. NSData *data = [self readDatafileName:@"shapeParamsData"];
  308. if (data) {
  309. defaultData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  310. }
  311. data = [self readDatafileName:@"skinParamsData"];
  312. if (data) {
  313. defaultSkinData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  314. }
  315. data = [self readDatafileName:@"filtersParamsData"];
  316. if (data) {
  317. defaultfiltersData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  318. }
  319. data = [self readDatafileName:@"oneKeyParamsData"];
  320. if (data) {
  321. defaultfaceData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  322. }
  323. // 更新 UI
  324. self.beautyEditView.shapeParams = defaultData;
  325. self.beautyEditView.skinParams = defaultSkinData;
  326. self.beautyEditView.filtersParams = defaultfiltersData;
  327. self.beautyEditView.faceTypeParams = defaultfaceData;
  328. NSUserDefaults*userDefaults = [NSUserDefaults standardUserDefaults];
  329. int oneKeyType = (int)[userDefaults integerForKey:@"oneKeyType"];
  330. int filtersIndex = (int)[userDefaults integerForKey:@"filtersUseIndex"];
  331. self.beautyEditView.oneKeyType = oneKeyType;
  332. self.beautyEditView.filterIndex = filtersIndex;
  333. [self.beautyEditView updateDemoBar];
  334. // 更新 SDK 设置
  335. for (PFBeautyParam *param in defaultData) {
  336. [self filterValueChange:param];
  337. }
  338. for (PFBeautyParam *param in defaultSkinData) {
  339. [self filterValueChange:param];
  340. }
  341. PFBeautyParam *param = defaultfaceData[oneKeyType];
  342. [self filterValueChange:param];
  343. param = defaultfiltersData[filtersIndex];
  344. [self filterValueChange:param];
  345. }
  346. -(void)filterValueChange:(PFBeautyParam *)param{
  347. CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
  348. float value = param.mValue;
  349. if(param.type == FUDataTypeBeautify){
  350. if ([param.mParam isEqualToString:@"face_EyeStrength"]) {
  351. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_EyeStrength value:&value];
  352. }
  353. if ([param.mParam isEqualToString:@"face_thinning"]) {
  354. float aa = param.mValue;
  355. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_thinning value:&value];
  356. }
  357. if ([param.mParam isEqualToString:@"face_narrow"]) {
  358. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_narrow value:&value];
  359. }
  360. if ([param.mParam isEqualToString:@"face_chin"]) {
  361. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_chin value:&value];
  362. }
  363. if ([param.mParam isEqualToString:@"face_V"]) {
  364. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_V value:&value];
  365. }
  366. if ([param.mParam isEqualToString:@"face_small"]) {
  367. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_small value:&value];
  368. }
  369. if ([param.mParam isEqualToString:@"face_nose"]) {
  370. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_nose value:&value];
  371. }
  372. if ([param.mParam isEqualToString:@"face_forehead"]) {
  373. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_forehead value:&value];
  374. }
  375. if ([param.mParam isEqualToString:@"face_mouth"]) {
  376. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_mouth value:&value];
  377. }
  378. if ([param.mParam isEqualToString:@"face_philtrum"]) {
  379. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_philtrum value:&value];
  380. }
  381. if ([param.mParam isEqualToString:@"face_long_nose"]) {
  382. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_long_nose value:&value];
  383. }
  384. if ([param.mParam isEqualToString:@"face_eye_space"]) {
  385. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_space value:&value];
  386. }
  387. if ([param.mParam isEqualToString:@"face_smile"]) {
  388. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_smile value:&value];
  389. }
  390. if ([param.mParam isEqualToString:@"face_eye_rotate"]) {
  391. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_rotate value:&value];
  392. }
  393. if ([param.mParam isEqualToString:@"face_canthus"]) {
  394. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_canthus value:&value];
  395. }
  396. if ([param.mParam isEqualToString:@"runddy"]) {
  397. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceRuddyStrength value:&value];
  398. }
  399. if ([param.mParam isEqualToString:@"writen"]) {
  400. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceWhitenStrength value:&value];
  401. }
  402. if ([param.mParam isEqualToString:@"blur"]) {
  403. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceBlurStrength value:&value];
  404. }
  405. if ([param.mParam isEqualToString:@"sharpen"]) {
  406. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceSharpenStrength value:&value];
  407. }
  408. if ([param.mParam isEqualToString:@"newWhitenStrength"]) {
  409. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceM_newWhitenStrength value:&value];
  410. }
  411. if ([param.mParam isEqualToString:@"qualityStrength"]) {
  412. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceH_qualityStrength value:&value];
  413. }
  414. }
  415. if (param.type == FUDataTypeFilter) {
  416. const char *aaa = [param.mParam UTF8String];
  417. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterName value:(void *)aaa];
  418. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterStrength value:&value];
  419. }
  420. if (param.type == FUDataTypeStickers) {
  421. if([param.mParam isEqualToString:@"origin"]){
  422. [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:NULL];
  423. } else{
  424. // NSString *path = [[NSBundle mainBundle] pathForResource:@"Stickers" ofType:nil];
  425. // NSString *currentFolder = [path stringByAppendingPathComponent:param.mParam];
  426. // const char *aaa = [currentFolder UTF8String];
  427. // [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)aaa];
  428. NSString *name = [NSString stringWithFormat:@"%@.bundle",param.mParam];
  429. NSString *paths = [[NSBundle mainBundle] pathForResource:name ofType:nil];
  430. [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)[paths UTF8String]];
  431. }
  432. }
  433. if (param.type == FUDataTypeOneKey) {
  434. if ([param.mTitle isEqualToString:@"origin"]) {
  435. int value = PFBeautyTypeOneKeyNormal;
  436. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  437. }
  438. if ([param.mTitle isEqualToString:@"自然"]) {
  439. int value = PFBeautyTypeOneKeyNatural;
  440. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  441. }
  442. if ([param.mTitle isEqualToString:@"可爱"]) {
  443. int value = PFBeautyTypeOneKeyCute;
  444. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  445. }
  446. if ([param.mTitle isEqualToString:@"女神"]) {
  447. int value = PFBeautyTypeOneKeyGoddess;
  448. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  449. }
  450. if ([param.mTitle isEqualToString:@"白净"]) {
  451. int value = PFBeautyTypeOneKeyFair;
  452. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  453. }
  454. }
  455. }
  456. -(void)bottomDidChange:(int)index{
  457. if (index != 0 && _beautyEditView.oneKeyType != PFBeautyTypeOneKeyNormal) {
  458. int value = PFBeautyTypeOneKeyNormal;
  459. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  460. [self showDelayedAlert];
  461. _beautyEditView.oneKeyType = PFBeautyTypeOneKeyNormal;
  462. }
  463. }
  464. - (void)showDelayedAlert {
  465. // 创建 UIAlertController
  466. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"一键美颜已关闭" preferredStyle:UIAlertControllerStyleAlert];
  467. dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
  468. dispatch_after(delay, dispatch_get_main_queue(), ^{
  469. [alertController dismissViewControllerAnimated:YES completion:nil];
  470. });
  471. [self presentViewController:alertController animated:YES completion:nil];
  472. }
  473. #pragma mark 澜极美颜--end
  474. /// 设置headerView
  475. - (void)youpaifsetupHeaderView{
  476. UIView *headerView = [[UIView alloc] init];
  477. [self.view addSubview:headerView];
  478. [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
  479. make.left.offset(0.0f);
  480. make.height.offset(70.0f);
  481. make.top.offset(StatusBarHeight);
  482. }];
  483. UIButton *anchorInfoBgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  484. anchorInfoBgBtn.layer.cornerRadius = 17.5f;
  485. anchorInfoBgBtn.clipsToBounds = YES;
  486. anchorInfoBgBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
  487. anchorInfoBgBtn.tag = [self.youpaipliveModel.youpaipuser_info.youpaipuser_id integerValue];
  488. [anchorInfoBgBtn addTarget:self action:@selector(youpaifshowUserInfoClick:) forControlEvents:UIControlEventTouchUpInside];
  489. [headerView addSubview:anchorInfoBgBtn];
  490. [anchorInfoBgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  491. make.left.offset(12.0f);
  492. make.top.offset(5.0f);
  493. make.height.offset(35.0f);
  494. make.width.lessThanOrEqualTo(140.0f);
  495. make.right.offset(0.0f);
  496. }];
  497. UIImageView *youpaipavatarImgV = [[UIImageView alloc] init];
  498. youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill;
  499. youpaipavatarImgV.layer.cornerRadius = 16.5f;
  500. youpaipavatarImgV.clipsToBounds = YES;
  501. [youpaipavatarImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipliveModel.youpaipuser_info.youpaipavatar]];
  502. [anchorInfoBgBtn addSubview:youpaipavatarImgV];
  503. [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  504. make.left.top.offset(1.0f);
  505. make.size.mas_offset(CGSizeMake(33.0f, 33.0f));
  506. }];
  507. UIImageView *anchorTagImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_anchor_vlog"]];
  508. [anchorInfoBgBtn addSubview:anchorTagImgV];
  509. [anchorTagImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  510. make.right.equalTo(youpaipavatarImgV.mas_right).offset(0.0f);
  511. make.bottom.equalTo(youpaipavatarImgV.mas_bottom).offset(0.0f);
  512. make.size.mas_offset(CGSizeMake(10.0f, 10.0f));
  513. }];
  514. UILabel *youpaipnicknameL = [[UILabel alloc] init];
  515. youpaipnicknameL.font = LCBoldFont(11.0f);
  516. youpaipnicknameL.textColor = [UIColor whiteColor];
  517. youpaipnicknameL.text = self.youpaipliveModel.youpaipuser_info.youpaipnickname;
  518. [anchorInfoBgBtn addSubview:youpaipnicknameL];
  519. [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
  520. make.left.equalTo(youpaipavatarImgV.mas_right).offset(4.0f);
  521. make.right.offset(-12.0f);
  522. make.top.offset(5.0f);
  523. // make.height.offset(17.5f);
  524. }];
  525. UILabel *youpaipfansCountL = [[UILabel alloc] init];
  526. youpaipfansCountL.font = LCFont(8.0f);
  527. youpaipfansCountL.textColor = [UIColor whiteColor];
  528. youpaipfansCountL.text = [NSString stringWithFormat:@"粉丝:%@",self.youpaipliveModel.youpaipfans_count];
  529. [anchorInfoBgBtn addSubview:youpaipfansCountL];
  530. self.youpaipfansCountL = youpaipfansCountL;
  531. [youpaipfansCountL mas_makeConstraints:^(MASConstraintMaker *make) {
  532. make.left.equalTo(youpaipavatarImgV.mas_right).offset(4.0f);
  533. make.right.offset(-12.0f);
  534. make.bottom.offset(-5.0f);
  535. // make.height.offset(17.5f);
  536. }];
  537. UIButton *closeLiveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  538. [closeLiveBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_close"] forState:UIControlStateNormal];
  539. [closeLiveBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_close"] forState:UIControlStateHighlighted];
  540. [closeLiveBtn addTarget:self action:@selector(youpaifendLive) forControlEvents:UIControlEventTouchUpInside];
  541. [self.view addSubview:closeLiveBtn];
  542. [closeLiveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  543. make.right.offset(-12.0f);
  544. make.top.offset(7.0f + StatusBarHeight);
  545. make.height.offset(31.0f);
  546. make.width.offset(19.0f);
  547. }];
  548. UIButton *liveMemberCountBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  549. liveMemberCountBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
  550. liveMemberCountBtn.layer.cornerRadius = 15.5f;
  551. liveMemberCountBtn.clipsToBounds = YES;
  552. [liveMemberCountBtn addTarget:self action:@selector(youpaifliveMemberCountBtnClick) forControlEvents:UIControlEventTouchUpInside];
  553. [self.youpaipchatBgView addSubview:liveMemberCountBtn];
  554. [liveMemberCountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  555. make.right.offset(-1.0f-19.0f-12.0f);
  556. make.top.offset(7.0f + StatusBarHeight);
  557. make.height.offset(31.0f);
  558. make.width.greaterThanOrEqualTo(31.0f);
  559. }];
  560. UILabel *youpaipliveMemberCountL = [[UILabel alloc] init];
  561. youpaipliveMemberCountL.font = LCFont(12.0f);
  562. youpaipliveMemberCountL.textColor = [UIColor whiteColor];
  563. youpaipliveMemberCountL.textAlignment = NSTextAlignmentCenter;
  564. youpaipliveMemberCountL.text = @"0";
  565. [liveMemberCountBtn addSubview:youpaipliveMemberCountL];
  566. self.youpaipliveMemberCountL = youpaipliveMemberCountL;
  567. [youpaipliveMemberCountL mas_makeConstraints:^(MASConstraintMaker *make) {
  568. make.left.offset(7.0f);
  569. make.top.bottom.offset(0.0f);
  570. make.right.offset(-7.0f);
  571. }];
  572. @weakify(self);
  573. [self setYoupaipliveMemberCountChangeBlock:^(NSInteger memberCount) {
  574. @strongify(self);
  575. self.youpaipliveMemberCountL.text = [NSString stringWithFormat:@"%@",@(memberCount)];
  576. }];
  577. UIView *youpaiprankBgV = [[UIView alloc] init];//WithFrame:CGRectMake(liveMemberCountBtn.mj_x - 4.0f, 7.0f, 0.0f, 31.0f)
  578. [self.youpaipchatBgView addSubview:youpaiprankBgV];
  579. self.youpaiprankBgV = youpaiprankBgV;
  580. [youpaiprankBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  581. make.right.equalTo(liveMemberCountBtn.mas_left).offset(-4.0f);
  582. make.top.offset(7.0f + StatusBarHeight);
  583. make.height.offset(31.0f);
  584. make.width.offset(0.0f);
  585. }];
  586. [self youpaifupdateMemberInfo];
  587. [self setYoupaipliveMemberListChangeBlock:^(NSArray * _Nonnull members) {
  588. @strongify(self);
  589. self.youpaipliveModel.youpaiplive_top_three = [LZLiveTopThreeModel mj_objectArrayWithKeyValuesArray:members];
  590. [self youpaifupdateMemberInfo];
  591. }];
  592. NSMutableArray *arr = [NSMutableArray array];
  593. if (self.youpaipliveModel.youpaipanchor_rank_info.youpaiptotalMoney.youpaipval.length != 0) {
  594. [arr addObject:@"totalMoney"];
  595. }
  596. if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipgapMoney.youpaipval.length != 0) {
  597. [arr addObject:@"gapMoney"];
  598. }
  599. if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipno.youpaipval.length != 0) {
  600. [arr addObject:@"no"];
  601. }
  602. SDCycleScrollView *youpaipboardCycleView = [[SDCycleScrollView alloc] init];
  603. youpaipboardCycleView.backgroundColor = [UIColor clearColor];
  604. youpaipboardCycleView.scrollDirection = UICollectionViewScrollDirectionVertical;
  605. youpaipboardCycleView.autoScrollTimeInterval = 5.0f/arr.count;
  606. youpaipboardCycleView.autoScroll = YES;
  607. youpaipboardCycleView.imageURLStringsGroup = arr.copy;
  608. youpaipboardCycleView.titleLabelTextColor = [UIColor redColor];
  609. youpaipboardCycleView.showPageControl = NO;
  610. youpaipboardCycleView.delegate = self;
  611. [headerView addSubview:youpaipboardCycleView];
  612. self.youpaipboardCycleView = youpaipboardCycleView;
  613. [youpaipboardCycleView mas_makeConstraints:^(MASConstraintMaker *make) {
  614. make.left.offset(14.0f);
  615. make.top.equalTo(anchorInfoBgBtn.mas_bottom).offset(10.0f);
  616. make.height.offset(20.0f);
  617. make.width.offset(150.0f);
  618. }];
  619. [self setYoupaipliveInfoUpdateBlock:^(NSString * _Nonnull anchor_charm, NSString * _Nonnull fans, NSDictionary * _Nonnull anchor_rank_info) {
  620. @strongify(self);
  621. self.youpaipfansCountL.text = [NSString stringWithFormat:@"粉丝:%@",fans];
  622. self.youpaipliveModel.youpaipanchor_rank_info = [LZLiveAnchorRankInfoModel mj_objectWithKeyValues:anchor_rank_info];
  623. NSMutableArray *arr = [NSMutableArray array];
  624. if (self.youpaipliveModel.youpaipanchor_rank_info.youpaiptotalMoney.youpaipval.length != 0) {
  625. [arr addObject:@"totalMoney"];
  626. }
  627. if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipgapMoney.youpaipval.length != 0) {
  628. [arr addObject:@"gapMoney"];
  629. }
  630. if (self.youpaipliveModel.youpaipanchor_rank_info.youpaipno.youpaipval.length != 0) {
  631. [arr addObject:@"no"];
  632. }
  633. self.youpaipboardCycleView.imageURLStringsGroup = arr.copy;
  634. self.youpaipboardCycleView.autoScrollTimeInterval = 5.0f/arr.count;
  635. }];
  636. // UIView *userIdBgV = [[UIView alloc] init];
  637. // userIdBgV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f];
  638. // userIdBgV.layer.cornerRadius = 8.5f;
  639. // userIdBgV.clipsToBounds = YES;
  640. // [self.youpaipchatBgView addSubview:userIdBgV];
  641. // [userIdBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  642. // make.right.offset(-12.0f);
  643. // make.top.equalTo(anchorInfoBgBtn.mas_bottom).offset(8.0f);
  644. // make.height.offset(17.0f);
  645. // }];
  646. //
  647. // UILabel *userIdL = [[UILabel alloc] init];
  648. // userIdL.font = LCFont(12.0f);
  649. // userIdL.textColor = HexColorFromRGB(0xDDDDDD);
  650. // userIdL.text = [NSString stringWithFormat:@"花舞号 %@",self.youpaipliveModel.user_info.usercode];
  651. // [userIdBgV addSubview:userIdL];
  652. // [userIdL mas_makeConstraints:^(MASConstraintMaker *make) {
  653. // make.left.offset(7.0f);
  654. // make.right.offset(-7.0f);
  655. // make.top.bottom.offset(0.0f);
  656. // }];
  657. UIButton *youpaiprePKBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  658. // youpaiprePKBtn.layer.cornerRadius = 12.0f;
  659. // youpaiprePKBtn.clipsToBounds = YES;
  660. youpaiprePKBtn.frame = CGRectMake(0, 0, 56.0f, 22.0f);
  661. [LCTools clipCorner:UIRectCornerBottomLeft|UIRectCornerBottomRight View:youpaiprePKBtn size:CGSizeMake(5.0f, 5.0f)];
  662. [youpaiprePKBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(56.0f, 22.0f) FromColors:@[HexColorFromRGB(0x69BCF8),HexColorFromRGB(0x274BE8)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  663. [youpaiprePKBtn setTitle:@"重新PK" forState:UIControlStateNormal];
  664. [youpaiprePKBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  665. youpaiprePKBtn.titleLabel.font = LCFont12;
  666. youpaiprePKBtn.hidden = YES;
  667. [youpaiprePKBtn addTarget:self action:@selector(youpaifrePKBtnClick) forControlEvents:UIControlEventTouchUpInside];
  668. [self.view addSubview:youpaiprePKBtn];
  669. self.youpaiprePKBtn = youpaiprePKBtn;
  670. [youpaiprePKBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  671. make.centerX.equalTo(self.view);
  672. make.top.equalTo(headerView.mas_bottom).offset(8.0f);
  673. make.size.mas_offset(CGSizeMake(56.0f, 22.0f));
  674. }];
  675. }
  676. - (void)youpaifupdateMemberInfo{
  677. [self youpaifeditBtnCountWithCount:self.youpaipliveModel.youpaiplive_top_three.count > 3 ? 3 : self.youpaipliveModel.youpaiplive_top_three.count];
  678. [self.youpaiprankBgV updateConstraints:^(MASConstraintMaker *make) {
  679. make.width.offset(self.youpaipmemberBtns.count * 31.0f + (self.youpaipmemberBtns.count - 1.0f) * 4.0f);
  680. }];
  681. NSArray <UIColor *>*borderColors = @[[HexColorFromRGB(0xFF0000) colorWithAlphaComponent:0.47f],[HexColorFromRGB(0xFFD043) colorWithAlphaComponent:0.47f],[HexColorFromRGB(0x6EF467) colorWithAlphaComponent:0.47f]];
  682. NSArray <UIColor *>*titleBgColors = @[[HexColorFromRGB(0xF46767) colorWithAlphaComponent:0.41f],[HexColorFromRGB(0xFFC104) colorWithAlphaComponent:0.41f],[HexColorFromRGB(0x6EF467) colorWithAlphaComponent:0.41f]];
  683. // for (NSInteger i = 0; i < self.youpaipmemberBtns.count; i ++) {
  684. // YOUPAILZLiveMemberButton *imgBtn = self.youpaipmemberBtns[i];
  685. // imgBtn.layer.cornerRadius = 15.5f;
  686. // imgBtn.clipsToBounds = YES;
  687. // imgBtn.tag = [self.youpaipliveModel.youpaiplive_top_three[i].youpaipid integerValue];
  688. // [imgBtn addTarget:self action:@selector(youpaifshowUserInfoClick:) forControlEvents:UIControlEventTouchUpInside];
  689. // [imgBtn sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipliveModel.youpaiplive_top_three[i].youpaipavatar] forState:UIControlStateNormal];
  690. // imgBtn.frame = CGRectMake(i * 31.0f + i * 4.0f, 0, 31.0f, 31.0f);
  691. // imgBtn.youpaipcountL.text = self.youpaipliveModel.youpaiplive_top_three[i].youpaipscore;
  692. // imgBtn.layer.borderColor = borderColors[i].CGColor;
  693. // imgBtn.layer.borderWidth = 1.0f;
  694. // imgBtn.youpaipcountL.mj_w = 31.0f;
  695. // imgBtn.youpaipcountL.backgroundColor = titleBgColors[i];
  696. // [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:imgBtn.youpaipcountL size:CGSizeMake(6.0f, 6.0f)];
  697. // }
  698. }
  699. /// 设置FooterView
  700. - (void)youpaifsetupFooterView{
  701. UIView *youpaipfooterView = [[UIView alloc] init];
  702. [self.youpaipchatBgView addSubview:youpaipfooterView];
  703. [youpaipfooterView mas_makeConstraints:^(MASConstraintMaker *make) {
  704. make.right.left.offset(0.0f);
  705. make.height.offset(40.0f);
  706. make.bottom.offset(-SafeHeight - 10.0f);
  707. }];
  708. UIButton *sendMessageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  709. sendMessageBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f];
  710. sendMessageBtn.layer.cornerRadius = 20.0f;
  711. sendMessageBtn.clipsToBounds = YES;
  712. [sendMessageBtn addTarget:self action:@selector(youpaifsendMessageBtnClick) forControlEvents:UIControlEventTouchUpInside];
  713. [youpaipfooterView addSubview:sendMessageBtn];
  714. self.youpaipsendMessageBtn = sendMessageBtn;
  715. [sendMessageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  716. make.left.offset(0.0f);
  717. make.height.offset(40.0f);
  718. make.bottom.offset(0.0f);
  719. make.width.offset(103.0f);
  720. }];
  721. UILabel *youpaiptextL = [[UILabel alloc] init];
  722. youpaiptextL.font = LCFont16;
  723. youpaiptextL.textColor = HexColorFromRGB(0xDDDDDD);
  724. youpaiptextL.text = @"聊聊天…";
  725. [sendMessageBtn addSubview:youpaiptextL];
  726. [youpaiptextL mas_makeConstraints:^(MASConstraintMaker *make) {
  727. make.left.offset(16.0f);
  728. make.top.bottom.offset(0.0f);
  729. }];
  730. UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  731. [moreBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_audience_more"] forState:UIControlStateNormal];
  732. [moreBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_audience_more"] forState:UIControlStateHighlighted];
  733. [moreBtn addTarget:self action:@selector(youpaifmoreBtnClick) forControlEvents:UIControlEventTouchUpInside];
  734. [youpaipfooterView addSubview:moreBtn];
  735. [moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  736. make.right.offset(-16.0f);
  737. make.top.offset(0.0f);
  738. make.size.mas_offset(CGSizeMake(40.0f, 40.0f));
  739. }];
  740. // 连麦
  741. UIButton *youpaiplianmaiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  742. [youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateNormal];
  743. [youpaiplianmaiBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_lianmai"] forState:UIControlStateHighlighted];
  744. [youpaiplianmaiBtn addTarget:self action:@selector(youpaiflianmaiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  745. [youpaipfooterView addSubview:youpaiplianmaiBtn];
  746. self.youpaiplianmaiBtn = youpaiplianmaiBtn;
  747. [youpaiplianmaiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  748. make.right.equalTo(moreBtn.mas_left).offset(-16.0f);
  749. make.top.offset(0.0f);
  750. make.size.mas_offset(CGSizeMake(40.0f, 40.0f));
  751. }];
  752. // pk
  753. UIButton *youpaippkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  754. [youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateNormal];
  755. [youpaippkBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_avchor_pk"] forState:UIControlStateHighlighted];
  756. [youpaippkBtn addTarget:self action:@selector(youpaifpkBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  757. [youpaipfooterView addSubview:youpaippkBtn];
  758. self.youpaippkBtn = youpaippkBtn;
  759. [youpaippkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  760. make.right.equalTo(youpaiplianmaiBtn.mas_left).offset(-16.0f);
  761. make.top.offset(0.0f);
  762. make.size.mas_offset(CGSizeMake(40.0f, 40.0f));
  763. }];
  764. // 礼物
  765. UIButton *giftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  766. [giftBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_gift"] forState:UIControlStateNormal];
  767. [giftBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_anchor_gift"] forState:UIControlStateHighlighted];
  768. [giftBtn addTarget:self action:@selector(youpaifgiftBtnClick) forControlEvents:UIControlEventTouchUpInside];
  769. [youpaipfooterView addSubview:giftBtn];
  770. [giftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  771. make.right.equalTo(youpaippkBtn.mas_left).offset(-9.0f);
  772. make.top.offset(0.0f);
  773. make.size.mas_offset(CGSizeMake(40.0f, 40.0f));
  774. }];
  775. }
  776. #pragma mark - Click
  777. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  778. [self youpaifhideKayboard];
  779. UITouch* touch = [touches anyObject];
  780. UIView* view = [touch view];
  781. if (view == self.youpaipdemoBarBgV) {
  782. [self youpaifhideDemoBar];
  783. }
  784. }
  785. /// 发送消息按钮点击事件
  786. - (void)youpaifsendMessageBtnClick{
  787. [self youpaifsendMessageBecomeFirstResponder];
  788. }
  789. /// 喇叭
  790. - (void)youpaifvoice:(BOOL)isOpen{
  791. if (isOpen) {
  792. [self.youpaipagoraKit muteLocalAudioStream:YES];
  793. }else{
  794. [self.youpaipagoraKit muteLocalAudioStream:NO];
  795. }
  796. }
  797. /// 查看在线人员列表
  798. - (void)youpaifliveMemberCountBtnClick{
  799. YOUPAILZLiveMemberListVC *memberVc = [[YOUPAILZLiveMemberListVC alloc] init];
  800. memberVc.youpaiplive_id = self.youpaipliveModel.youpaiplive_id;
  801. memberVc.isTouchDismiss = YES;
  802. memberVc.youpaipisAnchor = YES;
  803. @weakify(self);
  804. [memberVc setSelectedMemberBlock:^(YOUPAILZLiveMemberModel * _Nonnull member) {
  805. @strongify(self);
  806. [self youpaifshowUserInfoWithUserId:member.youpaipid];
  807. }];
  808. [self TFPresentVC:memberVc completion:^{}];
  809. }
  810. /// 切换摄像头
  811. - (void)youpaifchangeCamera{
  812. [self.youpaipmCamera changeCameraInputDeviceisFront:!self.youpaipmCamera.isFrontCamera];
  813. [self.youpaipagoraKit switchCamera];
  814. }
  815. /// 连麦事件
  816. - (void)youpaifforwardChannel{
  817. AgoraChannelMediaRelayConfiguration *config = [[AgoraChannelMediaRelayConfiguration alloc] init];
  818. AgoraChannelMediaRelayInfo *fromRelayInfo = [[AgoraChannelMediaRelayInfo alloc] init];
  819. fromRelayInfo.channelName = self.youpaipliveModel.youpaiproomid;
  820. fromRelayInfo.uid = [self.youpaipliveModel.youpaipuser_info.youpaipuser_id integerValue];
  821. config.sourceInfo = fromRelayInfo;
  822. NSString *roomid = self.youpaipstartPKModel.youpaipto_roomid;
  823. if (roomid.length == 0) {
  824. roomid = self.youpaipstartPKModel.youpaipfrom_roomid;
  825. }
  826. [config setDestinationInfo:fromRelayInfo forChannelName:roomid];
  827. // [self.youpaipagoraKit startChannelMediaRelay:config];
  828. [self.youpaipagoraKit startOrUpdateChannelMediaRelay:config];
  829. UIButton *btn = nil;
  830. if (self.youpaipinviteType == LZLiveInviteTypePK) {
  831. btn = self.youpaippkBtn;
  832. }else{
  833. btn = self.youpaiplianmaiBtn;
  834. }
  835. btn.selected = YES;
  836. [btn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_close_pk_lianmai"] forState:UIControlStateNormal];
  837. [btn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_close_pk_lianmai"] forState:UIControlStateHighlighted];
  838. }
  839. /// 更多菜单点击
  840. - (void)youpaifmoreBtnClick{
  841. [self.youpaipmenuView youpaifshowAnimation];
  842. }
  843. // 连麦按钮点击事件
  844. - (void)youpaiflianmaiBtnClick:(UIButton *)sender{
  845. if (sender.isSelected == NO) {
  846. YOUPAILZLiveInviteVC *vc = [[YOUPAILZLiveInviteVC alloc] initWithType:LZLiveInviteTypeLianMai];
  847. @weakify(self);
  848. [vc setYoupaipinviteBlock:^(LZLiveInviteType type, YOUPAILZLiveInviteModel * _Nonnull model) {
  849. @strongify(self);
  850. [self youpaifrequestLianMaiOrPKWithType:type model:model];
  851. }];
  852. [self TFPresentViewController:vc presentSize:CGSizeMake(KScreenWidth, ScaleSize(343.0f)) direction:TFDirectionBottom completion:^{}];
  853. }else{
  854. @weakify(self);
  855. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"结束连麦" handler:^(LZAlertAction *action) {
  856. @strongify(self);
  857. [self youpaifhangupLianMaiOrPK];
  858. }];
  859. cancelAction.cornerRadius = 24.0f;
  860. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  861. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"继续连麦" handler:^(LZAlertAction *action) {
  862. }];
  863. confimAction.cornerRadius = 24.0f;
  864. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  865. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"当前处于连麦状态,是否确认结束连麦?" action:@[cancelAction,confimAction]];
  866. [self TFPresentVC:alert completion:^{}];
  867. }
  868. }
  869. /// 赠送礼物按钮点击事件
  870. - (void)youpaifgiftBtnClick{
  871. YOUPAILZCommonGiftView *view = [YOUPAILZCommonGiftView new];
  872. view.isTouchDismiss = YES;
  873. view.youpaipisAnchor = YES;
  874. [view setYoupaiplzgiftblock:^(YOUPAILCGiftModel * _Nonnull model, NSInteger count,NSString*categoryID) {
  875. [ZCHUDHelper showTitle:@"你在直播中,暂时不可以送礼物"];
  876. }];
  877. [self TFPresentVC:view completion:^{
  878. }];
  879. }
  880. // pk按钮点击事件
  881. - (void)youpaifpkBtnClick:(UIButton *)sender{
  882. if (sender.isSelected == NO) {
  883. YOUPAILZLiveInviteVC *vc = [[YOUPAILZLiveInviteVC alloc] initWithType:LZLiveInviteTypePK];
  884. @weakify(self);
  885. [vc setYoupaipinviteBlock:^(LZLiveInviteType type, YOUPAILZLiveInviteModel * _Nonnull model) {
  886. @strongify(self);
  887. [self youpaifrequestLianMaiOrPKWithType:type model:model];
  888. }];
  889. [self TFPresentViewController:vc presentSize:CGSizeMake(KScreenWidth, ScaleSize(343.0f)) direction:TFDirectionBottom completion:^{}];
  890. }else{
  891. NSString *cancelT = @"";
  892. NSString *confimT = @"";
  893. NSString *contentT = @"";
  894. if (self.youpaippkState == LZLivePKStatePK) {
  895. cancelT = @"结束PK";
  896. confimT = @"继续PK";
  897. contentT = @"当前处于PK状态,是否确认结束PK?";
  898. }else if(self.youpaippkState == LZLivePKStatePunishment){
  899. cancelT = @"断开PK";
  900. confimT = @"继续PK";
  901. contentT = @"当前处于惩罚时间,是否断开PK?";
  902. }else if(self.youpaippkState == LZLivePKStateEnd){
  903. cancelT = @"结束PK";
  904. confimT = @"继续PK";
  905. contentT = @"当前处于PK连线状态,是否确认结束PK?";
  906. }
  907. @weakify(self);
  908. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:cancelT handler:^(LZAlertAction *action) {
  909. @strongify(self);
  910. [self youpaifhangupLianMaiOrPK];
  911. }];
  912. cancelAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[HexColorFromRGB(0x9F9DA5),HexColorFromRGB(0x9F9DA5)] ByGradientType:GradientLeftToRight]];;
  913. cancelAction.cornerRadius = 24.0f;
  914. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:confimT handler:^(LZAlertAction *action) {
  915. }];
  916. confimAction.cornerRadius = 24.0f;
  917. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  918. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:contentT action:@[cancelAction,confimAction]];
  919. [self TFPresentVC:alert completion:^{}];
  920. }
  921. }
  922. /// 重新pk事件
  923. - (void)youpaifrePKBtnClick{
  924. NSString *roomid = self.youpaipstartPKModel.youpaipto_roomid;
  925. if (roomid.length == 0) {
  926. roomid = self.youpaipstartPKModel.youpaipfrom_roomid;
  927. }
  928. [LCHttpHelper requestWithURLString:ReStartPK parameters:@{@"room_id":roomid} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  929. NSDictionary* dict = (NSDictionary*)responseObject;
  930. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  931. if (code == 0) {
  932. }else{
  933. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  934. }
  935. } failure:^(NSError *error) {
  936. [ZCHUDHelper showTitle:error.localizedDescription];
  937. }];
  938. }
  939. /// 获取用户信息
  940. - (void)youpaifshowUserInfoClick:(UIButton *)sender{
  941. [self youpaifshowUserInfoWithUserId:[NSString stringWithFormat:@"%@",@(sender.tag)]];
  942. }
  943. /// 隐藏demoBar
  944. - (void)youpaifhideDemoBar{
  945. self.beautyEditView.hidden = YES;
  946. }
  947. /// 显示demoBar
  948. - (void)youpaifshowDemoBar{
  949. [self.view bringSubviewToFront:self.beautyEditView];
  950. self.beautyEditView.hidden = NO;
  951. }
  952. #pragma mark - SDCycleScrollViewDelegate
  953. //- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
  954. //
  955. //}
  956. - (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view{
  957. return [YOUPAILZLiveBoardCycleViewCell class];
  958. }
  959. - (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view{
  960. YOUPAILZLiveBoardCycleViewCell *boardCell = (YOUPAILZLiveBoardCycleViewCell *)cell;
  961. NSString *type = view.imageURLStringsGroup[index];
  962. [boardCell youpaifreloadWithModel:[self.youpaipliveModel.youpaipanchor_rank_info valueForKey:type] type:type];
  963. @weakify(self);
  964. [boardCell setYoupaipclickBlock:^{
  965. @strongify(self);
  966. YOUPAILZLiveAnchorHotWindow *memberVc = [[YOUPAILZLiveAnchorHotWindow alloc] init];
  967. memberVc.youpaiplive_id = self.youpaipliveModel.youpaiplive_id;
  968. memberVc.isTouchDismiss = YES;
  969. memberVc.youpaipisAnchor = YES;
  970. [memberVc setSelectedMemberBlock:^(YOUPAILZLiveMemberModel * _Nonnull member) {
  971. @strongify(self);
  972. [self youpaifshowUserInfoWithUserId:member.youpaipid];
  973. }];
  974. [self TFPresentVC:memberVc completion:^{}];
  975. }];
  976. }
  977. - (YOUPAILZAnchorMenuView *)youpaipmenuView{
  978. if (!_youpaipmenuView) {
  979. _youpaipmenuView = [[YOUPAILZAnchorMenuView alloc] initWithSupView:self.view];
  980. @weakify(self);
  981. // 隐藏聊天记录
  982. [_youpaipmenuView setYoupaiphideChatMessageBlock:^{
  983. @strongify(self);
  984. [self youpaifhiddenChatList];
  985. }];
  986. // // 更换字体大小
  987. // [_youpaipmenuView setYoupaipreplaceChatMessageFontSizeBlock:^{
  988. // @strongify(self);
  989. // self.youpaipliveModel.isMaxFont = !self.youpaipliveModel.isMaxFont;
  990. // [self youpaifreloadChatList];
  991. // }];
  992. // 静音
  993. [_youpaipmenuView setYoupaipcloseVoiceBlock:^(BOOL open) {
  994. @strongify(self);
  995. [self youpaifvoice:open];
  996. }];
  997. // 点击切换摄像头
  998. [_youpaipmenuView setYoupaipchangeCameraBlock:^{
  999. @strongify(self);
  1000. [self youpaifchangeCamera];
  1001. }];
  1002. // 点击美颜
  1003. [_youpaipmenuView setYoupaipbeautyBlock:^{
  1004. @strongify(self);
  1005. [self youpaifshowDemoBar];
  1006. }];
  1007. // 结束直播
  1008. [_youpaipmenuView setYoupaipcloseBlock:^{
  1009. @strongify(self);
  1010. [self youpaifendLive];
  1011. }];
  1012. // 背景音乐
  1013. [_youpaipmenuView setShowMusicBlock:^{
  1014. @strongify(self);
  1015. YOUPAILZLiveMusicListWindow *vc = [[YOUPAILZLiveMusicListWindow alloc] init];
  1016. vc.youpaipcurrentMusic = self.currentMusic;
  1017. vc.showLyric = self.youpaipmusicPlayerView.showLyric;
  1018. vc.youpaipmusicList = self.youpaipmusicList;
  1019. // vc.youpaipmusicPlayState = self.youpaipmusicPlayState;
  1020. // 播放音乐
  1021. [vc setYoupaipplayMusicBlock:^(YOUPAILZMusicListItemModel * _Nonnull model) {
  1022. @strongify(self);
  1023. if (![model.youpaipsongCode isEqual: self.currentMusic.youpaipsongCode]) {
  1024. self.currentMusic = model;
  1025. [self youpaifloadMusicInfoWithModel:self.currentMusic];
  1026. }
  1027. }];
  1028. // 暂停or播放
  1029. [vc setYoupaipsuspendMusicBlock:^{
  1030. @strongify(self);
  1031. // if (self.youpaipmusicPlayState == AgoraAudioMixingStatePlaying) {
  1032. // [self.youpaipagoraKit pauseAudioMixing];
  1033. // }else{
  1034. // [self.youpaipagoraKit resumeAudioMixing];
  1035. // }
  1036. }];
  1037. // 下一首
  1038. [vc setYoupaipnextMusicBlock:^{
  1039. @strongify(self);
  1040. [self youpaifnextMusic];
  1041. }];
  1042. // 是否展示歌词
  1043. [vc setShowLyricBlock:^(BOOL show) {
  1044. @strongify(self);
  1045. self.youpaipmusicPlayerView.showLyric = show;
  1046. }];
  1047. // 退出
  1048. [vc setYoupaipcloseBlock:^{
  1049. @strongify(self);
  1050. self.youpaipmusicPlayerView.hidden = YES;
  1051. [self.youpaipagoraKit stopAudioMixing];
  1052. }];
  1053. ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc] initWithRootViewController:vc];
  1054. [self TFPresentViewController:nav presentSize:CGSizeMake(KScreenWidth, KScreenHeight * 0.6f) direction:TFDirectionBottom completion:^{}];
  1055. }];
  1056. // 成员管理
  1057. [_youpaipmenuView setShowMemberManage:^{
  1058. @strongify(self);
  1059. [self youpaifshowMemberManageAlert];
  1060. }];
  1061. }
  1062. return _youpaipmenuView;
  1063. }
  1064. /// 下一首音乐
  1065. - (void)youpaifnextMusic{
  1066. if (self.youpaipmusicList.count == 0) {
  1067. return;
  1068. }
  1069. if ([self.youpaipmusicList containsObject:self.currentMusic]) {
  1070. NSInteger index = [self.youpaipmusicList indexOfObject:self.currentMusic];
  1071. if (index + 1 < self.youpaipmusicList.count) {
  1072. self.currentMusic = self.youpaipmusicList[index + 1];
  1073. [self youpaifloadMusicInfoWithModel:self.currentMusic];
  1074. }else{
  1075. self.currentMusic = self.youpaipmusicList[0];
  1076. [self youpaifloadMusicInfoWithModel:self.currentMusic];
  1077. }
  1078. }else{
  1079. self.currentMusic = self.youpaipmusicList[0];
  1080. [self youpaifloadMusicInfoWithModel:self.currentMusic];
  1081. }
  1082. }
  1083. /// 获取音乐信息
  1084. - (void)youpaifloadMusicInfoWithModel:(YOUPAILZMusicListItemModel *)model{
  1085. /* [[NSNotificationCenter defaultCenter] postNotificationName:@"CurrentMusicChangeNotification" object:model userInfo:nil];
  1086. @weakify(self);
  1087. [LCHttpHelper requestWithURLString:MusicInfo parameters:@{@"musicId":model.youpaipsongCode} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1088. @strongify(self);
  1089. NSDictionary* dict = (NSDictionary*)responseObject;
  1090. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1091. if (code == 0) {
  1092. NSLog(@"-----%@",[dict objectForKey:@"data"]);
  1093. YOUPAILZMusicModel *youpaipmusicModel = [YOUPAILZMusicModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  1094. youpaipmusicModel.youpaipmusicName = model.youpaipname;
  1095. if (model.youpaipposter.length != 0) {
  1096. youpaipmusicModel.youpaipcover = model.youpaipposter;
  1097. }
  1098. if (youpaipmusicModel.youpaipdynamicLyricUrl.length != 0) {
  1099. dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
  1100. dispatch_async(queue, ^{
  1101. NSString *lrcStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:youpaipmusicModel.youpaipdynamicLyricUrl] encoding:NSUTF8StringEncoding error:nil];
  1102. [youpaipmusicModel youpaifparseLrc:lrcStr];
  1103. dispatch_async(dispatch_get_main_queue(), ^{
  1104. @strongify(self);
  1105. self.youpaipmusicPlayerView.hidden = NO;
  1106. [self.youpaipmusicPlayerView youpaifreloadMusicModel:youpaipmusicModel];
  1107. [self youpaifstartPlayMusicWithPath:youpaipmusicModel.youpaipfileUrl];
  1108. });
  1109. });
  1110. }else{
  1111. self.youpaipmusicPlayerView.hidden = NO;
  1112. youpaipmusicModel.youpaipwordArray = @[youpaipmusicModel.youpaipmusicName,@""].mutableCopy;
  1113. [self.youpaipmusicPlayerView youpaifreloadMusicModel:youpaipmusicModel];
  1114. [self youpaifstartPlayMusicWithPath:youpaipmusicModel.youpaipfileUrl];
  1115. }
  1116. }else{
  1117. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1118. }
  1119. } failure:^(NSError *error) {
  1120. [ZCHUDHelper showTitle:error.localizedDescription];
  1121. }]; */
  1122. }
  1123. /// 播放音乐
  1124. - (void)youpaifstartPlayMusicWithPath:(NSString *)path{
  1125. // 设置是否只在本地播放音乐文件。true 表示只有本地用户能听到音乐;false 表示本地用户和远端用户都能听到音乐。
  1126. BOOL youpaiploopback = NO;
  1127. // 设置是否用音乐文件替换麦克风采集的音频。true 表示用户只能听到音乐;false 表示用户可以听到音乐和麦克风采集的音频。
  1128. BOOL youpaipreplace = NO;
  1129. // 设置音乐文件的播放次数。1 表示播放 1 次。
  1130. NSInteger cycle = 1;
  1131. // [self.youpaipagoraKit startAudioMixing:path loopback:youpaiploopback replace:youpaipreplace cycle:cycle];
  1132. // 调节音乐文件的播放音量
  1133. [self.youpaipagoraKit adjustAudioMixingVolume:50];
  1134. }
  1135. /// 设置用户角色
  1136. - (AgoraClientRole)youpaifclientRole{
  1137. return AgoraClientRoleBroadcaster;
  1138. }
  1139. /// 结束直播
  1140. - (void)youpaifendLive{
  1141. @weakify(self);
  1142. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  1143. }];
  1144. cancelAction.cornerRadius = 24.0f;
  1145. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  1146. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确认" handler:^(LZAlertAction *action) {
  1147. @strongify(self);
  1148. [self youpaifrequestCloseLiveData];
  1149. }];
  1150. confimAction.cornerRadius = 24.0f;
  1151. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  1152. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"是否要结束直播" action:@[cancelAction,confimAction]];
  1153. alert.contentTextAlignment = NSTextAlignmentCenter;
  1154. [self TFPresentVC:alert completion:^{}];
  1155. }
  1156. bool youpaipisShowRePKAlert = NO;
  1157. /// 被连麦者获取连麦或pk信息
  1158. - (void)youpaifrequestObtainInteractWithPkId:(NSString *)pkId type:(LZLiveInviteType)type{
  1159. @weakify(self);
  1160. [LCHttpHelper requestWithURLString:ObtainInteract parameters:@{@"pk_id":pkId} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1161. @strongify(self);
  1162. NSDictionary* dict = (NSDictionary*)responseObject;
  1163. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1164. if (code == 0) {
  1165. YOUPAILZLiveStartPKModel *model = [YOUPAILZLiveStartPKModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  1166. if (self.youpaipstartPKModel != nil && ![self.youpaipstartPKModel.youpaippk_id isEqual:model.youpaippk_id]) {
  1167. if (youpaipisShowRePKAlert == NO) {
  1168. youpaipisShowRePKAlert = YES;
  1169. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"拒绝" handler:^(LZAlertAction *action) {
  1170. youpaipisShowRePKAlert = NO;
  1171. [LCHttpHelper requestWithURLString:ReFusePK parameters:@{@"pk_id":model.youpaippk_id} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1172. NSDictionary* dict = (NSDictionary*)responseObject;
  1173. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1174. if (code == 0) {
  1175. }else{
  1176. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1177. }
  1178. } failure:^(NSError *error) {
  1179. [ZCHUDHelper showTitle:error.localizedDescription];
  1180. }];
  1181. }];
  1182. cancelAction.cornerRadius = 24.0f;
  1183. cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  1184. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"接受" handler:^(LZAlertAction *action) {
  1185. @strongify(self);
  1186. youpaipisShowRePKAlert = NO;
  1187. NSDictionary *params = @{@"pk_id":self.youpaipstartPKModel.youpaippk_id,@"new_pk_id":model.youpaippk_id};
  1188. self.youpaipstartPKModel = model;
  1189. [LCHttpHelper requestWithURLString:ReceiveRestartPK parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1190. NSDictionary* dict = (NSDictionary*)responseObject;
  1191. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1192. if (code == 0) {
  1193. }else{
  1194. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1195. }
  1196. } failure:^(NSError *error) {
  1197. [ZCHUDHelper showTitle:error.localizedDescription];
  1198. }];
  1199. }];
  1200. confimAction.cornerRadius = 24.0f;
  1201. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  1202. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"对方邀请您重新PK" action:@[cancelAction,confimAction]];
  1203. alert.contentTextAlignment = NSTextAlignmentCenter;
  1204. [self TFPresentVC:alert completion:^{}];
  1205. }
  1206. }else{
  1207. YOUPAILZLiveCallWindow *vc = [[YOUPAILZLiveCallWindow alloc] initWithState:LZLiveInviteStateAnswer type:type model:model];
  1208. vc.isTouchDismiss = NO;
  1209. [vc setYoupaipstartConnectBlock:^(YOUPAILZLiveStartPKModel * _Nonnull model) {
  1210. @strongify(self);
  1211. self.youpaipstartPKModel = model;
  1212. self.youpaipinviteType = type;
  1213. [self youpaifforwardChannel];
  1214. }];
  1215. [self TFPresentVC:vc completion:^{}];
  1216. }
  1217. }else{
  1218. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1219. }
  1220. } failure:^(NSError *error) {
  1221. [ZCHUDHelper showTitle:error.localizedDescription];
  1222. }];
  1223. }
  1224. /// 开始连麦/PK
  1225. - (void)youpaifrequestLianMaiOrPKWithType:(LZLiveInviteType)type model:(YOUPAILZLiveInviteModel *)model{
  1226. NSDictionary *params = @{
  1227. @"room_id":model.youpaiproom_id,
  1228. @"type":type == LZLiveInviteTypePK ? @"pk" : @"lianmai"
  1229. };
  1230. @weakify(self);
  1231. [LCHttpHelper requestWithURLString:StartInteract parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1232. @strongify(self);
  1233. NSDictionary* dict = (NSDictionary*)responseObject;
  1234. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1235. if (code == 0) {
  1236. YOUPAILZLiveStartPKModel *model = [YOUPAILZLiveStartPKModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  1237. self.youpaipstartPKModel = model;
  1238. YOUPAILZLiveCallWindow *vc = [[YOUPAILZLiveCallWindow alloc] initWithState:LZLiveInviteStateCall type:type model:model];
  1239. vc.isTouchDismiss = NO;
  1240. [self TFPresentVC:vc completion:^{}];
  1241. }else{
  1242. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1243. }
  1244. } failure:^(NSError *error) {
  1245. [ZCHUDHelper showTitle:error.localizedDescription];
  1246. }];
  1247. }
  1248. /// 挂断连麦/PK
  1249. - (void)youpaifhangupLianMaiOrPK{
  1250. NSDictionary *params = @{
  1251. @"pk_id":self.youpaipstartPKModel.youpaippk_id,
  1252. @"event":@"hangup"
  1253. };
  1254. NSString *api = OperateFrom;
  1255. if (self.youpaipstartPKModel.youpaipfrom_roomid.length != 0) {
  1256. api = OperateTo;
  1257. }
  1258. [LCHttpHelper requestWithURLString:api parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1259. NSDictionary* dict = (NSDictionary*)responseObject;
  1260. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1261. if (code == 0) {
  1262. }else{
  1263. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1264. }
  1265. } failure:^(NSError *error) {
  1266. [ZCHUDHelper showTitle:error.localizedDescription];
  1267. }];
  1268. }
  1269. - (void)youpaifrequestCloseLiveData{
  1270. @weakify(self);
  1271. [LCHttpHelper requestWithURLString:CloseLive parameters:@{@"id":self.youpaipliveModel.youpaiplive_id} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  1272. @strongify(self);
  1273. NSDictionary* dict = (NSDictionary*)responseObject;
  1274. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  1275. if (code == 0) {
  1276. [LCSaveData saveIsVideo:NO];
  1277. YOUPAILZLiveCloseModel *model = [YOUPAILZLiveCloseModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  1278. [self youpaifleaveChannel];
  1279. YOUPAILZAnchorLiveCloseVC *vc = [[YOUPAILZAnchorLiveCloseVC alloc] init];
  1280. vc.youpaipmodel = model;
  1281. vc.hidesBottomBarWhenPushed = YES;
  1282. NSArray *vcs = self.navigationController.viewControllers;
  1283. NSMutableArray <UIViewController *>*nVcs = [NSMutableArray array];
  1284. BOOL youpaipisContainsCloseVC = NO;
  1285. for (UIViewController *fvc in vcs) {
  1286. if ([fvc isKindOfClass:[YOUPAILZAnchorLiveCloseVC class]]) {
  1287. youpaipisContainsCloseVC = YES;
  1288. }
  1289. }
  1290. if (!youpaipisContainsCloseVC) {
  1291. for (UIViewController *fvc in vcs) {
  1292. if (!([fvc isKindOfClass:[YOUPAILZLiveAnchorVC class]] || [fvc isKindOfClass:[YOUPAILZAnchorLiveCloseVC class]])) {
  1293. [nVcs addObject:fvc];
  1294. }
  1295. }
  1296. [nVcs addObject:vc];
  1297. [self.navigationController setViewControllers:nVcs.copy animated:YES];
  1298. }
  1299. }else{
  1300. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  1301. }
  1302. } failure:^(NSError *error) {
  1303. [ZCHUDHelper showTitle:error.localizedDescription];
  1304. }];
  1305. }
  1306. /// 顶部榜单相关函数
  1307. - (void)youpaifeditBtnCountWithCount:(NSInteger)count{
  1308. if (count >= self.youpaipmemberBtns.count) {
  1309. [self youpaifaddBtnWithCount:count - self.youpaipmemberBtns.count];
  1310. }else{
  1311. [self youpaifdeleteBtnWithCount:self.youpaipmemberBtns.count - count];
  1312. }
  1313. }
  1314. - (void)youpaifdeleteBtnWithCount:(NSInteger)count{
  1315. if (count != 0) {
  1316. for (NSInteger i = 0; i < count; i ++) {
  1317. YOUPAILZLiveMemberButton *btn = self.youpaipmemberBtns.lastObject;
  1318. [self.youpaipmemberBtns removeLastObject];
  1319. [btn removeFromSuperview];
  1320. }
  1321. }
  1322. }
  1323. - (void)youpaifaddBtnWithCount:(NSInteger)count{
  1324. for (NSInteger i = 0; i < count; i ++) {
  1325. [self youpaifcreateBtn];
  1326. }
  1327. }
  1328. - (void)youpaifcreateBtn{
  1329. YOUPAILZLiveMemberButton *btn = [[YOUPAILZLiveMemberButton alloc] init];
  1330. btn.imageView.contentMode = UIViewContentModeScaleAspectFill;
  1331. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
  1332. btn.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
  1333. // btn.layer.cornerRadius = 3.0f;
  1334. // btn.clipsToBounds = YES;
  1335. [self.youpaiprankBgV addSubview:btn];
  1336. [self.youpaipmemberBtns addObject:btn];
  1337. }
  1338. - (NSMutableArray<YOUPAILZLiveMemberButton *> *)youpaipmemberBtns{
  1339. if (!_youpaipmemberBtns) {
  1340. _youpaipmemberBtns = [NSMutableArray array];
  1341. }
  1342. return _youpaipmemberBtns;
  1343. }
  1344. - (NSMutableArray<YOUPAILZMusicListItemModel *> *)youpaipmusicList{
  1345. if (!_youpaipmusicList) {
  1346. _youpaipmusicList = [NSMutableArray array];
  1347. }
  1348. return _youpaipmusicList;
  1349. }
  1350. @end