BGVoiceController.m 99 KB

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