BGTLiveController.m 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  1. //
  2. // BGTLiveController.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 16/12/5.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. // 腾讯云直播,只处理与SDK有关的业务
  8. #import "BGTLiveController.h"
  9. #import "BGMD5UTils.h"
  10. #import "TLiveMickListModel.h"
  11. #import "YunMusicPlayVC.h"
  12. #import "HostCheckMickAlertView.h"
  13. #import "TCShowLiveView.h"
  14. #define kPlayContrainerHeight 30
  15. /////////////////// TiFaceSDK 添加 开始 ///////////////////
  16. #import "TiSDKInterface.h"
  17. //#import "TiUIView.h"
  18. #import "BeautySettingPanel.h"
  19. /////////////////// TiFaceSDK 添加 结束 ///////////////////
  20. #import "BGOtherPushPopView.h"
  21. #import "VoiceLianmaiUserModel.h"
  22. @interface BGTLiveController ()<BeautySettingPanelDelegate,BeautyLoadPituDelegate>
  23. {
  24. BeautySettingPanel *_beautyPanel; // 美颜控件
  25. }
  26. ///////////// TiSDK 添加 开始 /////////////
  27. @property(nonatomic, strong) TiSDKManager *tiSDKManager;
  28. //@property(nonatomic, strong) TiUIView *tiUIView;
  29. ///////////// TiSDK 添加 结束 /////////////
  30. @property (nonatomic, strong) UIView *liveView;
  31. @property(nonatomic, strong) BGOtherPushPopView *otherPushPopView;
  32. @end
  33. @implementation BGTLiveController
  34. #pragma mark - ----------------------- 添加UI -----------------------
  35. - (void)addSubViews
  36. {
  37. if (self.liveType == FW_LIVE_TYPE_HOST)
  38. {
  39. _beautyView = [[BGTLiveBeautyView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  40. [self.liveServiceController.liveUIViewController.liveView addSubview:_beautyView];
  41. _beautyView.delegate = self;
  42. _beautyView.hidden = YES;
  43. }
  44. if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  45. {
  46. self.backVerticalBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 15, 35, 35)];
  47. [self.backVerticalBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back_2"] forState:UIControlStateNormal];
  48. [self.backVerticalBtn addTarget:self action:@selector(goVerticalScreen) forControlEvents:UIControlEventTouchUpInside];
  49. [self.view addSubview:self.backVerticalBtn];
  50. self.backVerticalBtn.hidden = YES;
  51. }
  52. }
  53. #pragma mark 添加视频
  54. - (void)initLive
  55. {
  56. // 付费直播控制云直播声音
  57. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(voiceNotice:) name:@"closeAndOpenVoice" object:nil];
  58. // 音量监听
  59. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  60. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
  61. // 屏幕旋转监听
  62. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
  63. if (self.liveType == FW_LIVE_TYPE_HOST)
  64. {
  65. _publishController = [[BGTLinkMicPublishController alloc] init];
  66. // _publishController.liveView = self.liveServiceController.liveUIViewController.liveView;
  67. _publishController.delegate = self;
  68. _publishController.linkMicPublishDelegate = self;
  69. _publishController.roomIDStr = _roomIDStr;
  70. [self addChild:_publishController inRect:self.view.bounds];
  71. [self.view sendSubviewToBack:_publishController.view];
  72. [_publishController.txLivePublisher setMirror:NO];
  73. }
  74. else if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  75. {
  76. _linkMicPlayController = [[BGTLinkMicPlayController alloc] init];
  77. _linkMicPlayController.playLiveType = [self.liveItem liveType];
  78. _linkMicPlayController.delegate = self;
  79. _linkMicPlayController.linkMicPlayDelegate = self;
  80. [self addChild:_linkMicPlayController inRect:self.view.bounds];
  81. [self.view sendSubviewToBack:_linkMicPlayController.view];
  82. // _linkSecondMicPlayController = [[BGTLinkMicPlayController alloc] init];
  83. // _linkSecondMicPlayController.liveType = [self.liveItem liveType];
  84. // _linkSecondMicPlayController.delegate = self;
  85. // _linkSecondMicPlayController.linkMicPlayDelegate = self;
  86. // [self addChild:_linkSecondMicPlayController inRect:self.view.bounds];
  87. // [self.view sendSubviewToBack:_linkSecondMicPlayController.view];
  88. _firstImgView = [UIImageView new];
  89. _firstImgView.frame = self.view.bounds;
  90. _firstImgView.top = kScreenH;
  91. _firstImgView.userInteractionEnabled = YES;
  92. [self.view addSubview:_firstImgView];
  93. _secondImgView = [UIImageView new];
  94. _secondImgView.frame = self.view.bounds;
  95. _secondImgView.top = kScreenH * 2;
  96. _secondImgView.userInteractionEnabled = YES;
  97. [self.view addSubview:_secondImgView];
  98. }
  99. }
  100. -(void)protocolDidScrollView:(BGTLiveScrollView *)scrollView isRefreshLive:(BOOL)isRefresh{
  101. NSInteger currentIndex = 1;
  102. for (int i = 0; i < self.modelArr.count; i++) {
  103. LivingModel *model = self.modelArr[i];
  104. NSString *roomID = [NSString stringWithFormat:@"%d",model.room_id];
  105. if ([roomID isEqualToString:scrollView.roomID]) {
  106. currentIndex = i;
  107. }
  108. }
  109. scrollView.nowIndex = currentIndex;
  110. if ((self.now_LiveIndex == 0 && scrollView.isFromeTop)|| (self.now_LiveIndex == self.modelArr.count - 1 && !scrollView.isFromeTop)){
  111. _linkMicPlayController.videoContrainerView.top = 0;
  112. _liveServiceController.liveUIViewController.liveScrollView.top = 0;
  113. _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
  114. _secondImgView.top = _firstImgView.bottom;
  115. return;
  116. }
  117. LivingModel *first_Model;
  118. LivingModel *second_Model;
  119. //只有一个直播间时 不滑动
  120. if (self.modelArr.count < 2) {
  121. _liveServiceController.liveUIViewController.liveScrollView.top = 0;
  122. return;
  123. }
  124. NSLog(@"BGTLiveScrollView%@",scrollView);
  125. if (self.modelArr.count == 2) { //只有两个直播时
  126. if (currentIndex == 1) {//进入的是第二个直播间时
  127. first_Model = self.modelArr[1];
  128. second_Model = self.modelArr[0];
  129. }else{//进入的是第一个直播间时
  130. first_Model = self.modelArr[0];
  131. second_Model = self.modelArr[1];
  132. }
  133. }else{
  134. if (currentIndex == self.modelArr.count - 1) {
  135. first_Model = self.modelArr[self.modelArr.count - 2];
  136. second_Model = self.modelArr[self.modelArr.count - 1];
  137. }
  138. if (currentIndex == 0) {//进入第一个直播间
  139. first_Model = self.modelArr[1];
  140. second_Model = self.modelArr[2];
  141. }else if (currentIndex == self.modelArr.count - 1) {
  142. first_Model = self.modelArr[self.modelArr.count - 2];
  143. second_Model = self.modelArr[self.modelArr.count - 1];
  144. }else{//进入中间的直播间
  145. first_Model = self.modelArr[currentIndex + 1];
  146. second_Model = self.modelArr[currentIndex - 1];
  147. }
  148. }
  149. LivingModel *model = [LivingModel new];
  150. _linkMicPlayController.videoContrainerView.top = scrollView.y;
  151. _firstImgView.bottom = _linkMicPlayController.videoContrainerView.top;
  152. _secondImgView.top = _linkMicPlayController.videoContrainerView.bottom;
  153. //5-7 回播点击问题
  154. [_firstImgView sd_setImageWithURL:[NSURL URLWithString:first_Model.live_image]placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
  155. [_secondImgView sd_setImageWithURL:[NSURL URLWithString:second_Model.live_image]placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
  156. if (!isRefresh) return;
  157. if (scrollView.isFromeTop) {
  158. model = second_Model;
  159. }else{
  160. model = first_Model;
  161. }
  162. if (model.live_in != FW_LIVE_STATE_ING) {
  163. // [FanweMessage alert:ASLocalizedString(@"主播不在直播")];
  164. return;
  165. }
  166. NSLog(@"%d",model.room_id);
  167. NSLog(@"%d",model.room_id);
  168. if (scrollView.y == kScreenH || scrollView.y == 0) {
  169. // if (scrollView.y == 0) {
  170. // model = first_Model;
  171. // }else if (scrollView.y == kScreenH){
  172. // model = second_Model;
  173. // }
  174. self.nowModel = model;
  175. for (int i = 0; i < self.modelArr.count; i++) {
  176. LivingModel *model = self.modelArr[i];
  177. if (model.room_id == self.nowModel.room_id) {
  178. self.now_LiveIndex = i;
  179. }
  180. }
  181. FWWeakify(self)
  182. NSString *roomID = [NSString stringWithFormat:@"%d",model.room_id];
  183. [_liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
  184. TCShowUser *user = [[TCShowUser alloc] init];
  185. user.avatar = liveInfo.podcast.user.head_image;
  186. user.uid = liveInfo.user_id;
  187. user.username = liveInfo.podcast.user.nick_name;
  188. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
  189. liveRoom.host = user;
  190. liveRoom.avRoomId = [liveInfo.room_id intValue];
  191. liveRoom.title = [NSString stringWithFormat:@"%d",liveRoom.avRoomId];
  192. liveRoom.vagueImgUrl = liveInfo.podcast.user.head_image;
  193. //SUS_WINDOW 去记录直播间类型 这是不是观众
  194. liveRoom.liveType = SUS_WINDOW.liveType;
  195. liveRoom.isHost = NO;
  196. // TCShowLiveView *liveView = [[TCShowLiveView alloc]initWith:liveRoom liveController:self];
  197. // _liveServiceController.liveUIViewController.liveView = liveView;
  198. _liveServiceController.liveUIViewController.liveScrollView.roomID = liveInfo.room_id;
  199. [_liveServiceController.liveUIViewController.liveView refreshLiveItem:liveRoom liveInfo:liveInfo];
  200. [_liveServiceController.liveUIViewController.liveView.msgView.liveMessages removeAllObjects];
  201. FWStrongify(self)
  202. self.liveInfo = liveInfo;
  203. [self beginPlayVideo:liveInfo];
  204. self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
  205. _linkMicPlayController.videoContrainerView.top = 0;
  206. _liveServiceController.liveUIViewController.liveScrollView.top = 0;
  207. _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
  208. _secondImgView.top = _firstImgView.bottom;
  209. NSLog(@"_liveServiceControlle.scrollview%@",_liveServiceController.liveUIViewController.liveScrollView);
  210. [super startEnterChatGroup:liveInfo.group_id succ:nil failed:nil];
  211. } roomID:roomID failed:^(int errId, NSString *errMsg) {
  212. }];
  213. }
  214. }
  215. -(void)clickRightContrainerView:(NSString *)roomID{
  216. FWWeakify(self)
  217. [_liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
  218. TCShowUser *user = [[TCShowUser alloc] init];
  219. user.avatar = liveInfo.podcast.user.head_image;
  220. user.uid = liveInfo.user_id;
  221. user.username = liveInfo.podcast.user.nick_name;
  222. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
  223. liveRoom.host = user;
  224. liveRoom.avRoomId = [liveInfo.room_id intValue];
  225. liveRoom.title = [NSString stringWithFormat:@"%d",liveRoom.avRoomId];
  226. liveRoom.vagueImgUrl = liveInfo.podcast.user.head_image;
  227. //SUS_WINDOW 去记录直播间类型 这是不是观众
  228. liveRoom.liveType = SUS_WINDOW.liveType;
  229. liveRoom.isHost = NO;
  230. // TCShowLiveView *liveView = [[TCShowLiveView alloc]initWith:liveRoom liveController:self];
  231. // _liveServiceController.liveUIViewController.liveView = liveView;
  232. _liveServiceController.liveUIViewController.liveScrollView.roomID = liveInfo.room_id;
  233. [_liveServiceController.liveUIViewController.liveView refreshLiveItem:liveRoom liveInfo:liveInfo];
  234. FWStrongify(self)
  235. self.liveInfo = liveInfo;
  236. [self beginPlayVideo:liveInfo];
  237. self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
  238. _linkMicPlayController.videoContrainerView.top = 0;
  239. _liveServiceController.liveUIViewController.liveScrollView.top = 0;
  240. _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
  241. _secondImgView.top = _firstImgView.bottom;
  242. NSLog(@"_liveServiceControlle.scrollview%@",_liveServiceController.liveUIViewController.liveScrollView);
  243. [super startEnterChatGroup:liveInfo.group_id succ:nil failed:nil];
  244. } roomID:roomID failed:^(int errId, NSString *errMsg) {
  245. }];
  246. }
  247. #pragma mark 添加直播间逻辑、视图
  248. - (void)addServiceController {
  249. if (_liveServiceController) {
  250. return;
  251. }
  252. _liveServiceController = [[BGLiveServiceController alloc]initWith:self.liveItem liveController:self];
  253. _liveServiceController.delegate = self;
  254. [_liveServiceController.liveUIViewController.liveView.voicebottomView removeFromSuperview];
  255. _liveServiceController.liveUIViewController.liveView.voicebottomView = nil;
  256. _liveServiceController.pluginCenterView.toolsView.toSDKdelegate = self;
  257. _liveServiceController.liveUIViewController.liveView.sdkDelegate = self;
  258. _liveServiceController.liveUIViewController.liveView.topView.toSDKDelegate = self;
  259. [self addChild:_liveServiceController inRect:self.view.bounds];
  260. __weak __typeof(self)weakSelf = self;
  261. //音效
  262. self.liveServiceController.liveUIViewController.playUrlBlock = ^(BGSoundEffectModel *model) {
  263. int EFFECT_ID = model.id.intValue;
  264. TXAudioMusicParam *bgmParam = [[TXAudioMusicParam alloc] init];
  265. bgmParam.ID = EFFECT_ID;
  266. bgmParam.path = model.url;
  267. bgmParam.publish = true;
  268. bgmParam.loopCount = 0;
  269. [[weakSelf.publishController.trtcCloud getAudioEffectManager] startPlayMusic:bgmParam onStart:^(NSInteger errCode) {
  270. } onProgress:^(NSInteger progressMs, NSInteger durationMs) {
  271. } onComplete:^(NSInteger errCode) {
  272. }];
  273. NSLog(@"播放音效 %@",model);
  274. };
  275. }
  276. #pragma mark - ----------------------- 重写父方法 -----------------------
  277. - (void)viewWillAppear:(BOOL)animated
  278. {
  279. [super viewWillAppear:animated];
  280. }
  281. - (void)viewWillDisappear:(BOOL)animated
  282. {
  283. [super viewWillDisappear:animated];
  284. }
  285. - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem modelArr:(NSArray *)modelArr
  286. {
  287. if (self = [super initWith:liveItem modelArr:modelArr])
  288. {
  289. self.modelArr = [NSMutableArray arrayWithArray:modelArr];
  290. for (int i = 0; i < modelArr.count; i++) {
  291. LivingModel *model = modelArr[i];
  292. if (model.room_id == liveItem.liveAVRoomId) {
  293. self.nowModel = model;
  294. self.now_LiveIndex = i;
  295. }
  296. }
  297. [self addServiceController];
  298. [self addSubViews];
  299. }
  300. return self;
  301. }
  302. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  303. {
  304. [super refreshLiveItem:liveItem liveInfo:liveInfo];
  305. //声网dev
  306. _linkMicPlayController.liveInfo = liveInfo;
  307. [_liveServiceController refreshLiveItem:liveItem liveInfo:liveInfo];
  308. }
  309. - (void)viewDidLoad
  310. {
  311. [super viewDidLoad];
  312. // [GlobalVariables sharedInstance].tliveView = self.view;
  313. ///////////// TiSDK 添加 开始 ////////////
  314. ///////////// TiSDK 添加 结束 /////////////
  315. if (self.BuguLive.appModel.mic_max_num >= 3 || self.BuguLive.appModel.mic_max_num == 0)
  316. {
  317. _micMaxNum = 3;
  318. }
  319. else
  320. {
  321. _micMaxNum = self.BuguLive.appModel.mic_max_num;
  322. }
  323. //初始化直播
  324. [self initLive];
  325. //#error TiSDK Key, 与包名对应,请联系商务获取
  326. NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key;
  327. if([BGUtils isBlankString:key])
  328. {
  329. //这里写上那个key
  330. key = @"517a990947274dd8b51e1525feb0fb79";
  331. // [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"美颜key为空,请尝试重新打开app获取!")];
  332. }
  333. else
  334. {
  335. // [TiSDK init:key];
  336. //
  337. // //在这里创建好像会被覆盖掉 你看看这里
  338. //
  339. // // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  340. // if([[GlobalVariables sharedInstance].appModel.spear_live isEqualToString:@"1"])
  341. // {
  342. // ///////////// TiSDK 添加 开始 ////////////
  343. //
  344. // // [[TiUIManager shareManager] loadToSuperview:self.view];
  345. // [TiUIManager shareManager].showsDefaultUI = NO;
  346. // [[TiUIManager shareManager]loadToWindowDelegate:nil];
  347. //
  348. //
  349. //// self.tiSDKManager = [[TiSDKManager alloc]init];
  350. ////// self.tiUIView = [[TiUIView alloc]initTiUIViewWith:self.tiSDKManager delegate:self superView:self.liveServiceController.liveUIViewController.view];
  351. ////// self.tiUIView.isClearOldUI = NO;
  352. ////// [self.tiUIView createTiUIView];
  353. // // 美颜控件
  354. // NSUInteger controlHeight = [BeautySettingPanel getHeight];
  355. // _beautyPanel = [[BeautySettingPanel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - controlHeight - MG_BOTTOM_MARGIN, self.view.frame.size.width, controlHeight + MG_BOTTOM_MARGIN)];
  356. // _beautyPanel.hidden = YES;
  357. // _beautyPanel.delegate = self;
  358. // _beautyPanel.pituDelegate = self;
  359. // [self.liveServiceController.liveUIViewController.view addSubview:_beautyPanel];
  360. // [_beautyPanel resetValues]; // 美颜设置初始值
  361. // }
  362. }
  363. }
  364. #pragma mark ---------美颜增加-------------
  365. - (GLuint)onPreProcessTexture:(GLuint)texture width:(CGFloat)width height:(CGFloat)height{
  366. if (self.tiSDKManager && [self.tiSDKManager renderTexture2D:texture Width:width Height:height Rotation:CLOCKWISE_0 Mirror:NO]) {
  367. /////////////////// TiFaceSDK 添加 开始 ///////////////////
  368. return [self.tiSDKManager renderTexture2D:texture Width:width Height:height Rotation:CLOCKWISE_0 Mirror:NO];
  369. /////////////////// TiFaceSDK 添加 结束 ///////////////////
  370. }
  371. return texture;
  372. }
  373. #pragma mark 腾讯云直播开始进入直播间:根据是否传入了聊天组ID选择对应的进入直播间的方案
  374. - (void)startEnterChatGroup:(NSString *)chatGroupID succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed
  375. {
  376. __weak typeof(self) ws = self;
  377. [_liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
  378. if (liveInfo)
  379. {
  380. ws.liveInfo = liveInfo;
  381. ws.hasVideoControl = liveInfo.has_video_control ? YES : NO;
  382. _reLiveProgressView.hidden = YES;
  383. ws.liveServiceController.liveUIViewController.livePay.payDelegate = self;
  384. if (![BGUtils isBlankString:liveInfo.push_rtmp] || ![BGUtils isBlankString:liveInfo.play_url])
  385. {
  386. [ws beginPlayVideo:liveInfo];
  387. }
  388. if (liveInfo.is_live_pay == 1 && liveInfo.is_pay_over == 0 && ![liveInfo.podcast.user.user_id isEqualToString:[[IMAPlatform sharedInstance].host imUserId]])
  389. {
  390. if (succ)
  391. {
  392. succ();
  393. }
  394. }
  395. else
  396. {
  397. [super startEnterChatGroup:liveInfo.group_id succ:^{
  398. [ws getVideoState:1];
  399. if (succ)
  400. {
  401. succ();
  402. }
  403. } failed:^(int errId, NSString *errMsg) {
  404. [ws getVideoState:0];
  405. if (failed)
  406. {
  407. failed(errId, errMsg);
  408. }
  409. }];
  410. }
  411. }
  412. else
  413. {
  414. [ws setGetVideoFailed:nil];
  415. if (failed)
  416. {
  417. failed(FWCode_Net_Error, ASLocalizedString(@"获取到的liveInfo为空"));
  418. }
  419. }
  420. }roomID:@"" failed:^(int errId, NSString *errMsg) {
  421. [ws setGetVideoFailed:errMsg];
  422. if (failed)
  423. {
  424. failed(errId, errMsg);
  425. }
  426. DebugLog(@"=========加载get_video接口出错 code: %d , msg = %@", errId, errMsg);
  427. }];
  428. }
  429. #pragma mark 加入聊天组成功
  430. - (void)enterChatGroupSucc:(CurrentLiveInfo *)liveInfo
  431. {
  432. [super enterChatGroupSucc:liveInfo];
  433. if (!_isHost && (_liveInfo.join_room_prompt == 1 || [[IMAPlatform sharedInstance].host getUserRank] >= self.BuguLive.appModel.jr_user_level))
  434. {
  435. _liveServiceController.liveUIViewController.liveView.canShowLightMessage = YES;
  436. }
  437. }
  438. #pragma mark 重写父方法: 业务上退出直播:退出的时候分SDK退出和业务退出,减少退出等待时间
  439. - (void)onServiceExitLive:(BOOL)isDirectCloseLive succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed
  440. {
  441. [_liveServiceController endLive];
  442. if (self.liveType == FW_LIVE_TYPE_HOST) // 主播
  443. {
  444. [_publishController endLive];
  445. [_liveServiceController showHostFinishView:@"" andVote:@"" andHasDel:NO];
  446. __weak typeof(self) ws = self;
  447. [[BGHUDHelper sharedInstance] syncLoading];
  448. [_liveServiceController hostExitLive:^{
  449. ws.publishController.leaveRoomBlockSuccess = ^{
  450. [[BGHUDHelper sharedInstance] syncStopLoading];
  451. if(isDirectCloseLive)
  452. {
  453. [ws onExitLiveUI];
  454. }
  455. if (succ)
  456. {
  457. succ();
  458. }
  459. };
  460. [ws.publishController.trtcCloud stopLocalPreview];
  461. [ws.publishController.trtcCloud stopLocalAudio];
  462. [ws.publishController.trtcCloud exitRoom];
  463. [TRTCCloud destroySharedInstance];
  464. } failed:^(int errId, NSString *errMsg) {
  465. [[BGHUDHelper sharedInstance] syncLoading];
  466. ws.publishController.leaveRoomBlockSuccess = ^{
  467. [[BGHUDHelper sharedInstance] syncStopLoading];
  468. if(isDirectCloseLive)
  469. {
  470. [ws onExitLiveUI];
  471. }
  472. failed(errId, errMsg);
  473. };
  474. [ws.publishController.trtcCloud stopLocalPreview];
  475. [ws.publishController.trtcCloud stopLocalAudio];
  476. [ws.publishController.trtcCloud exitRoom];
  477. [TRTCCloud destroySharedInstance];
  478. }];
  479. [_publishController stopRtmp];
  480. return;
  481. }
  482. if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  483. {
  484. [_linkMicPlayController endVideo];
  485. [self cancelMickingAlert];
  486. if ([_linkMicPlayController.linkMemeberSet containsObject:[[IMAPlatform sharedInstance].host imUserId]])
  487. {
  488. [BGLiveSDKViewModel tLiveStopMick:_roomIDStr toUserId:@""];
  489. }
  490. }
  491. if(isDirectCloseLive)
  492. {
  493. [self onExitLiveUI];
  494. }
  495. if (succ)
  496. {
  497. succ();
  498. }
  499. }
  500. #pragma mark 是否需要打断视频
  501. - (void)interruptionLiveIng:(BOOL)interruptioning
  502. {
  503. if (interruptioning)
  504. {
  505. [_liveServiceController pauseLive];
  506. if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
  507. {
  508. [_publishController.txLivePublisher pausePush];
  509. }
  510. else if([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
  511. {
  512. [_linkMicPlayController onAppDidEnterBackGround];
  513. }
  514. }
  515. else
  516. {
  517. [_liveServiceController resumeLive];
  518. if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST) // 直播的主播
  519. {
  520. [_publishController.txLivePublisher resumePush];
  521. }
  522. else if([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
  523. {
  524. [_linkMicPlayController onAppWillEnterForeground];
  525. }
  526. }
  527. }
  528. #pragma mark 是否正在被电话打断
  529. - (void)phoneInterruptioning:(BOOL)interruptioning
  530. {
  531. [super phoneInterruptioning:interruptioning];
  532. [self interruptionLiveIng:interruptioning];
  533. }
  534. #pragma mark app进入前台
  535. - (void)onAppEnterForeground
  536. {
  537. [super onAppEnterForeground];
  538. if (_isHost)
  539. {
  540. [super onAppEnterForeground];
  541. [_publishController.txLivePublisher resumePush];
  542. }
  543. else
  544. {
  545. if (_isMickAudiencePushing)
  546. {
  547. _isMickAudiencePushing = NO;
  548. [_linkMicPlayController.txLivePush resumePush];
  549. }
  550. }
  551. }
  552. #pragma mark app进入后台
  553. - (void)onAppEnterBackground
  554. {
  555. [super onAppEnterBackground];
  556. if (_isHost)
  557. {
  558. [super onAppEnterBackground];
  559. [_publishController.txLivePublisher pausePush];
  560. }
  561. else
  562. {
  563. if (_linkMicPlayController.txLivePush.isPublishing)
  564. {
  565. _isMickAudiencePushing = YES;
  566. [_linkMicPlayController.txLivePush pausePush];
  567. }
  568. }
  569. if (_toolsView)
  570. {
  571. // 关闭LED
  572. [BGUtils turnOnFlash:NO];
  573. ToolsCollectionViewCell *cell = (ToolsCollectionViewCell *)[_toolsView.toolsCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:0]];
  574. if (cell)
  575. {
  576. cell.toolImgView.image = [UIImage imageNamed:@"lr_plugin_flash_unsel"];
  577. }
  578. }
  579. }
  580. #pragma mark 重写退出方法
  581. - (void)onExitLiveUI
  582. {
  583. [super onExitLiveUI];
  584. // 执行下 悬浮参数退出
  585. if (SUS_WINDOW.isSusWindow &&SUS_WINDOW.isDirectCloseLive == YES)
  586. {
  587. [[LiveCenterManager sharedInstance]resetSuswindowPramaComple:^(BOOL finished) {
  588. }];
  589. }
  590. [_liveServiceController endLive];
  591. [_liveServiceController.view removeFromSuperview];
  592. // _liveServiceController = nil;
  593. if (_publishController)
  594. {
  595. _publishController = nil;
  596. }
  597. if (_playController)
  598. {
  599. _playController = nil;
  600. }
  601. if (_linkMicPlayController)
  602. {
  603. _linkMicPlayController = nil;
  604. }
  605. if (!SUS_WINDOW.isSusWindow)
  606. {
  607. self.navigationController.navigationBarHidden = NO;
  608. [self.navigationController popViewControllerAnimated:YES];
  609. }
  610. }
  611. #pragma mark 重写声音打断监听
  612. - (void)onAudioInterruption:(NSNotification *)notification
  613. {
  614. [super onAudioInterruption:notification];
  615. if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
  616. {
  617. [_linkMicPlayController onAudioInterruption:notification];
  618. }
  619. }
  620. #pragma mark 监听耳机插入和拔出
  621. - (void)audioRouteChangeListenerCallback:(NSNotification *)notification
  622. {
  623. [super audioRouteChangeListenerCallback:notification];
  624. NSDictionary *interuptionDict = notification.userInfo;
  625. NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
  626. switch (routeChangeReason)
  627. {
  628. case AVAudioSessionRouteChangeReasonNewDeviceAvailable: // 耳机插入
  629. // 开启耳返功能
  630. _publishController.txLivePushonfig.enableAudioPreview = YES;
  631. [_publishController.txLivePublisher setConfig:_publishController.txLivePushonfig];
  632. break;
  633. case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: // 耳机拔出,停止播放操作
  634. // 关闭耳返功能
  635. _publishController.txLivePushonfig.enableAudioPreview = NO;
  636. [_publishController.txLivePublisher setConfig:_publishController.txLivePushonfig];
  637. break;
  638. case AVAudioSessionRouteChangeReasonCategoryChange:
  639. // called at start - also when other audio wants to play
  640. NSLog(@"AVAudioSessionRouteChangeReasonCategoryChange");
  641. break;
  642. }
  643. }
  644. #pragma mark 重写弹出退出或直接退出
  645. /**
  646. 重写 弹出退出或直接退出
  647. @param isDirectCloseLive 该参数针对主播、观众,表示是否直播关闭直播,而不显示结束界面
  648. @param isHostShowAlert 该参数针对主播,表示主播是否需要弹出“您当前正在直播,是否退出直播?”,正常情况都需要弹出这个,不需要弹出的情况:1、当前直播被后台系统关闭了的情况 2、SDK结束了直播
  649. @param succ 成功回调
  650. @param failed 失败回调
  651. */
  652. - (void)alertExitLive:(BOOL)isDirectCloseLive isHostShowAlert:(BOOL)isHostShowAlert succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed
  653. {
  654. //在后面退出 基础类需要 这个判断 需不需要 Finish界面
  655. self.isDirectCloseLive = isDirectCloseLive;
  656. [self.liveServiceController.liveUIViewController.liveView.livewWishView.rotateTimer invalidate]; self.liveServiceController.liveUIViewController.liveView.livewWishView.rotateTimer = nil;
  657. LiveCenterManager *liveCenterManager = [LiveCenterManager sharedInstance];
  658. NSLog(@"%ld",_liveInfo.is_live_pay);
  659. if (self.isHost || !isDirectCloseLive || _liveInfo.is_live_pay == 1) {
  660. [liveCenterManager closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:isDirectCloseLive isHostShowAlert:isHostShowAlert colseLivecomplete:^(BOOL finished) {
  661. if (finished)
  662. {
  663. if (succ)
  664. {
  665. succ();
  666. }
  667. }
  668. else
  669. {
  670. if (failed)
  671. {
  672. failed(FWCode_Normal_Error, @"");
  673. }
  674. }
  675. }];
  676. }else{
  677. // [self.navigationController popViewControllerAnimated:YES];
  678. // if (isHostShowAlert) {
  679. [liveCenterManager closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:isDirectCloseLive isHostShowAlert:isHostShowAlert colseLivecomplete:^(BOOL finished) {
  680. if (isHostShowAlert) {
  681. [FanweMessage alert:ASLocalizedString(@"您被主播踢出直播间")];
  682. }
  683. if (finished)
  684. {
  685. if (succ)
  686. {
  687. succ();
  688. }
  689. }
  690. else
  691. {
  692. if (failed)
  693. {
  694. failed(FWCode_Normal_Error, @"");
  695. }
  696. }
  697. }];
  698. //悬浮小弹窗
  699. // }else{
  700. // [self showHoverViewWithAlert:isHostShowAlert];
  701. // }
  702. }
  703. }
  704. //悬浮view
  705. -(void)showHoverViewWithAlert:(BOOL)isHostShowAlert{
  706. NSLog(@"%@",self.liveServiceController);
  707. NSLog(@"%@",self.linkMicPlayController);
  708. //6-23 退出直播时关闭pk
  709. [self.liveServiceController.liveUIViewController pkVivewHidden];
  710. __weak __typeof(self)weakSelf = self;
  711. self.liveServiceController.clickCloseBlock = ^(BOOL isReresh) {
  712. [weakSelf.hoverView removeFromSuperview];
  713. weakSelf.hoverView = nil;
  714. [weakSelf.linkMicPlayController.view removeFromSuperview];
  715. weakSelf.linkMicPlayController.view = nil;
  716. };
  717. if (!self.hoverView) {
  718. self.hoverView = [[WMDragView alloc]init];
  719. self.hoverView.backgroundColor = kClearColor;
  720. self.hoverView.button.titleLabel.font = [UIFont systemFontOfSize:15.0];
  721. [self.hoverView.button setTitle:ASLocalizedString(@"可拖曳")forState:UIControlStateNormal];
  722. self.hoverView.button.hidden = YES;
  723. //2020-1-7 小直播变大
  724. self.hoverView.clickDragViewBlock = ^(WMDragView *dragView){
  725. [weakSelf.hoverView removeFromSuperview];
  726. weakSelf.hoverView = nil;
  727. [weakSelf.linkMicPlayController.view removeFromSuperview];
  728. weakSelf.linkMicPlayController.view = nil;
  729. [[LiveCenterManager sharedInstance] closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:YES isHostShowAlert:YES colseLivecomplete:^(BOOL finished) {
  730. weakSelf.linkMicPlayController.view = nil;
  731. weakSelf.linkMicPlayController = nil;
  732. // 直播管理中心开启观众直播
  733. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  734. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem: [LiveCenterManager sharedInstance].itemModel modelArr:nil isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
  735. }];
  736. }];
  737. };
  738. //__weak __typeof(self)weakSelf = self;
  739. self.hoverView.duringDragBlock = ^(WMDragView *dragView) {
  740. weakSelf.linkMicPlayController.videoContrainerView.frame = dragView.frame;
  741. };
  742. self.hoverView.endDragBlock = ^(WMDragView *dragView) {
  743. CGContextRef context = UIGraphicsGetCurrentContext();
  744. [UIView beginAnimations:@"rightMove" context:context];
  745. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  746. [UIView setAnimationDuration:0.5];
  747. weakSelf.linkMicPlayController.videoContrainerView.frame = dragView.frame;
  748. [UIView commitAnimations];
  749. };
  750. }
  751. CGRect frame = CGRectMake(kScreenW * 0.7, kScreenH / 2, kScreenW * 0.3, kScreenH * 0.25);
  752. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  753. // [btn setTitle:ASLocalizedString(@"关闭")forState:UIControlStateNormal];
  754. [btn setImage:[UIImage imageNamed:@"lr_top_close"] forState:UIControlStateNormal];
  755. [btn addTarget:self action:@selector(clickLive:) forControlEvents:UIControlEventTouchUpInside];
  756. btn.frame = CGRectMake(frame.size.width - 40, 0, 40, 40);
  757. [self.hoverView addSubview:btn];
  758. //直播界面vc的view
  759. _linkMicPlayController.view.frame = frame;
  760. _linkMicPlayController.view.backgroundColor = kClearColor;
  761. //5-7 悬浮小窗口的阴影
  762. _linkMicPlayController.pkBgView.hidden=YES;
  763. [_linkMicPlayController.pkBgView removeAllSubViews];
  764. _linkMicPlayController.pkBgView=nil;
  765. //hoverView,拖拽的view
  766. self.hoverView.frame = _linkMicPlayController.view.bounds;
  767. //在直播VC上放置视频的view
  768. _linkMicPlayController.videoContrainerView.frame = _linkMicPlayController.view.bounds;
  769. [[BGBaseAppDelegate sharedAppDelegate].window addSubview:_linkMicPlayController.view];
  770. [_linkMicPlayController.view addSubview:self.hoverView];
  771. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clickLive:) name:@"clickLiveRoomNotification" object:nil];
  772. }
  773. //- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  774. // NSLog(@"%@", touches);
  775. // UITouch *touch = [touches anyObject];
  776. //
  777. // //当前的point
  778. // CGPoint currentP = [touch locationInView:self.hoverView];
  779. //
  780. // //以前的point
  781. // CGPoint preP = [touch previousLocationInView:self.hoverView];
  782. //
  783. // //x轴偏移的量
  784. // CGFloat offsetX = currentP.x - preP.x;
  785. //
  786. // //Y轴偏移的量
  787. // CGFloat offsetY = currentP.y - preP.y;
  788. //
  789. // self.hoverView.transform = CGAffineTransformTranslate(self.hoverView.transform, offsetX, offsetY);
  790. //}
  791. //
  792. //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  793. //{
  794. //
  795. //}
  796. //观众关闭直播走的方法
  797. -(void)clickLive:(UIButton *)sender{
  798. self.hoverView.hidden = self.linkMicPlayController.view.hidden = YES;
  799. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  800. dispatch_async(dispatch_get_main_queue(), ^{
  801. [self.hoverView removeFromSuperview];
  802. self.hoverView = nil;
  803. [self.linkMicPlayController.view removeFromSuperview];
  804. self.liveView = nil;
  805. [self clickEndLive];
  806. });
  807. });
  808. }
  809. -(void)clickEndLive{
  810. LiveCenterManager *liveCenterManager = [LiveCenterManager sharedInstance];
  811. __weak __typeof(self)weakSelf = self;
  812. //4-16 1.苹果端打字不显示直播间自带的发送,手机上面的发送可以用,我手机是苹果11
  813. [liveCenterManager closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:YES isHostShowAlert:YES colseLivecomplete:^(BOOL finished) {
  814. weakSelf.linkMicPlayController.view = nil;
  815. weakSelf.linkMicPlayController = nil;
  816. weakSelf.linkMicPlayController.view = nil;
  817. }];
  818. }
  819. #pragma mark - ----------------------- 部分业务逻辑 -----------------------
  820. #pragma mark 请求get_video接口失败的情况
  821. - (void)setGetVideoFailed:(NSString *)errMsg
  822. {
  823. NSString *errStr = errMsg;
  824. if ([BGUtils isBlankString:errStr])
  825. {
  826. errStr = ASLocalizedString(@"获取聊天室信息失败,请稍候尝试");
  827. }
  828. [self getVideoState:0];
  829. __weak typeof(self) ws = self;
  830. [BGHUDHelper alert:errStr action:^{
  831. [ws onExitLiveUI];
  832. }];
  833. }
  834. #pragma mark 真正开始播放
  835. - (void)beginPlayVideo:(CurrentLiveInfo *)liveInfo
  836. {
  837. _iMMsgHandler.isEnterRooming = NO;
  838. __weak typeof(self) ws = self;
  839. if (self.liveType == FW_LIVE_TYPE_HOST)
  840. {
  841. if (liveInfo.push_rtmp && ![liveInfo.push_rtmp isEqualToString:@""])
  842. {
  843. //声网dev
  844. _publishController.agora_token = liveInfo.agora_token;
  845. _publishController.pushUrlStr = liveInfo.push_rtmp;
  846. if (![GlobalVariables sharedInstance].isOtherPush) {
  847. [_publishController startPushRtmpLiveMethod];
  848. }
  849. }
  850. else
  851. {
  852. [BGHUDHelper alert:ASLocalizedString(@"抱歉,推流地址为空,请稍后尝试")action:^{
  853. [ws alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
  854. }];
  855. }
  856. }
  857. else if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  858. {
  859. if (liveInfo.play_url && ![liveInfo.play_url isEqualToString:@""])
  860. {
  861. // if (!([self.BuguLive.appModel.open_vip intValue] == 1 && liveInfo.is_vip == 0))
  862. // {
  863. _linkMicPlayController.playUrlStr = liveInfo.play_url;
  864. _linkMicPlayController.agora_token = liveInfo.agora_token;
  865. _linkMicPlayController.roomIDStr = self.roomIDStr;
  866. // _linkMicPlayController.roomIDStr = liveInfo.agora_token;
  867. [_linkMicPlayController startRtmp:liveInfo.create_type];
  868. // }
  869. }
  870. else
  871. {
  872. // [BGHUDHelper alert:ASLocalizedString(@"抱歉,播放地址为空,请稍后尝试")action:^{
  873. // [ws alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
  874. // }];
  875. }
  876. }
  877. if (_isHost)
  878. {
  879. [_liveServiceController startLiveTimer];
  880. }
  881. }
  882. #pragma mark 请求video_cstatus接口来获取直播间信息
  883. - (void)getVideoState:(NSInteger)state
  884. {
  885. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  886. [mDict setObject:@"video" forKey:@"ctl"];
  887. [mDict setObject:@"video_cstatus" forKey:@"act"];
  888. [mDict setObject:[NSString stringWithFormat:@"%d",[self.liveItem liveAVRoomId]] forKey:@"room_id"];
  889. [mDict setObject:StringFromInteger(state) forKey:@"status"];
  890. if ([self.liveItem liveIMChatRoomId] && ![[self.liveItem liveIMChatRoomId] isEqualToString:@""])
  891. {
  892. [mDict setObject:[self.liveItem liveIMChatRoomId] forKey:@"group_id"];
  893. }
  894. [_liveServiceController getVideoState:mDict];
  895. }
  896. //#pragma mark - ----------------------- 回放相关界面事件操作 -----------------------
  897. //#pragma mark 进度条事件
  898. //- (void)onClickPlay
  899. //{
  900. // [_playController clickPlay:_btnPlay create_type:self.liveInfo.create_type];
  901. //}
  902. //
  903. //- (void)onSeek
  904. //{
  905. // [_playController onSeek:_playProgress];
  906. //}
  907. //
  908. //- (void)onSeekBegin
  909. //{
  910. // [_playController onSeekBegin:_playProgress];
  911. //}
  912. //
  913. //- (void)onDrag
  914. //{
  915. // [_playController onDrag:_playProgress];
  916. //}
  917. //
  918. //- (void)dragSliderDidEnd:(UISlider *)slider
  919. //{
  920. // [_playController dragSliderDidEnd:_playProgress];
  921. //}
  922. #pragma mark - ----------------------- 连麦 -----------------------
  923. #pragma mark 观众检查是否有连麦权限(主播不需要此操作)
  924. - (void)audienceCheckMick
  925. {
  926. //检查是否有连麦权限
  927. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  928. [mDict setObject:@"video" forKey:@"ctl"];
  929. [mDict setObject:@"check_lianmai" forKey:@"act"];
  930. [mDict setObject:_roomIDStr forKey:@"room_id"];
  931. [SVProgressHUD show];
  932. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  933. [SVProgressHUD dismiss];
  934. NSString *agora_token = responseJson[@"agora_token"];
  935. self.linkMicPlayController.agora_token = agora_token;
  936. if ([responseJson toInt:@"status"] == 1)
  937. {
  938. __weak BGIMMsgHandler *wd = _iMMsgHandler;
  939. FWWeakify(self)
  940. [FanweMessage alert:nil message:ASLocalizedString(@"是否请求与主播连麦?")destructiveAction:^{
  941. FWStrongify(self)
  942. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  943. sendCustomMsgModel.msgType = MSG_APPLY_MIKE;
  944. sendCustomMsgModel.msgReceiver = [self.liveItem liveHost];
  945. [wd sendCustomC2CMsg:sendCustomMsgModel succ:^{
  946. [self performSelector:@selector(alertLinkMicking) withObject:nil afterDelay:0.2];
  947. } fail:^(int code, NSString *msg) {
  948. [FanweMessage alertHUD:ASLocalizedString(@"您的连麦申请发送失败")];
  949. }];
  950. } cancelAction:^{
  951. }];
  952. }
  953. } FailureBlock:^(NSError *error) {
  954. }];
  955. }
  956. #pragma mark 主播判断某个观众是否互动观众
  957. - (BOOL)isInteractUser:(NSString *)userId
  958. {
  959. if (userId)
  960. {
  961. for (NSString *tmpUserId in _linkMicPlayController.linkMemeberSet)
  962. {
  963. if ([userId isEqualToString:tmpUserId])
  964. {
  965. return YES;
  966. }
  967. }
  968. }
  969. return NO;
  970. }
  971. #pragma mark 观众发起连麦,关闭连麦
  972. - (void)openOrCloseMike:(BGLiveServiceController *)liveServiceController
  973. {
  974. if (_linkMicPlayController.isWaitingResponse)
  975. {
  976. [FanweMessage alertHUD:ASLocalizedString(@"连麦申请中...")];
  977. return;
  978. }
  979. if (self.linkMicPlayController.isLinkingMic) {
  980. FWWeakify(self)
  981. [FanweMessage alert:nil message:ASLocalizedString(@"是否结束与主播的互动连麦?")destructiveAction:^{
  982. FWStrongify(self)
  983. [self.linkMicPlayController stopLinkMic];
  984. // [self.linkMicPlayController startRtmp:self.liveInfo.create_type];
  985. } cancelAction:^{
  986. }];
  987. }
  988. // if ([self isInteractUser:[[IMAPlatform sharedInstance].host imUserId]])
  989. // {
  990. // FWWeakify(self)
  991. // [FanweMessage alert:nil message:ASLocalizedString(@"是否结束与主播的互动连麦?")destructiveAction:^{
  992. //
  993. // FWStrongify(self)
  994. // [self.linkMicPlayController stopLinkMic];
  995. // [self.linkMicPlayController startRtmp:self.liveInfo.create_type];
  996. //
  997. // } cancelAction:^{
  998. //
  999. // }];
  1000. // }
  1001. else
  1002. {
  1003. [self audienceCheckMick];
  1004. }
  1005. }
  1006. #pragma mark 申请连麦中,等待对方应答...
  1007. - (void)alertLinkMicking
  1008. {
  1009. _isApplyMicking = YES;
  1010. FWWeakify(self)
  1011. _applyMickingAlert = [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"申请连麦中,等待对方应答...")isHideTitle:NO destructiveTitle:ASLocalizedString(@"取消连麦")destructiveAction:^{
  1012. FWStrongify(self)
  1013. self.isApplyMicking = NO;
  1014. [self performSelector:@selector(releaseMickingAlert) withObject:nil afterDelay:0.5];
  1015. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  1016. sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
  1017. sendCustomMsgModel.msgReceiver = [self.liveItem liveHost];
  1018. sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
  1019. [self.iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
  1020. }];
  1021. }
  1022. #pragma mark 关闭申请连麦中的提示
  1023. - (void)cancelMickingAlert
  1024. {
  1025. if (_applyMickingAlert)
  1026. {
  1027. _isApplyMicking = NO;
  1028. [_applyMickingAlert hide];
  1029. [self performSelector:@selector(releaseMickingAlert) withObject:nil afterDelay:0.5];
  1030. }
  1031. }
  1032. - (void)releaseMickingAlert
  1033. {
  1034. if (_applyMickingAlert)
  1035. {
  1036. _applyMickingAlert = nil;
  1037. }
  1038. }
  1039. - (void)releaseHostMickingAlert
  1040. {
  1041. if (_hostMickingAlert)
  1042. {
  1043. _hostMickingAlert = nil;
  1044. }
  1045. }
  1046. #pragma mark 主播获取连麦参数
  1047. - (void)getMickPara:(CustomMessageModel *)customMessageModel
  1048. {
  1049. // _isResponseMicking = YES;
  1050. // _isResponseMicking = YES;
  1051. //检查是否有连麦权限
  1052. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1053. [mDict setObject:@"video" forKey:@"ctl"];
  1054. [mDict setObject:@"start_lianmai" forKey:@"act"];
  1055. [mDict setObject:_roomIDStr forKey:@"room_id"];
  1056. [mDict setObject:customMessageModel.sender.user_id forKey:@"to_user_id"];
  1057. __weak typeof(self) ws = self;
  1058. __weak BGIMMsgHandler *wm = (BGIMMsgHandler *)_iMMsgHandler;
  1059. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  1060. if ([responseJson toInt:@"status"] == 1)
  1061. {
  1062. NSString *push_rtmp2 = [responseJson toString:@"push_rtmp2"];
  1063. NSString *play_rtmp_acc = [responseJson toString:@"play_rtmp_acc"];
  1064. if (![BGUtils isBlankString:push_rtmp2] && ![BGUtils isBlankString:play_rtmp_acc])
  1065. {
  1066. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  1067. sendCustomMsgModel.msgType = MSG_RECEIVE_MIKE;
  1068. sendCustomMsgModel.push_rtmp2 = push_rtmp2;
  1069. sendCustomMsgModel.play_rtmp_acc = play_rtmp_acc;
  1070. sendCustomMsgModel.link_mic_user_id = customMessageModel.sender.user_id;
  1071. sendCustomMsgModel.msgReceiver = customMessageModel.sender;
  1072. sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
  1073. [wm sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  1074. [ws.publishController agreeLinkMick:[responseJson toString:@"play_rtmp2_acc"] applicant:customMessageModel.sender.user_id];
  1075. }
  1076. else
  1077. {
  1078. ws.isResponseMicking = NO;
  1079. [FanweMessage alertHUD:ASLocalizedString(@"获取连麦参数失败")];
  1080. }
  1081. }
  1082. else
  1083. {
  1084. ws.isResponseMicking = NO;
  1085. }
  1086. } FailureBlock:^(NSError *error) {
  1087. ws.isResponseMicking = NO;
  1088. }];
  1089. }
  1090. #pragma mark 主播收到观众连麦请求
  1091. - (void)onRecvGuestApply:(CustomMessageModel *)customMessageModel
  1092. {
  1093. SenderModel *sender = customMessageModel.sender;
  1094. if ([_publishController.linkMemeberSet count] >= _micMaxNum || _hostMickingAlert || _isResponseMicking)
  1095. {
  1096. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  1097. sendCustomMsgModel.msgType = MSG_REFUSE_MIKE;
  1098. sendCustomMsgModel.msgReceiver = customMessageModel.sender;
  1099. if (_hostMickingAlert || _isResponseMicking)
  1100. {
  1101. sendCustomMsgModel.msg = ASLocalizedString(@"主播有未处理的连麦请求,请稍候再试");
  1102. [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
  1103. }
  1104. else
  1105. {
  1106. DebugLog(@"已达到请求上限,不能再请求");
  1107. sendCustomMsgModel.msg = ASLocalizedString(@"当前主播连麦数已上限,请稍后尝试");
  1108. [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
  1109. }
  1110. }
  1111. else
  1112. {
  1113. __weak BGIMMsgHandler *wm = (BGIMMsgHandler *)_iMMsgHandler;
  1114. NSString *text = [NSString stringWithFormat:ASLocalizedString(@"%@向你发来连麦请求"), [sender imUserName]];
  1115. FWWeakify(self)
  1116. _hostMickingAlert = [FanweMessage alert:ASLocalizedString(@"提示")message:text destructiveTitle:ASLocalizedString(@"同意")destructiveAction:^{
  1117. FWStrongify(self)
  1118. // 同意
  1119. [self getMickPara:customMessageModel];
  1120. [self performSelector:@selector(releaseHostMickingAlert) withObject:nil afterDelay:0.2];
  1121. } cancelTitle:ASLocalizedString(@"拒绝")cancelAction:^{
  1122. FWStrongify(self)
  1123. // 拒绝
  1124. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  1125. sendCustomMsgModel.msgType = MSG_REFUSE_MIKE;
  1126. sendCustomMsgModel.msgReceiver = customMessageModel.sender;
  1127. [wm sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
  1128. [self performSelector:@selector(releaseHostMickingAlert) withObject:nil afterDelay:0.2];
  1129. }];
  1130. }
  1131. }
  1132. #pragma mark 主播未处理连麦申请时,kApplyMikeTime秒后关闭申请连麦弹出框
  1133. - (void)closeAlertView
  1134. {
  1135. if (_hostMickingAlert)
  1136. {
  1137. [_hostMickingAlert hide];
  1138. [self performSelector:@selector(releaseHostMickingAlert) withObject:nil afterDelay:0.2];
  1139. }
  1140. }
  1141. - (void)showRefuseHud:(NSString *)refuseStr
  1142. {
  1143. [FanweMessage alert:refuseStr];
  1144. }
  1145. #pragma mark FWTLinkMicPlayControllerDelegate
  1146. /*
  1147. * 观众端连麦结果
  1148. * isSucc:是否上麦
  1149. * userID:当前用户ID
  1150. */
  1151. - (void)pushMickResult:(BOOL)isSucc userID:(NSString *)userID
  1152. {
  1153. if (![BGUtils isBlankString:userID])
  1154. {
  1155. if (isSucc)
  1156. {
  1157. if ([[[IMAPlatform sharedInstance].host imUserId] isEqualToString:userID])
  1158. {
  1159. // [BGLiveSDKViewModel tLiveMixStream:_roomIDStr toUserId:@""];
  1160. }
  1161. }
  1162. else
  1163. {
  1164. if ([[[IMAPlatform sharedInstance].host imUserId] isEqualToString:userID])
  1165. {
  1166. [BGLiveSDKViewModel tLiveStopMick:_roomIDStr toUserId:@""];
  1167. }
  1168. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  1169. sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
  1170. sendCustomMsgModel.msgReceiver = [self.liveItem liveHost];
  1171. sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
  1172. [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  1173. }
  1174. }
  1175. }
  1176. #pragma mark FWTLinkMicPublishControllerDelegate
  1177. /*
  1178. * 主播端连麦结果
  1179. * isSucc:是否拉取观众连麦加速流成功
  1180. * userID:拉取的连麦观众对应的ID
  1181. */
  1182. - (void)playMickResult:(BOOL)isSucc userID:(NSString *)userID
  1183. {
  1184. _isResponseMicking = NO;
  1185. if (![BGUtils isBlankString:userID])
  1186. {
  1187. if (isSucc)
  1188. {
  1189. [BGLiveSDKViewModel tLiveMixStream:_roomIDStr toUserId:userID];
  1190. }
  1191. }
  1192. }
  1193. #pragma mark 主播点击屏幕时,判断是否点击了连麦窗口
  1194. - (void)hostReceiveTouch:(UITouch *)touch
  1195. {
  1196. if ([_publishController.linkMemeberSet count])
  1197. {
  1198. for (NSString *user in _publishController.linkMemeberSet)
  1199. {
  1200. BGTLinkMicPlayItem *playItem = [self.publishController getPlayItemByUserID:user];
  1201. if (playItem)
  1202. {
  1203. if(CGRectContainsPoint(playItem.videoView.frame, [touch locationInView:self.publishController.view]))
  1204. {
  1205. UserModel *userModel;
  1206. for (UserModel *tmpModel in _liveServiceController.liveUIViewController.liveView.topView.userArray)
  1207. {
  1208. if ([tmpModel.user_id isEqualToString:user])
  1209. {
  1210. userModel = tmpModel;
  1211. break;
  1212. }
  1213. }
  1214. if (!userModel)
  1215. {
  1216. userModel = [[UserModel alloc]init];
  1217. userModel.user_id = user;
  1218. }
  1219. MMPopupCompletionBlock completeBlock = ^(MMPopupView *popupView, BOOL finished){
  1220. NSLog(@"animation complete");
  1221. };
  1222. HostCheckMickAlertView *view = [[HostCheckMickAlertView alloc] initAlertView:userModel closeMickBlock:^(UserModel *userModel) {
  1223. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  1224. sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
  1225. sendCustomMsgModel.msgReceiver = userModel;
  1226. sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
  1227. [[BGIMMsgHandler sharedInstance] sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  1228. [BGLiveSDKViewModel tLiveStopMick:_roomIDStr toUserId:userModel.user_id];
  1229. }];
  1230. [view showWithBlock:completeBlock];
  1231. }
  1232. }
  1233. }
  1234. }
  1235. }
  1236. #pragma mark - ----------------------- 横竖屏 -----------------------
  1237. - (void)goVerticalScreen
  1238. {
  1239. [self interfaceOrientation:UIInterfaceOrientationPortrait];
  1240. }
  1241. #pragma mark PC直播或者PC回播,观众端的点击全屏事件
  1242. - (void)clickFullScreen
  1243. {
  1244. [self interfaceOrientation:UIInterfaceOrientationLandscapeRight];
  1245. }
  1246. - (void)interfaceOrientation:(UIInterfaceOrientation)orientation
  1247. {
  1248. if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
  1249. {
  1250. SEL selector = NSSelectorFromString(@"setOrientation:");
  1251. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
  1252. [invocation setSelector:selector];
  1253. [invocation setTarget:[UIDevice currentDevice]];
  1254. int val = orientation;
  1255. [invocation setArgument:&val atIndex:2];
  1256. [invocation invoke];
  1257. }
  1258. }
  1259. - (void)deviceOrientationDidChange
  1260. {
  1261. if (self.liveInfo.create_type == 1)
  1262. {
  1263. NSLog(@"deviceOrientationDidChange:%ld",(long)[UIDevice currentDevice].orientation);
  1264. if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait)
  1265. {
  1266. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
  1267. [self orientationChange:kDirectionTypeDefault];
  1268. }
  1269. else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft)
  1270. {
  1271. [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
  1272. [self orientationChange:kDirectionTypeLeft];
  1273. }
  1274. }
  1275. }
  1276. - (void)orientationChange:(kDirectionType)landscape
  1277. {
  1278. if (landscape == kDirectionTypeDefault)
  1279. {
  1280. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  1281. _liveServiceController.liveUIViewController.liveView.hidden = NO;
  1282. _liveServiceController.closeBtn.hidden = NO;
  1283. [UIView animateWithDuration:0.2f animations:^{
  1284. self.view.transform = CGAffineTransformMakeRotation(0);
  1285. self.view.bounds = CGRectMake(0, 0, kScreenW, kScreenH);
  1286. if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  1287. {
  1288. _linkMicPlayController.videoContrainerView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  1289. self.backVerticalBtn.hidden = YES;
  1290. }
  1291. }];
  1292. }
  1293. else if (landscape == kDirectionTypeLeft)
  1294. {
  1295. [[UIApplication sharedApplication] setStatusBarHidden:YES];
  1296. _liveServiceController.liveUIViewController.liveView.hidden = YES;
  1297. _liveServiceController.closeBtn.hidden = YES;
  1298. [UIView animateWithDuration:0.2f animations:^{
  1299. self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
  1300. self.view.bounds = CGRectMake(0, 0, kScreenW, kScreenH);
  1301. if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  1302. {
  1303. _linkMicPlayController.videoContrainerView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  1304. self.backVerticalBtn.hidden = NO;
  1305. }
  1306. }];
  1307. }
  1308. }
  1309. #pragma mark - ----------------------- 代理方法 -----------------------
  1310. #pragma mark FWLiveServiceControllerDelegate
  1311. #pragma mark 收到自定义C2C消息
  1312. - (void)recvCustomC2C:(id<AVIMMsgAble>)msg
  1313. {
  1314. if (![msg isKindOfClass:[CustomMessageModel class]])
  1315. {
  1316. return;
  1317. }
  1318. CustomMessageModel *customMessageModel = (CustomMessageModel *)msg;
  1319. switch (customMessageModel.type)
  1320. {
  1321. case MSG_APPLY_MIKE: // 观众申请连麦(主播收到观众连麦请求消息)
  1322. {
  1323. // 关闭键盘
  1324. [BGUtils closeKeyboard];
  1325. _linkMicPlayController.isWaitingResponse = YES;
  1326. [self onRecvGuestApply:customMessageModel];
  1327. // [_publishController breakLinkMick:customMessageModel.sender.user_id];
  1328. }
  1329. break;
  1330. case MSG_RECEIVE_MIKE: // 主播接受连麦(观众收到主播接受连麦消息)
  1331. {
  1332. if (_isApplyMicking == NO)
  1333. {
  1334. break;
  1335. }
  1336. // 关闭键盘
  1337. [BGUtils closeKeyboard];
  1338. [self cancelMickingAlert];
  1339. if (![BGUtils isBlankString:customMessageModel.push_rtmp2] && ![BGUtils isBlankString:customMessageModel.play_rtmp_acc])
  1340. {
  1341. // [_linkMicPlayController stopRtmp];
  1342. //开始连麦,启动推流
  1343. _linkMicPlayController.push_rtmp2 = customMessageModel.push_rtmp2;
  1344. _linkMicPlayController.play_rtmp_acc = customMessageModel.play_rtmp_acc;
  1345. _linkMicPlayController.isWaitingResponse = NO;
  1346. [_linkMicPlayController startVideoLiveLinkMic];
  1347. [self cancelMickingAlert];
  1348. }
  1349. else
  1350. {
  1351. [FanweMessage alertHUD:ASLocalizedString(@"获取连麦参数失败")];
  1352. }
  1353. }
  1354. break;
  1355. case MSG_REFUSE_MIKE: // 主播拒绝连麦(观众收到主播拒绝连麦消息)
  1356. {
  1357. [self cancelMickingAlert];
  1358. _linkMicPlayController.isWaitingResponse = NO;
  1359. NSString *refuseStr = ASLocalizedString(@"主播拒绝了您的连麦请求");
  1360. if (![BGUtils isBlankString:customMessageModel.msg])
  1361. {
  1362. refuseStr = customMessageModel.msg;
  1363. }
  1364. [self showRefuseHud:refuseStr];
  1365. }
  1366. break;
  1367. case MSG_BREAK_MIKE: // 断开连麦(观众收到主播断开连麦消息 或者 主播收到观众主动断开连麦消息)
  1368. {
  1369. if (_isHost) // 主播收到观众主动断开连麦消息
  1370. {
  1371. [self closeAlertView];
  1372. [_publishController breakLinkMick:customMessageModel.sender.user_id];
  1373. }
  1374. else
  1375. {
  1376. [_linkMicPlayController stopLinkMic];
  1377. [_linkMicPlayController startRtmp:self.liveInfo.create_type];
  1378. }
  1379. }
  1380. break;
  1381. case MSG_ACCEPT_PK:
  1382. {
  1383. // if (_isApplyMicking)
  1384. // {
  1385. // 关闭键盘
  1386. [BGUtils closeKeyboard];
  1387. //接受pk!!
  1388. // }
  1389. }
  1390. break;
  1391. case MSG_END_PK:
  1392. {
  1393. // if (_isApplyMicking)
  1394. // {
  1395. // 关闭键盘
  1396. [BGUtils closeKeyboard];
  1397. //接受pk!!
  1398. // }
  1399. }
  1400. break;
  1401. default:
  1402. break;
  1403. }
  1404. }
  1405. #pragma mark 收到自定义的Group消息
  1406. - (void)recvCustomGroup:(id<AVIMMsgAble>)msg
  1407. {
  1408. if (![msg isKindOfClass:[CustomMessageModel class]])
  1409. {
  1410. return;
  1411. }
  1412. CustomMessageModel *customMessageModel = (CustomMessageModel *)msg;
  1413. switch (customMessageModel.type)
  1414. {
  1415. case MSG_SEND_GIFT_SUCCESS:
  1416. {
  1417. [_linkMicPlayController updateLianMaiCoin];
  1418. [_publishController updateLianMaiCoin];
  1419. }
  1420. break;
  1421. case MSG_LianMai_Mute: // 主播把我静音
  1422. {
  1423. // [_linkMicPlayController muteStatus:customMessageModel.mute_status andUserId:customMessageModel.to_user_id];
  1424. }
  1425. break;
  1426. case MSG_REFRESH_AUDIENCE_LIST: // 主播、所有连麦观众收到的定时连麦消息
  1427. {
  1428. // 当 data_type == 1,主播、所有连麦观众收到的定时连麦消息
  1429. if (customMessageModel.data_type == 1)
  1430. {
  1431. TLiveMickListModel *mickListModel = [TLiveMickListModel mj_objectWithKeyValues:customMessageModel.data];
  1432. if (self.liveType == FW_LIVE_TYPE_HOST)
  1433. {
  1434. [_publishController adjustPlayItem:mickListModel];
  1435. }
  1436. else if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
  1437. {
  1438. [_linkMicPlayController adjustPlayItem:mickListModel];
  1439. }
  1440. }
  1441. }
  1442. break;
  1443. case MSG_REFRESH_VOICE_Lianmai:
  1444. {
  1445. NSLog(@"========>>>>>>>>>>>>>>>");
  1446. NSLog(@"%@",customMessageModel.dicData);
  1447. NSArray *list = [NSArray modelArrayWithClass:VoiceLianmaiUserModel.class json:customMessageModel.dicData[@"data"]];
  1448. if (self.liveType == FW_LIVE_TYPE_HOST)
  1449. {
  1450. [_publishController adjustPlayItemVoiceUserList:list];
  1451. }
  1452. else if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
  1453. {
  1454. [_linkMicPlayController adjustPlayItemVoiceUserList:list];
  1455. }
  1456. NSLog(@"========>>>>>>>>>>>>>>>");
  1457. // 当 data_type == 1,主播、所有连麦观众收到的定时连麦消息
  1458. // if (customMessageModel.data_type == 1)
  1459. // {
  1460. // TLiveMickListModel *mickListModel = [TLiveMickListModel mj_objectWithKeyValues:customMessageModel.data];
  1461. //
  1462. // if (self.liveType == FW_LIVE_TYPE_HOST)
  1463. // {
  1464. // [_publishController adjustPlayItem:mickListModel];
  1465. // }
  1466. // else if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
  1467. // {
  1468. // [_linkMicPlayController adjustPlayItem:mickListModel];
  1469. // }
  1470. // }
  1471. }
  1472. break;
  1473. case MSG_RECEIVE_MIKE: // 主播接受连麦(观众收到主播接受连麦消息)
  1474. {
  1475. _linkMicPlayController.isWaitingResponse = NO;
  1476. if (_isApplyMicking)
  1477. {
  1478. // 关闭键盘
  1479. [BGUtils closeKeyboard];
  1480. [self cancelMickingAlert];
  1481. }
  1482. }
  1483. break;
  1484. case MSG_REFUSE_MIKE: // 主播拒绝连麦(观众收到主播拒绝连麦消息)
  1485. {
  1486. _linkMicPlayController.isWaitingResponse = NO;
  1487. // 关闭键盘
  1488. [BGUtils closeKeyboard];
  1489. [self cancelMickingAlert];
  1490. }
  1491. break;
  1492. default:
  1493. break;
  1494. }
  1495. // if([customMessageModel.link_mic_user_id isEqualToString:[IMAPlatform sharedInstance].host.userId])
  1496. }
  1497. #pragma mark 请求完接口后,刷新直播间相关信息
  1498. - (void)refreshCurrentLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
  1499. {
  1500. [self refreshLiveItem:liveItem liveInfo:liveInfo];
  1501. }
  1502. #pragma mark 点击飞屏模式,切换直播间(因切换房间涉及到比较多的逻辑,比如:付费、游戏,所以该方法暂时不用)
  1503. - (void)switchLiveRoom
  1504. {
  1505. [self stopLiveRtmp];
  1506. [self startEnterChatGroup:nil succ:^{
  1507. NSLog(@"11111");
  1508. } failed:^(int errId, NSString *errMsg) {
  1509. NSLog(@"22222");
  1510. }];
  1511. }
  1512. #pragma mark 关闭直播间代理事件
  1513. - (void)clickCloseLive:(BOOL)isDirectCloseLive isHostShowAlert:(BOOL)isHostShowAlert
  1514. {
  1515. // [self.linkMicPlayController.agoraKit leaveChannel:^(AgoraChannelStats * _Nonnull stat) {
  1516. //
  1517. // }];
  1518. [self.linkMicPlayController.trtcCloud exitRoom];
  1519. [TRTCCloud destroySharedInstance];
  1520. [self alertExitLive:isDirectCloseLive isHostShowAlert:isHostShowAlert succ:nil failed:nil];
  1521. }
  1522. #pragma mark 结束界面点击“返回首页”
  1523. - (void)finishViewClose:(BGLiveServiceController *)liveServiceController
  1524. {
  1525. UITabBarController *tabBars = [BGTabBarController sharedInstance];
  1526. tabBars.selectedIndex = 0;
  1527. // 已经走到这里了 必然更改记录
  1528. SUS_WINDOW.isDirectCloseLive = YES;
  1529. [self onExitLiveUI];
  1530. }
  1531. #pragma mark PlayControllerDelegate 结束回播,用来判断是否还有下一段回播
  1532. - (void)stopReLive
  1533. {
  1534. // 暂时不用做什么操作
  1535. }
  1536. #pragma mark ToolsViewDelegate
  1537. - (void)selectToolsItemWith:(ToolsView *)toolsView selectIndex:(NSInteger)index isSelected:(BOOL)isSelected
  1538. {
  1539. _toolsView = toolsView;
  1540. if (index == 999)
  1541. { // 音乐
  1542. if ([GlobalVariables sharedInstance].isOtherPush) {
  1543. self.otherPushPopView.liveInfo = self.liveInfo;
  1544. [self.otherPushPopView show:self.view type:FDPopTypeCenter];
  1545. }else{
  1546. [[[YunMusicPlayVC alloc] init] showYunMusicPlayInVC:self inview:self.liveServiceController.liveUIViewController.liveView showframe:CGRectMake(0,200, self.view.bounds.size.width,130) myPlayType:0];
  1547. }
  1548. }
  1549. else if (index == 0)
  1550. { // 美颜
  1551. // 如果key不为空就调用笑脸点击后出现的美颜控制台
  1552. NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key;
  1553. if([BGUtils isBlankString:key])
  1554. {
  1555. _beautyView.hidden = NO;
  1556. }else{
  1557. KPostNotification(@"onMainSwitchButtonClick", nil);
  1558. // [self.tiUIView onMainSwitchButtonClick:nil];
  1559. // _beautyPanel.hidden = NO;
  1560. // [[TiUIManager shareManager]showMainMenuView];
  1561. }
  1562. }
  1563. else if (index == 1)
  1564. { // 麦克风
  1565. if (isSelected == YES)
  1566. {
  1567. _isMuted = NO;
  1568. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"已打开麦克风")];
  1569. }
  1570. else
  1571. {
  1572. _isMuted = YES;
  1573. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"已关闭麦克风")];
  1574. }
  1575. if([GlobalVariables sharedInstance].openAgora)
  1576. {
  1577. // [self.publishController.agoraKit muteLocalAudioStream:!isSelected];
  1578. [self.publishController.trtcCloud muteLocalAudio:!isSelected];
  1579. }
  1580. }
  1581. else if (index == 2)
  1582. {
  1583. // 切换摄像
  1584. [[self.publishController.trtcCloud getDeviceManager] switchCamera:![[self.publishController.trtcCloud getDeviceManager] isFrontCamera]];
  1585. BOOL isFrontCamera = [[self.publishController.trtcCloud getDeviceManager] isFrontCamera];
  1586. toolsView.isRearCamera = !isFrontCamera;
  1587. if (isFrontCamera) {
  1588. toolsView.isClick = NO;
  1589. [toolsView.toolsCollectionView deselectItemAtIndexPath:[NSIndexPath indexPathWithIndex:3] animated:NO];
  1590. }
  1591. }
  1592. else if (index == 3) {
  1593. //判断当前是否为前置摄像头(仅适用于移动端)
  1594. BOOL isFrontCamera = [[self.publishController.trtcCloud getDeviceManager] isFrontCamera];
  1595. if (isFrontCamera){
  1596. [FanweMessage alert:ASLocalizedString(@"前置摄像头下暂时不能打开闪光灯")];
  1597. return;
  1598. }
  1599. [[self.publishController.trtcCloud getDeviceManager] enableCameraTorch:isSelected];
  1600. }
  1601. else if (index == 4)
  1602. {
  1603. if (isSelected == YES)
  1604. {
  1605. [FanweMessage alert:ASLocalizedString(@"已打开镜像")];
  1606. }
  1607. else
  1608. {
  1609. [FanweMessage alert:ASLocalizedString(@"已关闭镜像")];
  1610. }
  1611. // 设置本地画面的预览模式:开启左右镜像,设置画面为填充模式
  1612. TRTCRenderParams *param = [[TRTCRenderParams alloc] init];
  1613. if(isSelected == YES) {
  1614. param.mirrorType = TRTCVideoMirrorTypeEnable;
  1615. } else {
  1616. param.mirrorType = TRTCVideoMirrorTypeDisable;
  1617. }
  1618. [_publishController.trtcCloud setLocalRenderParams:param];
  1619. }
  1620. //音效
  1621. }
  1622. #pragma mark TCShowLiveTopViewToSDKDelegate
  1623. #pragma mark 推拉流请求所的码率
  1624. - (void)refreshKBPS:(TCShowLiveTopView *)topView
  1625. {
  1626. NSDictionary *tmpDict;
  1627. if ([self.liveItem liveType] == 0)
  1628. {
  1629. tmpDict = _publishController.qualityDict;
  1630. }
  1631. else if ([self.liveItem liveType] == 1)
  1632. {
  1633. tmpDict = _playController.qualityDict;
  1634. }
  1635. else if ([self.liveItem liveType] == 2)
  1636. {
  1637. tmpDict = _linkMicPlayController.qualityDict;
  1638. }
  1639. int totalkb = ([tmpDict toInt:NET_STATUS_VIDEO_BITRATE] + [tmpDict toInt:NET_STATUS_AUDIO_BITRATE])/8;
  1640. if (totalkb)
  1641. {
  1642. topView.kbpsSendLabel.hidden = NO;
  1643. topView.kbpsRecvLabel.hidden = YES;
  1644. CGRect newFrame = topView.kbpsSendLabel.frame;
  1645. newFrame.origin.y = CGRectGetHeight(topView.kbpsContainerView.frame)/4;
  1646. topView.kbpsSendLabel.frame = newFrame;
  1647. }
  1648. else
  1649. {
  1650. topView.kbpsSendLabel.hidden = YES;
  1651. topView.kbpsRecvLabel.hidden = YES;
  1652. }
  1653. topView.kbpsSendLabel.text = [NSString stringWithFormat:@"%@%dk",[self.liveItem liveType] == 0 ? @"↑" : @"↓" ,totalkb];
  1654. }
  1655. #pragma mark FWTPublishControllerDelegate
  1656. #pragma mark 腾讯云直播的主播首帧回调
  1657. - (void)firstIFrame:(BGTPublishController*)publishVC
  1658. {
  1659. if (!_hasShowVagueImg)
  1660. {
  1661. [self hideVagueImgView];
  1662. // 设置默认美颜
  1663. [self setCurrentBeautyValue:self.BuguLive.appModel.beauty_ios whiteValue:0];
  1664. SUS_WINDOW.isPushStreamIng = YES;
  1665. }
  1666. }
  1667. #pragma mark 推流时,网络断连,且经多次重连抢救无效后退出app
  1668. - (void)exitPublishAndApp:(BGTPublishController *)publishVC
  1669. {
  1670. [self alertExitLive:NO isHostShowAlert:NO succ:nil failed:nil];
  1671. }
  1672. #pragma mark FWTPlayControllerDelegate
  1673. #pragma mark 腾讯云直播的观众、回播首帧回调
  1674. - (void)firstFrame:(BGTPlayController*)playVC
  1675. {
  1676. [self hideVagueImgView];
  1677. }
  1678. #pragma mark 拉流时,网络断连,重连
  1679. - (void)playAgain:(BGTPlayController *)publishVC isHideLeaveTip:(BOOL)isHideLeaveTip
  1680. {
  1681. if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  1682. {
  1683. [_linkMicPlayController startRtmp:self.liveInfo.create_type];
  1684. }
  1685. if (!_liveServiceController.anchorLeaveTipLabel.isHidden && isHideLeaveTip)
  1686. {
  1687. _liveServiceController.anchorLeaveTipLabel.hidden = YES;
  1688. }
  1689. }
  1690. #pragma mark 拉流时,网络断连,且经多次重连抢救无效后退出app
  1691. - (void)exitPlayAndApp:(BGTPlayController *)publishVC
  1692. {
  1693. [self alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
  1694. }
  1695. #pragma mark livePayDelegate
  1696. #pragma mark 付费直播是否加载直播间视频的代理
  1697. - (void)livePayLoadVedioIsComfirm:(BOOL)isComfirm
  1698. {
  1699. if (isComfirm)
  1700. {
  1701. if (!self.hasEnterChatGroup)
  1702. {
  1703. [self.linkMicPlayController stopRtmp];
  1704. if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
  1705. {
  1706. [self.linkMicPlayController.txLivePlayer setMute:NO];
  1707. }
  1708. [self.liveServiceController.liveUIViewController dealLivepayTComfirm];
  1709. FWWeakify(self)
  1710. [self.liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
  1711. FWStrongify(self)
  1712. self.liveInfo = liveInfo;
  1713. [self beginPlayVideo:liveInfo];
  1714. self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
  1715. [super startEnterChatGroup:_liveInfo.group_id succ:nil failed:nil];
  1716. } roomID:@"" failed:^(int errId, NSString *errMsg){
  1717. }];
  1718. }
  1719. }
  1720. else
  1721. {
  1722. [self alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
  1723. }
  1724. }
  1725. -(void)protocolGetVideoWithRoomID:(NSString *)roomID{
  1726. FWWeakify(self)
  1727. [self.liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
  1728. TCShowUser *user = [[TCShowUser alloc] init];
  1729. user.avatar = liveInfo.podcast.user.head_image;
  1730. user.uid = liveInfo.user_id;
  1731. user.username = liveInfo.podcast.user.nick_name;
  1732. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
  1733. liveRoom.host = user;
  1734. liveRoom.avRoomId = [liveInfo.room_id intValue];
  1735. liveRoom.title = [NSString stringWithFormat:@"%d",liveRoom.avRoomId];
  1736. liveRoom.vagueImgUrl = liveInfo.podcast.user.head_image;
  1737. //SUS_WINDOW 去记录直播间类型 这是不是观众
  1738. liveRoom.liveType = SUS_WINDOW.liveType;
  1739. liveRoom.isHost = NO;
  1740. // TCShowLiveView *liveView = [[TCShowLiveView alloc]initWith:liveRoom liveController:self];
  1741. // _liveServiceController.liveUIViewController.liveView = liveView;
  1742. _liveServiceController.liveUIViewController.liveScrollView.roomID = liveInfo.room_id;
  1743. [_liveServiceController.liveUIViewController.liveView refreshLiveItem:liveRoom liveInfo:liveInfo];
  1744. FWStrongify(self)
  1745. self.liveInfo = liveInfo;
  1746. [self beginPlayVideo:liveInfo];
  1747. self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
  1748. _linkMicPlayController.videoContrainerView.top = 0;
  1749. _liveServiceController.liveUIViewController.liveScrollView.top = 0;
  1750. _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
  1751. _secondImgView.top = _firstImgView.bottom;
  1752. NSLog(@"_liveServiceControlle.scrollview%@",_liveServiceController.liveUIViewController.liveScrollView);
  1753. [FanweMessage alert:ASLocalizedString(@"切换直播间成功!")];
  1754. [super startEnterChatGroup:liveInfo.group_id succ:nil failed:nil];
  1755. } roomID:roomID failed:^(int errId, NSString *errMsg) {
  1756. }];
  1757. }
  1758. #pragma mark 付费直播关闭直播间的声音
  1759. - (void)voiceNotice:(NSNotification*)notification
  1760. {
  1761. NSMutableDictionary *dictM = [notification object];
  1762. if ([dictM toInt:@"type"] == 0)//关闭声音
  1763. {
  1764. [self setSDKMute:YES];
  1765. }
  1766. else if ([dictM toInt:@"type"] == 1)//打开声音
  1767. {
  1768. [self setSDKMute:NO];
  1769. }
  1770. }
  1771. #pragma mark ------------------------ 实现FWLiveControllerAble协议 -----------------------
  1772. #pragma mark 开始推流、拉流
  1773. - (void)startLiveRtmp:(NSString *)playUrlStr
  1774. {
  1775. if (![BGUtils isBlankString:playUrlStr])
  1776. {
  1777. if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
  1778. {
  1779. _publishController.pushUrlStr = playUrlStr;
  1780. if (![GlobalVariables sharedInstance].isOtherPush) {
  1781. [_publishController startPushRtmpLiveMethod];
  1782. }
  1783. }
  1784. else if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
  1785. {
  1786. _linkMicPlayController.playUrlStr = playUrlStr;
  1787. [_linkMicPlayController startRtmp:self.liveInfo.create_type];
  1788. }
  1789. }
  1790. }
  1791. #pragma mark 结束推流、拉流
  1792. - (void)stopLiveRtmp
  1793. {
  1794. if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
  1795. {
  1796. [_publishController stopRtmp];
  1797. }
  1798. else if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
  1799. {
  1800. [_linkMicPlayController stopRtmp];
  1801. }
  1802. }
  1803. //#pragma mark 按时付费剩余时间的倒计时
  1804. //- (void)livePayLeftTimeGo
  1805. //{
  1806. // _liveServiceController.liveUIViewController.livePayLeftCount --;
  1807. // if (_liveServiceController.liveUIViewController.livePayLeftCount == 0)
  1808. // {
  1809. // [_liveServiceController.liveUIViewController.livePayLeftTimer invalidate];
  1810. // _liveServiceController.liveUIViewController.livePayLeftTimer =nil;
  1811. // }else
  1812. // {
  1813. // _liveServiceController.liveUIViewController.livePayLabel.text = [NSString stringWithFormat:ASLocalizedString(@"亲,大约%d秒后进入直播间"),_liveServiceController.liveUIViewController.livePayLeftCount];
  1814. // }
  1815. //}
  1816. #pragma mark TCShowLiveViewToSDKDelegate
  1817. - (void)hideReLiveSlide:(BOOL)isHided
  1818. {
  1819. if (isHided)
  1820. {
  1821. _reLiveProgressView.hidden = YES;
  1822. }
  1823. else
  1824. {
  1825. if (self.hasVideoControl)
  1826. {
  1827. _reLiveProgressView.hidden = NO;
  1828. }
  1829. }
  1830. }
  1831. #pragma mark - ----------------------- 美颜 -----------------------
  1832. #pragma mark 设置美颜类型(FWTLiveBeautyViewDelegate)
  1833. - (void)setBeauty:(BGTLiveBeautyView *)beautyView withBeautyName:(NSString *)beautyName
  1834. {
  1835. if (_publishController.txLivePublisher)
  1836. {
  1837. if (![BGUtils isBlankString:beautyName])
  1838. {
  1839. NSString * path = [[NSBundle mainBundle] pathForResource:@"FilterResource" ofType:@"bundle"];
  1840. if(path && ![beautyName isEqualToString:ASLocalizedString(@"普通美颜")])
  1841. {
  1842. path = [path stringByAppendingPathComponent:beautyName];
  1843. UIImage *image = [UIImage imageWithContentsOfFile:path];
  1844. [_publishController.txLivePublisher setFilter:image];
  1845. }
  1846. else if ([beautyName isEqualToString:ASLocalizedString(@"普通美颜")])
  1847. {
  1848. [_publishController.txLivePublisher setFilter:nil];
  1849. }
  1850. }
  1851. else
  1852. {
  1853. [_publishController.txLivePublisher setFilter:nil];
  1854. [self setCurrentBeautyValue:0 whiteValue:0];
  1855. }
  1856. }
  1857. }
  1858. #pragma mark - 设置美颜的值
  1859. - (void)setBeautyValue:(BGTLiveBeautyView *)beautyView {
  1860. // if (_publishController.txLivePublisher) {
  1861. // [_publishController.txLivePublisher setBeautyStyle:0 beautyLevel:beautyView.filterParam1.slider.value/10 whitenessLevel:beautyView.filterParam2.slider.value/10 ruddinessLevel:0];
  1862. // }
  1863. // AgoraBeautyOptions *option = [[AgoraBeautyOptions alloc] init];
  1864. // option.lighteningLevel = beautyView.filterParam2.slider.value/100;
  1865. // option.smoothnessLevel = beautyView.filterParam1.slider.value/100;
  1866. // option.rednessLevel = beautyView.filterParam3.slider.value/100;
  1867. //功能描述:设置美颜级别
  1868. TXBeautyManager *bm = [self.publishController.trtcCloud getBeautyManager];
  1869. [bm setBeautyLevel:beautyView.filterParam1.slider.value/10];
  1870. // 功能描述:设置美颜(磨皮)算法
  1871. [bm setBeautyStyle:TXBeautyStyleNature];
  1872. //美白
  1873. [bm setWhitenessLevel:beautyView.filterParam2.slider.value/10];
  1874. //功能描述:设置红润级别
  1875. [bm setRuddyLevel:beautyView.filterParam3.slider.value/10];
  1876. NSLog(@"红润 = %f",beautyView.filterParam3.slider.value/10);
  1877. NSLog(@"美颜 = %f",beautyView.filterParam1.slider.value/10);
  1878. // [_publishController.agoraKit setBeautyEffectOptions:YES options:option];
  1879. }
  1880. - (void)setCurrentBeautyValue:(float)beautyDepth whiteValue:(float)whiteDepth
  1881. {
  1882. _beautyView.filterParam1.slider.value = beautyDepth;
  1883. _beautyView.filterParam2.slider.value = whiteDepth;
  1884. [_beautyView.filterParam1 updateValue];
  1885. [_beautyView.filterParam2 updateValue];
  1886. [self setBeautyValue:_beautyView];
  1887. }
  1888. #pragma mark - ----------------------- 其他 -----------------------
  1889. #pragma mark 获取当前直播质量
  1890. - (NSString *)getLiveQuality
  1891. {
  1892. NSDictionary *tmpDict;
  1893. if ([self.liveItem liveType] == 0)
  1894. {
  1895. tmpDict = _publishController.qualityDict;
  1896. }
  1897. else
  1898. {
  1899. tmpDict = _playController.qualityDict;
  1900. }
  1901. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1902. // 设备类型
  1903. [mDict setObject:@"Ios" forKey:@"device"];
  1904. // app占用CPU
  1905. if ([tmpDict toFloat:NET_STATUS_CPU_USAGE_D])
  1906. {
  1907. [mDict setObject:[NSString stringWithFormat:@"%f",[tmpDict toFloat:NET_STATUS_CPU_USAGE_D]*100] forKey:@"appCPURate"];
  1908. }
  1909. // 系统占用CPU
  1910. if ([tmpDict toFloat:NET_STATUS_CPU_USAGE])
  1911. {
  1912. [mDict setObject:[NSString stringWithFormat:@"%f",[tmpDict toFloat:NET_STATUS_CPU_USAGE]*100] forKey:@"sysCPURate"];
  1913. }
  1914. // 画面帧率,如:25
  1915. if ([tmpDict toString:NET_STATUS_VIDEO_FPS])
  1916. {
  1917. [mDict setObject:[tmpDict toString:NET_STATUS_VIDEO_FPS] forKey:@"fps"];
  1918. }
  1919. // 发送、接收码率(每秒钟发送、接收的数据量)
  1920. int totalkbps = [tmpDict toInt:NET_STATUS_VIDEO_BITRATE] + [tmpDict toInt:NET_STATUS_AUDIO_BITRATE];
  1921. int totalkb = totalkbps/8;
  1922. if (totalkb)
  1923. {
  1924. if ([self.liveItem liveType] == 0)
  1925. {
  1926. [mDict setObject:StringFromInt(totalkb) forKey:@"sendKBps"];
  1927. }
  1928. else
  1929. {
  1930. [mDict setObject:StringFromInt(totalkb) forKey:@"recvKBps"];
  1931. }
  1932. }
  1933. // 显示网络差的提示
  1934. int netSpeed = [tmpDict toInt:NET_STATUS_NET_SPEED];
  1935. if(netSpeed == 0) {netSpeed = 1;}
  1936. float loss_rate_send = (netSpeed-totalkbps)/netSpeed;
  1937. if ([self.liveItem liveType] == 0)
  1938. {
  1939. [mDict setObject:[NSString stringWithFormat:@"%f",loss_rate_send] forKey:@"sendLossRate"];
  1940. }
  1941. else
  1942. {
  1943. [mDict setObject:[NSString stringWithFormat:@"%f",loss_rate_send] forKey:@"recvLossRate"];
  1944. }
  1945. if (loss_rate_send <= 0.2)
  1946. {
  1947. _lossRateSendTipLabel.hidden = YES;
  1948. }
  1949. else if(loss_rate_send > 0.2 && loss_rate_send < 0.3)
  1950. {
  1951. _lossRateSendTipLabel.hidden = NO;
  1952. _lossRateSendTipLabel.text = kHostNetLowTip1;
  1953. _lossRateSendTipLabel.textColor = kYellowColor;
  1954. }
  1955. else
  1956. {
  1957. _lossRateSendTipLabel.hidden = NO;
  1958. _lossRateSendTipLabel.text = kHostNetLowTip2;
  1959. _lossRateSendTipLabel.textColor = kRedColor;
  1960. }
  1961. NSString *sendMessage = [BGUtils dataTOjsonString:mDict];
  1962. if (sendMessage)
  1963. {
  1964. return sendMessage;
  1965. }
  1966. else
  1967. {
  1968. return @"";
  1969. }
  1970. }
  1971. #pragma mark 获取当前视频容器视图的父视图
  1972. - (UIView *)getPlayViewBottomView
  1973. {
  1974. if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
  1975. {
  1976. return _publishController.view;
  1977. }
  1978. else if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
  1979. {
  1980. return _linkMicPlayController.view;
  1981. }
  1982. return nil;
  1983. }
  1984. #pragma mark 设置静音 YES:设置为静音
  1985. - (void)setSDKMute:(BOOL)bEnable
  1986. {
  1987. if (bEnable) // 关闭声音
  1988. {
  1989. if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
  1990. {
  1991. [self.linkMicPlayController.txLivePlayer setMute:YES];
  1992. }
  1993. }
  1994. else // 打开声音
  1995. {
  1996. if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
  1997. {
  1998. [self.linkMicPlayController.txLivePlayer setMute:NO];
  1999. }
  2000. }
  2001. }
  2002. #pragma mark - ----------------------- 其他 -----------------------
  2003. #pragma mark 解决不能调为最小音量问题
  2004. - (void)volumeChanged:(NSNotification *)noti
  2005. {
  2006. NSDictionary *tmpDict = noti.userInfo;
  2007. if (tmpDict && [tmpDict isKindOfClass:[NSDictionary class]])
  2008. {
  2009. if ([[tmpDict toString:@"AVSystemController_AudioVolumeChangeReasonNotificationParameter"] isEqualToString:@"ExplicitVolumeChange"] && !_isMuted)
  2010. {
  2011. float volume = [[tmpDict objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
  2012. if (volume <= 0.062500)
  2013. {
  2014. [_publishController.txLivePublisher setMute:YES];
  2015. }
  2016. else
  2017. {
  2018. [_publishController.txLivePublisher setMute:NO];
  2019. }
  2020. }
  2021. }
  2022. }
  2023. - (BGOtherPushPopView *)otherPushPopView{
  2024. if (!_otherPushPopView) {
  2025. _otherPushPopView = [[NSBundle mainBundle] loadNibNamed:@"BGOtherPushPopView" owner:nil options:nil].lastObject;
  2026. }
  2027. return _otherPushPopView;
  2028. }
  2029. #pragma mark - 断开连麦
  2030. -(void)clickCloseBtn:(UserView *)view
  2031. {
  2032. UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:ASLocalizedString(@"是否断开与%@连麦"),view.userName.text] message:nil preferredStyle:UIAlertControllerStyleAlert];
  2033. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2034. NSLog(@"确定按键被点击");
  2035. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  2036. [mDict setObject:@"video" forKey:@"ctl"];
  2037. [mDict setObject:@"stop_lianmai" forKey:@"act"];
  2038. [mDict setObject:self.roomIDStr forKey:@"room_id"];
  2039. [mDict setObject:view.uid forKey:@"to_user_id"];
  2040. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  2041. } FailureBlock:^(NSError *error) {
  2042. }];
  2043. SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
  2044. sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
  2045. sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
  2046. [self.iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
  2047. }];
  2048. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  2049. NSLog(@"取消按键被点击");
  2050. }];
  2051. [alert addAction:sureAction];
  2052. [alert addAction:cancelAction];
  2053. [self presentViewController:alert animated:YES completion:^{
  2054. }];
  2055. }
  2056. - (void)dealloc
  2057. {
  2058. [[NSNotificationCenter defaultCenter]removeObserver:self];
  2059. }
  2060. @end