| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492 |
- //
- // BGTLiveController.m
- // BuguLive
- //
- // Created by xfg on 16/12/5.
- // Copyright © 2016年 xfg. All rights reserved.
- // 腾讯云直播,只处理与SDK有关的业务
- #import "BGTLiveController.h"
- #import "BGMD5UTils.h"
- #import "TLiveMickListModel.h"
- #import "YunMusicPlayVC.h"
- #import "HostCheckMickAlertView.h"
- #import "TCShowLiveView.h"
- #define kPlayContrainerHeight 30
- /////////////////// TiFaceSDK 添加 开始 ///////////////////
- #import "TiSDKInterface.h"
- //#import "TiUIView.h"
- #import "BeautySettingPanel.h"
- /////////////////// TiFaceSDK 添加 结束 ///////////////////
- #import "BGOtherPushPopView.h"
- #import "VoiceLianmaiUserModel.h"
- @interface BGTLiveController ()<BeautySettingPanelDelegate,BeautyLoadPituDelegate>
- {
- BeautySettingPanel *_beautyPanel; // 美颜控件
- }
- ///////////// TiSDK 添加 开始 /////////////
- @property(nonatomic, strong) TiSDKManager *tiSDKManager;
- //@property(nonatomic, strong) TiUIView *tiUIView;
- ///////////// TiSDK 添加 结束 /////////////
- @property (nonatomic, strong) UIView *liveView;
- @property(nonatomic, strong) BGOtherPushPopView *otherPushPopView;
- @end
- @implementation BGTLiveController
- #pragma mark - ----------------------- 添加UI -----------------------
- - (void)addSubViews
- {
- if (self.liveType == FW_LIVE_TYPE_HOST)
- {
- _beautyView = [[BGTLiveBeautyView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
- [self.liveServiceController.liveUIViewController.liveView addSubview:_beautyView];
-
- _beautyView.delegate = self;
- _beautyView.hidden = YES;
- }
-
- if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- self.backVerticalBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 15, 35, 35)];
- [self.backVerticalBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back_2"] forState:UIControlStateNormal];
- [self.backVerticalBtn addTarget:self action:@selector(goVerticalScreen) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:self.backVerticalBtn];
- self.backVerticalBtn.hidden = YES;
- }
- }
- #pragma mark 添加视频
- - (void)initLive
- {
- // 付费直播控制云直播声音
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(voiceNotice:) name:@"closeAndOpenVoice" object:nil];
-
- // 音量监听
- [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
-
- // 屏幕旋转监听
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
-
- if (self.liveType == FW_LIVE_TYPE_HOST)
- {
- _publishController = [[BGTLinkMicPublishController alloc] init];
- // _publishController.liveView = self.liveServiceController.liveUIViewController.liveView;
- _publishController.delegate = self;
- _publishController.linkMicPublishDelegate = self;
- _publishController.roomIDStr = _roomIDStr;
- [self addChild:_publishController inRect:self.view.bounds];
- [self.view sendSubviewToBack:_publishController.view];
- [_publishController.txLivePublisher setMirror:NO];
- }
-
- else if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- _linkMicPlayController = [[BGTLinkMicPlayController alloc] init];
- _linkMicPlayController.playLiveType = [self.liveItem liveType];
- _linkMicPlayController.delegate = self;
- _linkMicPlayController.linkMicPlayDelegate = self;
-
- [self addChild:_linkMicPlayController inRect:self.view.bounds];
- [self.view sendSubviewToBack:_linkMicPlayController.view];
-
- // _linkSecondMicPlayController = [[BGTLinkMicPlayController alloc] init];
- // _linkSecondMicPlayController.liveType = [self.liveItem liveType];
- // _linkSecondMicPlayController.delegate = self;
- // _linkSecondMicPlayController.linkMicPlayDelegate = self;
- // [self addChild:_linkSecondMicPlayController inRect:self.view.bounds];
- // [self.view sendSubviewToBack:_linkSecondMicPlayController.view];
-
- _firstImgView = [UIImageView new];
- _firstImgView.frame = self.view.bounds;
- _firstImgView.top = kScreenH;
- _firstImgView.userInteractionEnabled = YES;
- [self.view addSubview:_firstImgView];
-
- _secondImgView = [UIImageView new];
- _secondImgView.frame = self.view.bounds;
- _secondImgView.top = kScreenH * 2;
- _secondImgView.userInteractionEnabled = YES;
- [self.view addSubview:_secondImgView];
- }
- }
- -(void)protocolDidScrollView:(BGTLiveScrollView *)scrollView isRefreshLive:(BOOL)isRefresh{
-
- NSInteger currentIndex = 1;
-
-
- for (int i = 0; i < self.modelArr.count; i++) {
- LivingModel *model = self.modelArr[i];
- NSString *roomID = [NSString stringWithFormat:@"%d",model.room_id];
- if ([roomID isEqualToString:scrollView.roomID]) {
- currentIndex = i;
- }
- }
-
- scrollView.nowIndex = currentIndex;
-
- if ((self.now_LiveIndex == 0 && scrollView.isFromeTop)|| (self.now_LiveIndex == self.modelArr.count - 1 && !scrollView.isFromeTop)){
- _linkMicPlayController.videoContrainerView.top = 0;
- _liveServiceController.liveUIViewController.liveScrollView.top = 0;
- _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
- _secondImgView.top = _firstImgView.bottom;
-
- return;
- }
-
-
- LivingModel *first_Model;
- LivingModel *second_Model;
-
- //只有一个直播间时 不滑动
- if (self.modelArr.count < 2) {
- _liveServiceController.liveUIViewController.liveScrollView.top = 0;
- return;
- }
-
- NSLog(@"BGTLiveScrollView%@",scrollView);
-
- if (self.modelArr.count == 2) { //只有两个直播时
- if (currentIndex == 1) {//进入的是第二个直播间时
- first_Model = self.modelArr[1];
- second_Model = self.modelArr[0];
- }else{//进入的是第一个直播间时
- first_Model = self.modelArr[0];
- second_Model = self.modelArr[1];
- }
- }else{
- if (currentIndex == self.modelArr.count - 1) {
- first_Model = self.modelArr[self.modelArr.count - 2];
- second_Model = self.modelArr[self.modelArr.count - 1];
- }
- if (currentIndex == 0) {//进入第一个直播间
- first_Model = self.modelArr[1];
- second_Model = self.modelArr[2];
- }else if (currentIndex == self.modelArr.count - 1) {
- first_Model = self.modelArr[self.modelArr.count - 2];
- second_Model = self.modelArr[self.modelArr.count - 1];
- }else{//进入中间的直播间
- first_Model = self.modelArr[currentIndex + 1];
- second_Model = self.modelArr[currentIndex - 1];
- }
- }
-
-
- LivingModel *model = [LivingModel new];
-
-
-
-
-
- _linkMicPlayController.videoContrainerView.top = scrollView.y;
-
- _firstImgView.bottom = _linkMicPlayController.videoContrainerView.top;
- _secondImgView.top = _linkMicPlayController.videoContrainerView.bottom;
- //5-7 回播点击问题
- [_firstImgView sd_setImageWithURL:[NSURL URLWithString:first_Model.live_image]placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
- [_secondImgView sd_setImageWithURL:[NSURL URLWithString:second_Model.live_image]placeholderImage:[UIImage imageNamed:@"DefaultImg"]];
-
- if (!isRefresh) return;
-
- if (scrollView.isFromeTop) {
- model = second_Model;
- }else{
- model = first_Model;
- }
-
- if (model.live_in != FW_LIVE_STATE_ING) {
- // [FanweMessage alert:ASLocalizedString(@"主播不在直播")];
- return;
- }
-
- NSLog(@"%d",model.room_id);
- NSLog(@"%d",model.room_id);
-
- if (scrollView.y == kScreenH || scrollView.y == 0) {
-
- // if (scrollView.y == 0) {
- // model = first_Model;
- // }else if (scrollView.y == kScreenH){
- // model = second_Model;
- // }
-
- self.nowModel = model;
- for (int i = 0; i < self.modelArr.count; i++) {
- LivingModel *model = self.modelArr[i];
- if (model.room_id == self.nowModel.room_id) {
- self.now_LiveIndex = i;
- }
- }
-
- FWWeakify(self)
- NSString *roomID = [NSString stringWithFormat:@"%d",model.room_id];
- [_liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
-
- TCShowUser *user = [[TCShowUser alloc] init];
- user.avatar = liveInfo.podcast.user.head_image;
- user.uid = liveInfo.user_id;
- user.username = liveInfo.podcast.user.nick_name;
-
- TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
- liveRoom.host = user;
- liveRoom.avRoomId = [liveInfo.room_id intValue];
- liveRoom.title = [NSString stringWithFormat:@"%d",liveRoom.avRoomId];
- liveRoom.vagueImgUrl = liveInfo.podcast.user.head_image;
- //SUS_WINDOW 去记录直播间类型 这是不是观众
- liveRoom.liveType = SUS_WINDOW.liveType;
- liveRoom.isHost = NO;
-
-
- // TCShowLiveView *liveView = [[TCShowLiveView alloc]initWith:liveRoom liveController:self];
- // _liveServiceController.liveUIViewController.liveView = liveView;
- _liveServiceController.liveUIViewController.liveScrollView.roomID = liveInfo.room_id;
- [_liveServiceController.liveUIViewController.liveView refreshLiveItem:liveRoom liveInfo:liveInfo];
- [_liveServiceController.liveUIViewController.liveView.msgView.liveMessages removeAllObjects];
-
-
-
- FWStrongify(self)
- self.liveInfo = liveInfo;
- [self beginPlayVideo:liveInfo];
- self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
- _linkMicPlayController.videoContrainerView.top = 0;
- _liveServiceController.liveUIViewController.liveScrollView.top = 0;
- _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
- _secondImgView.top = _firstImgView.bottom;
-
- NSLog(@"_liveServiceControlle.scrollview%@",_liveServiceController.liveUIViewController.liveScrollView);
-
- [super startEnterChatGroup:liveInfo.group_id succ:nil failed:nil];
-
- } roomID:roomID failed:^(int errId, NSString *errMsg) {
-
- }];
- }
- }
- -(void)clickRightContrainerView:(NSString *)roomID{
-
- FWWeakify(self)
- [_liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
-
- TCShowUser *user = [[TCShowUser alloc] init];
- user.avatar = liveInfo.podcast.user.head_image;
- user.uid = liveInfo.user_id;
- user.username = liveInfo.podcast.user.nick_name;
-
- TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
- liveRoom.host = user;
- liveRoom.avRoomId = [liveInfo.room_id intValue];
- liveRoom.title = [NSString stringWithFormat:@"%d",liveRoom.avRoomId];
- liveRoom.vagueImgUrl = liveInfo.podcast.user.head_image;
- //SUS_WINDOW 去记录直播间类型 这是不是观众
- liveRoom.liveType = SUS_WINDOW.liveType;
- liveRoom.isHost = NO;
-
-
- // TCShowLiveView *liveView = [[TCShowLiveView alloc]initWith:liveRoom liveController:self];
- // _liveServiceController.liveUIViewController.liveView = liveView;
- _liveServiceController.liveUIViewController.liveScrollView.roomID = liveInfo.room_id;
- [_liveServiceController.liveUIViewController.liveView refreshLiveItem:liveRoom liveInfo:liveInfo];
-
- FWStrongify(self)
- self.liveInfo = liveInfo;
- [self beginPlayVideo:liveInfo];
- self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
-
- _linkMicPlayController.videoContrainerView.top = 0;
- _liveServiceController.liveUIViewController.liveScrollView.top = 0;
- _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
- _secondImgView.top = _firstImgView.bottom;
-
- NSLog(@"_liveServiceControlle.scrollview%@",_liveServiceController.liveUIViewController.liveScrollView);
-
- [super startEnterChatGroup:liveInfo.group_id succ:nil failed:nil];
-
- } roomID:roomID failed:^(int errId, NSString *errMsg) {
-
- }];
- }
- #pragma mark 添加直播间逻辑、视图
- - (void)addServiceController {
-
- if (_liveServiceController) {
- return;
- }
-
- _liveServiceController = [[BGLiveServiceController alloc]initWith:self.liveItem liveController:self];
- _liveServiceController.delegate = self;
- [_liveServiceController.liveUIViewController.liveView.voicebottomView removeFromSuperview];
- _liveServiceController.liveUIViewController.liveView.voicebottomView = nil;
- _liveServiceController.pluginCenterView.toolsView.toSDKdelegate = self;
- _liveServiceController.liveUIViewController.liveView.sdkDelegate = self;
- _liveServiceController.liveUIViewController.liveView.topView.toSDKDelegate = self;
- [self addChild:_liveServiceController inRect:self.view.bounds];
-
- __weak __typeof(self)weakSelf = self;
-
- //音效
- self.liveServiceController.liveUIViewController.playUrlBlock = ^(BGSoundEffectModel *model) {
-
- int EFFECT_ID = model.id.intValue;
-
- TXAudioMusicParam *bgmParam = [[TXAudioMusicParam alloc] init];
- bgmParam.ID = EFFECT_ID;
- bgmParam.path = model.url;
- bgmParam.publish = true;
- bgmParam.loopCount = 0;
-
- [[weakSelf.publishController.trtcCloud getAudioEffectManager] startPlayMusic:bgmParam onStart:^(NSInteger errCode) {
-
- } onProgress:^(NSInteger progressMs, NSInteger durationMs) {
-
- } onComplete:^(NSInteger errCode) {
-
- }];
-
-
- NSLog(@"播放音效 %@",model);
- };
-
-
- }
- #pragma mark - ----------------------- 重写父方法 -----------------------
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- }
- - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem modelArr:(NSArray *)modelArr
- {
- if (self = [super initWith:liveItem modelArr:modelArr])
- {
- self.modelArr = [NSMutableArray arrayWithArray:modelArr];
- for (int i = 0; i < modelArr.count; i++) {
- LivingModel *model = modelArr[i];
- if (model.room_id == liveItem.liveAVRoomId) {
- self.nowModel = model;
- self.now_LiveIndex = i;
- }
- }
-
- [self addServiceController];
- [self addSubViews];
- }
- return self;
- }
- - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
- {
- [super refreshLiveItem:liveItem liveInfo:liveInfo];
- //声网dev
- _linkMicPlayController.liveInfo = liveInfo;
-
- [_liveServiceController refreshLiveItem:liveItem liveInfo:liveInfo];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // [GlobalVariables sharedInstance].tliveView = self.view;
- ///////////// TiSDK 添加 开始 ////////////
-
-
-
- ///////////// TiSDK 添加 结束 /////////////
-
- if (self.BuguLive.appModel.mic_max_num >= 3 || self.BuguLive.appModel.mic_max_num == 0)
- {
- _micMaxNum = 3;
- }
- else
- {
- _micMaxNum = self.BuguLive.appModel.mic_max_num;
- }
-
- //初始化直播
- [self initLive];
-
- //#error TiSDK Key, 与包名对应,请联系商务获取
- NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key;
- if([BGUtils isBlankString:key])
- {
- //这里写上那个key
- key = @"517a990947274dd8b51e1525feb0fb79";
- // [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"美颜key为空,请尝试重新打开app获取!")];
- }
- else
- {
- // [TiSDK init:key];
- //
- // //在这里创建好像会被覆盖掉 你看看这里
- //
- // // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // if([[GlobalVariables sharedInstance].appModel.spear_live isEqualToString:@"1"])
- // {
- // ///////////// TiSDK 添加 开始 ////////////
- //
- // // [[TiUIManager shareManager] loadToSuperview:self.view];
- // [TiUIManager shareManager].showsDefaultUI = NO;
- // [[TiUIManager shareManager]loadToWindowDelegate:nil];
- //
- //
- //// self.tiSDKManager = [[TiSDKManager alloc]init];
- ////// self.tiUIView = [[TiUIView alloc]initTiUIViewWith:self.tiSDKManager delegate:self superView:self.liveServiceController.liveUIViewController.view];
- ////// self.tiUIView.isClearOldUI = NO;
- ////// [self.tiUIView createTiUIView];
- // // 美颜控件
- // NSUInteger controlHeight = [BeautySettingPanel getHeight];
- // _beautyPanel = [[BeautySettingPanel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - controlHeight - MG_BOTTOM_MARGIN, self.view.frame.size.width, controlHeight + MG_BOTTOM_MARGIN)];
- // _beautyPanel.hidden = YES;
- // _beautyPanel.delegate = self;
- // _beautyPanel.pituDelegate = self;
- // [self.liveServiceController.liveUIViewController.view addSubview:_beautyPanel];
- // [_beautyPanel resetValues]; // 美颜设置初始值
- // }
- }
- }
- #pragma mark ---------美颜增加-------------
- - (GLuint)onPreProcessTexture:(GLuint)texture width:(CGFloat)width height:(CGFloat)height{
- if (self.tiSDKManager && [self.tiSDKManager renderTexture2D:texture Width:width Height:height Rotation:CLOCKWISE_0 Mirror:NO]) {
- /////////////////// TiFaceSDK 添加 开始 ///////////////////
- return [self.tiSDKManager renderTexture2D:texture Width:width Height:height Rotation:CLOCKWISE_0 Mirror:NO];
- /////////////////// TiFaceSDK 添加 结束 ///////////////////
- }
- return texture;
- }
- #pragma mark 腾讯云直播开始进入直播间:根据是否传入了聊天组ID选择对应的进入直播间的方案
- - (void)startEnterChatGroup:(NSString *)chatGroupID succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed
- {
- __weak typeof(self) ws = self;
-
- [_liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
-
- if (liveInfo)
- {
- ws.liveInfo = liveInfo;
- ws.hasVideoControl = liveInfo.has_video_control ? YES : NO;
- _reLiveProgressView.hidden = YES;
-
- ws.liveServiceController.liveUIViewController.livePay.payDelegate = self;
-
- if (![BGUtils isBlankString:liveInfo.push_rtmp] || ![BGUtils isBlankString:liveInfo.play_url])
- {
- [ws beginPlayVideo:liveInfo];
- }
-
- if (liveInfo.is_live_pay == 1 && liveInfo.is_pay_over == 0 && ![liveInfo.podcast.user.user_id isEqualToString:[[IMAPlatform sharedInstance].host imUserId]])
- {
- if (succ)
- {
- succ();
- }
- }
- else
- {
- [super startEnterChatGroup:liveInfo.group_id succ:^{
-
- [ws getVideoState:1];
-
- if (succ)
- {
- succ();
- }
-
- } failed:^(int errId, NSString *errMsg) {
-
- [ws getVideoState:0];
-
- if (failed)
- {
- failed(errId, errMsg);
- }
- }];
- }
- }
- else
- {
- [ws setGetVideoFailed:nil];
-
- if (failed)
- {
- failed(FWCode_Net_Error, ASLocalizedString(@"获取到的liveInfo为空"));
- }
- }
- }roomID:@"" failed:^(int errId, NSString *errMsg) {
-
- [ws setGetVideoFailed:errMsg];
-
- if (failed)
- {
- failed(errId, errMsg);
- }
-
- DebugLog(@"=========加载get_video接口出错 code: %d , msg = %@", errId, errMsg);
-
- }];
- }
- #pragma mark 加入聊天组成功
- - (void)enterChatGroupSucc:(CurrentLiveInfo *)liveInfo
- {
- [super enterChatGroupSucc:liveInfo];
-
- if (!_isHost && (_liveInfo.join_room_prompt == 1 || [[IMAPlatform sharedInstance].host getUserRank] >= self.BuguLive.appModel.jr_user_level))
- {
- _liveServiceController.liveUIViewController.liveView.canShowLightMessage = YES;
- }
- }
- #pragma mark 重写父方法: 业务上退出直播:退出的时候分SDK退出和业务退出,减少退出等待时间
- - (void)onServiceExitLive:(BOOL)isDirectCloseLive succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed
- {
- [_liveServiceController endLive];
-
- if (self.liveType == FW_LIVE_TYPE_HOST) // 主播
- {
- [_publishController endLive];
- [_liveServiceController showHostFinishView:@"" andVote:@"" andHasDel:NO];
-
- __weak typeof(self) ws = self;
- [[BGHUDHelper sharedInstance] syncLoading];
- [_liveServiceController hostExitLive:^{
-
- ws.publishController.leaveRoomBlockSuccess = ^{
- [[BGHUDHelper sharedInstance] syncStopLoading];
- if(isDirectCloseLive)
- {
- [ws onExitLiveUI];
- }
- if (succ)
- {
- succ();
- }
- };
- [ws.publishController.trtcCloud stopLocalPreview];
- [ws.publishController.trtcCloud stopLocalAudio];
- [ws.publishController.trtcCloud exitRoom];
- [TRTCCloud destroySharedInstance];
-
- } failed:^(int errId, NSString *errMsg) {
-
- [[BGHUDHelper sharedInstance] syncLoading];
-
- ws.publishController.leaveRoomBlockSuccess = ^{
- [[BGHUDHelper sharedInstance] syncStopLoading];
- if(isDirectCloseLive)
- {
- [ws onExitLiveUI];
- }
- failed(errId, errMsg);
- };
-
- [ws.publishController.trtcCloud stopLocalPreview];
- [ws.publishController.trtcCloud stopLocalAudio];
- [ws.publishController.trtcCloud exitRoom];
- [TRTCCloud destroySharedInstance];
-
- }];
-
- [_publishController stopRtmp];
- return;
- }
-
-
- if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController endVideo];
- [self cancelMickingAlert];
-
- if ([_linkMicPlayController.linkMemeberSet containsObject:[[IMAPlatform sharedInstance].host imUserId]])
- {
- [BGLiveSDKViewModel tLiveStopMick:_roomIDStr toUserId:@""];
- }
- }
-
- if(isDirectCloseLive)
- {
- [self onExitLiveUI];
- }
-
- if (succ)
- {
- succ();
- }
-
- }
- #pragma mark 是否需要打断视频
- - (void)interruptionLiveIng:(BOOL)interruptioning
- {
- if (interruptioning)
- {
- [_liveServiceController pauseLive];
-
- if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
- {
- [_publishController.txLivePublisher pausePush];
- }
-
- else if([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController onAppDidEnterBackGround];
- }
- }
- else
- {
- [_liveServiceController resumeLive];
-
- if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST) // 直播的主播
- {
- [_publishController.txLivePublisher resumePush];
- }
- else if([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController onAppWillEnterForeground];
- }
- }
- }
- #pragma mark 是否正在被电话打断
- - (void)phoneInterruptioning:(BOOL)interruptioning
- {
- [super phoneInterruptioning:interruptioning];
-
- [self interruptionLiveIng:interruptioning];
- }
- #pragma mark app进入前台
- - (void)onAppEnterForeground
- {
- [super onAppEnterForeground];
-
- if (_isHost)
- {
- [super onAppEnterForeground];
- [_publishController.txLivePublisher resumePush];
- }
- else
- {
- if (_isMickAudiencePushing)
- {
- _isMickAudiencePushing = NO;
- [_linkMicPlayController.txLivePush resumePush];
- }
- }
- }
- #pragma mark app进入后台
- - (void)onAppEnterBackground
- {
- [super onAppEnterBackground];
-
- if (_isHost)
- {
- [super onAppEnterBackground];
- [_publishController.txLivePublisher pausePush];
- }
- else
- {
- if (_linkMicPlayController.txLivePush.isPublishing)
- {
- _isMickAudiencePushing = YES;
- [_linkMicPlayController.txLivePush pausePush];
- }
- }
-
- if (_toolsView)
- {
- // 关闭LED
- [BGUtils turnOnFlash:NO];
-
- ToolsCollectionViewCell *cell = (ToolsCollectionViewCell *)[_toolsView.toolsCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:0]];
- if (cell)
- {
- cell.toolImgView.image = [UIImage imageNamed:@"lr_plugin_flash_unsel"];
- }
- }
- }
- #pragma mark 重写退出方法
- - (void)onExitLiveUI
- {
- [super onExitLiveUI];
-
- // 执行下 悬浮参数退出
- if (SUS_WINDOW.isSusWindow &&SUS_WINDOW.isDirectCloseLive == YES)
- {
- [[LiveCenterManager sharedInstance]resetSuswindowPramaComple:^(BOOL finished) {
-
- }];
- }
-
- [_liveServiceController endLive];
- [_liveServiceController.view removeFromSuperview];
- // _liveServiceController = nil;
- if (_publishController)
- {
- _publishController = nil;
- }
- if (_playController)
- {
- _playController = nil;
- }
- if (_linkMicPlayController)
- {
- _linkMicPlayController = nil;
- }
-
- if (!SUS_WINDOW.isSusWindow)
- {
- self.navigationController.navigationBarHidden = NO;
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- #pragma mark 重写声音打断监听
- - (void)onAudioInterruption:(NSNotification *)notification
- {
- [super onAudioInterruption:notification];
-
- if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController onAudioInterruption:notification];
- }
- }
- #pragma mark 监听耳机插入和拔出
- - (void)audioRouteChangeListenerCallback:(NSNotification *)notification
- {
- [super audioRouteChangeListenerCallback:notification];
-
- NSDictionary *interuptionDict = notification.userInfo;
- NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
- switch (routeChangeReason)
- {
- case AVAudioSessionRouteChangeReasonNewDeviceAvailable: // 耳机插入
-
- // 开启耳返功能
- _publishController.txLivePushonfig.enableAudioPreview = YES;
- [_publishController.txLivePublisher setConfig:_publishController.txLivePushonfig];
-
- break;
- case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: // 耳机拔出,停止播放操作
-
- // 关闭耳返功能
- _publishController.txLivePushonfig.enableAudioPreview = NO;
- [_publishController.txLivePublisher setConfig:_publishController.txLivePushonfig];
-
- break;
- case AVAudioSessionRouteChangeReasonCategoryChange:
- // called at start - also when other audio wants to play
- NSLog(@"AVAudioSessionRouteChangeReasonCategoryChange");
- break;
- }
- }
- #pragma mark 重写弹出退出或直接退出
- /**
- 重写 弹出退出或直接退出
-
- @param isDirectCloseLive 该参数针对主播、观众,表示是否直播关闭直播,而不显示结束界面
- @param isHostShowAlert 该参数针对主播,表示主播是否需要弹出“您当前正在直播,是否退出直播?”,正常情况都需要弹出这个,不需要弹出的情况:1、当前直播被后台系统关闭了的情况 2、SDK结束了直播
- @param succ 成功回调
- @param failed 失败回调
- */
- - (void)alertExitLive:(BOOL)isDirectCloseLive isHostShowAlert:(BOOL)isHostShowAlert succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed
- {
- //在后面退出 基础类需要 这个判断 需不需要 Finish界面
- self.isDirectCloseLive = isDirectCloseLive;
-
- [self.liveServiceController.liveUIViewController.liveView.livewWishView.rotateTimer invalidate]; self.liveServiceController.liveUIViewController.liveView.livewWishView.rotateTimer = nil;
-
- LiveCenterManager *liveCenterManager = [LiveCenterManager sharedInstance];
-
- NSLog(@"%ld",_liveInfo.is_live_pay);
- if (self.isHost || !isDirectCloseLive || _liveInfo.is_live_pay == 1) {
- [liveCenterManager closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:isDirectCloseLive isHostShowAlert:isHostShowAlert colseLivecomplete:^(BOOL finished) {
-
- if (finished)
- {
- if (succ)
- {
- succ();
- }
- }
- else
- {
- if (failed)
- {
- failed(FWCode_Normal_Error, @"");
- }
- }
- }];
- }else{
- // [self.navigationController popViewControllerAnimated:YES];
- // if (isHostShowAlert) {
-
- [liveCenterManager closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:isDirectCloseLive isHostShowAlert:isHostShowAlert colseLivecomplete:^(BOOL finished) {
-
- if (isHostShowAlert) {
- [FanweMessage alert:ASLocalizedString(@"您被主播踢出直播间")];
- }
-
- if (finished)
- {
- if (succ)
- {
- succ();
- }
- }
- else
- {
- if (failed)
- {
- failed(FWCode_Normal_Error, @"");
- }
- }
-
- }];
- //悬浮小弹窗
- // }else{
- // [self showHoverViewWithAlert:isHostShowAlert];
- // }
-
- }
- }
- //悬浮view
- -(void)showHoverViewWithAlert:(BOOL)isHostShowAlert{
- NSLog(@"%@",self.liveServiceController);
- NSLog(@"%@",self.linkMicPlayController);
- //6-23 退出直播时关闭pk
- [self.liveServiceController.liveUIViewController pkVivewHidden];
- __weak __typeof(self)weakSelf = self;
-
- self.liveServiceController.clickCloseBlock = ^(BOOL isReresh) {
-
- [weakSelf.hoverView removeFromSuperview];
- weakSelf.hoverView = nil;
- [weakSelf.linkMicPlayController.view removeFromSuperview];
- weakSelf.linkMicPlayController.view = nil;
- };
-
- if (!self.hoverView) {
- self.hoverView = [[WMDragView alloc]init];
- self.hoverView.backgroundColor = kClearColor;
- self.hoverView.button.titleLabel.font = [UIFont systemFontOfSize:15.0];
- [self.hoverView.button setTitle:ASLocalizedString(@"可拖曳")forState:UIControlStateNormal];
- self.hoverView.button.hidden = YES;
- //2020-1-7 小直播变大
-
- self.hoverView.clickDragViewBlock = ^(WMDragView *dragView){
- [weakSelf.hoverView removeFromSuperview];
- weakSelf.hoverView = nil;
- [weakSelf.linkMicPlayController.view removeFromSuperview];
- weakSelf.linkMicPlayController.view = nil;
-
- [[LiveCenterManager sharedInstance] closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:YES isHostShowAlert:YES colseLivecomplete:^(BOOL finished) {
- weakSelf.linkMicPlayController.view = nil;
- weakSelf.linkMicPlayController = nil;
- // 直播管理中心开启观众直播
- BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
- [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem: [LiveCenterManager sharedInstance].itemModel modelArr:nil isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
- }];
- }];
- };
- //__weak __typeof(self)weakSelf = self;
- self.hoverView.duringDragBlock = ^(WMDragView *dragView) {
- weakSelf.linkMicPlayController.videoContrainerView.frame = dragView.frame;
-
-
- };
-
-
-
-
- self.hoverView.endDragBlock = ^(WMDragView *dragView) {
-
- CGContextRef context = UIGraphicsGetCurrentContext();
- [UIView beginAnimations:@"rightMove" context:context];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration:0.5];
-
- weakSelf.linkMicPlayController.videoContrainerView.frame = dragView.frame;
-
- [UIView commitAnimations];
- };
- }
-
- CGRect frame = CGRectMake(kScreenW * 0.7, kScreenH / 2, kScreenW * 0.3, kScreenH * 0.25);
-
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- // [btn setTitle:ASLocalizedString(@"关闭")forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:@"lr_top_close"] forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(clickLive:) forControlEvents:UIControlEventTouchUpInside];
- btn.frame = CGRectMake(frame.size.width - 40, 0, 40, 40);
- [self.hoverView addSubview:btn];
-
-
- //直播界面vc的view
- _linkMicPlayController.view.frame = frame;
- _linkMicPlayController.view.backgroundColor = kClearColor;
- //5-7 悬浮小窗口的阴影
- _linkMicPlayController.pkBgView.hidden=YES;
- [_linkMicPlayController.pkBgView removeAllSubViews];
- _linkMicPlayController.pkBgView=nil;
- //hoverView,拖拽的view
- self.hoverView.frame = _linkMicPlayController.view.bounds;
- //在直播VC上放置视频的view
- _linkMicPlayController.videoContrainerView.frame = _linkMicPlayController.view.bounds;
- [[BGBaseAppDelegate sharedAppDelegate].window addSubview:_linkMicPlayController.view];
-
- [_linkMicPlayController.view addSubview:self.hoverView];
- [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clickLive:) name:@"clickLiveRoomNotification" object:nil];
- }
- //- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- // NSLog(@"%@", touches);
- // UITouch *touch = [touches anyObject];
- //
- // //当前的point
- // CGPoint currentP = [touch locationInView:self.hoverView];
- //
- // //以前的point
- // CGPoint preP = [touch previousLocationInView:self.hoverView];
- //
- // //x轴偏移的量
- // CGFloat offsetX = currentP.x - preP.x;
- //
- // //Y轴偏移的量
- // CGFloat offsetY = currentP.y - preP.y;
- //
- // self.hoverView.transform = CGAffineTransformTranslate(self.hoverView.transform, offsetX, offsetY);
- //}
- //
- //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- //{
- //
- //}
- //观众关闭直播走的方法
- -(void)clickLive:(UIButton *)sender{
-
- self.hoverView.hidden = self.linkMicPlayController.view.hidden = YES;
-
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.hoverView removeFromSuperview];
- self.hoverView = nil;
- [self.linkMicPlayController.view removeFromSuperview];
- self.liveView = nil;
-
- [self clickEndLive];
- });
- });
- }
- -(void)clickEndLive{
- LiveCenterManager *liveCenterManager = [LiveCenterManager sharedInstance];
- __weak __typeof(self)weakSelf = self;
- //4-16 1.苹果端打字不显示直播间自带的发送,手机上面的发送可以用,我手机是苹果11
- [liveCenterManager closeLiveOfPramaOfLiveViewController:self paiTimeNum:nil alertExitLive:YES isHostShowAlert:YES colseLivecomplete:^(BOOL finished) {
- weakSelf.linkMicPlayController.view = nil;
- weakSelf.linkMicPlayController = nil;
- weakSelf.linkMicPlayController.view = nil;
- }];
- }
- #pragma mark - ----------------------- 部分业务逻辑 -----------------------
- #pragma mark 请求get_video接口失败的情况
- - (void)setGetVideoFailed:(NSString *)errMsg
- {
- NSString *errStr = errMsg;
-
- if ([BGUtils isBlankString:errStr])
- {
- errStr = ASLocalizedString(@"获取聊天室信息失败,请稍候尝试");
- }
-
- [self getVideoState:0];
-
- __weak typeof(self) ws = self;
- [BGHUDHelper alert:errStr action:^{
- [ws onExitLiveUI];
- }];
- }
- #pragma mark 真正开始播放
- - (void)beginPlayVideo:(CurrentLiveInfo *)liveInfo
- {
- _iMMsgHandler.isEnterRooming = NO;
-
- __weak typeof(self) ws = self;
-
- if (self.liveType == FW_LIVE_TYPE_HOST)
- {
- if (liveInfo.push_rtmp && ![liveInfo.push_rtmp isEqualToString:@""])
- {
- //声网dev
-
- _publishController.agora_token = liveInfo.agora_token;
- _publishController.pushUrlStr = liveInfo.push_rtmp;
- if (![GlobalVariables sharedInstance].isOtherPush) {
- [_publishController startPushRtmpLiveMethod];
- }
-
- }
- else
- {
- [BGHUDHelper alert:ASLocalizedString(@"抱歉,推流地址为空,请稍后尝试")action:^{
- [ws alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
- }];
- }
- }
-
- else if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- if (liveInfo.play_url && ![liveInfo.play_url isEqualToString:@""])
- {
- // if (!([self.BuguLive.appModel.open_vip intValue] == 1 && liveInfo.is_vip == 0))
- // {
- _linkMicPlayController.playUrlStr = liveInfo.play_url;
- _linkMicPlayController.agora_token = liveInfo.agora_token;
- _linkMicPlayController.roomIDStr = self.roomIDStr;
- // _linkMicPlayController.roomIDStr = liveInfo.agora_token;
- [_linkMicPlayController startRtmp:liveInfo.create_type];
- // }
- }
- else
- {
- // [BGHUDHelper alert:ASLocalizedString(@"抱歉,播放地址为空,请稍后尝试")action:^{
- // [ws alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
- // }];
- }
- }
-
- if (_isHost)
- {
- [_liveServiceController startLiveTimer];
- }
-
- }
- #pragma mark 请求video_cstatus接口来获取直播间信息
- - (void)getVideoState:(NSInteger)state
- {
- NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
- [mDict setObject:@"video" forKey:@"ctl"];
- [mDict setObject:@"video_cstatus" forKey:@"act"];
- [mDict setObject:[NSString stringWithFormat:@"%d",[self.liveItem liveAVRoomId]] forKey:@"room_id"];
- [mDict setObject:StringFromInteger(state) forKey:@"status"];
- if ([self.liveItem liveIMChatRoomId] && ![[self.liveItem liveIMChatRoomId] isEqualToString:@""])
- {
- [mDict setObject:[self.liveItem liveIMChatRoomId] forKey:@"group_id"];
- }
-
- [_liveServiceController getVideoState:mDict];
- }
- //#pragma mark - ----------------------- 回放相关界面事件操作 -----------------------
- //#pragma mark 进度条事件
- //- (void)onClickPlay
- //{
- // [_playController clickPlay:_btnPlay create_type:self.liveInfo.create_type];
- //}
- //
- //- (void)onSeek
- //{
- // [_playController onSeek:_playProgress];
- //}
- //
- //- (void)onSeekBegin
- //{
- // [_playController onSeekBegin:_playProgress];
- //}
- //
- //- (void)onDrag
- //{
- // [_playController onDrag:_playProgress];
- //}
- //
- //- (void)dragSliderDidEnd:(UISlider *)slider
- //{
- // [_playController dragSliderDidEnd:_playProgress];
- //}
- #pragma mark - ----------------------- 连麦 -----------------------
- #pragma mark 观众检查是否有连麦权限(主播不需要此操作)
- - (void)audienceCheckMick
- {
- //检查是否有连麦权限
- NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
- [mDict setObject:@"video" forKey:@"ctl"];
- [mDict setObject:@"check_lianmai" forKey:@"act"];
- [mDict setObject:_roomIDStr forKey:@"room_id"];
-
- [SVProgressHUD show];
-
- [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
-
- [SVProgressHUD dismiss];
- NSString *agora_token = responseJson[@"agora_token"];
- self.linkMicPlayController.agora_token = agora_token;
- if ([responseJson toInt:@"status"] == 1)
- {
- __weak BGIMMsgHandler *wd = _iMMsgHandler;
-
- FWWeakify(self)
- [FanweMessage alert:nil message:ASLocalizedString(@"是否请求与主播连麦?")destructiveAction:^{
-
- FWStrongify(self)
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_APPLY_MIKE;
- sendCustomMsgModel.msgReceiver = [self.liveItem liveHost];
-
- [wd sendCustomC2CMsg:sendCustomMsgModel succ:^{
- [self performSelector:@selector(alertLinkMicking) withObject:nil afterDelay:0.2];
- } fail:^(int code, NSString *msg) {
- [FanweMessage alertHUD:ASLocalizedString(@"您的连麦申请发送失败")];
- }];
-
- } cancelAction:^{
-
- }];
- }
-
- } FailureBlock:^(NSError *error) {
-
- }];
- }
- #pragma mark 主播判断某个观众是否互动观众
- - (BOOL)isInteractUser:(NSString *)userId
- {
- if (userId)
- {
- for (NSString *tmpUserId in _linkMicPlayController.linkMemeberSet)
- {
- if ([userId isEqualToString:tmpUserId])
- {
- return YES;
- }
- }
- }
- return NO;
- }
- #pragma mark 观众发起连麦,关闭连麦
- - (void)openOrCloseMike:(BGLiveServiceController *)liveServiceController
- {
-
- if (_linkMicPlayController.isWaitingResponse)
- {
- [FanweMessage alertHUD:ASLocalizedString(@"连麦申请中...")];
- return;
- }
-
- if (self.linkMicPlayController.isLinkingMic) {
- FWWeakify(self)
- [FanweMessage alert:nil message:ASLocalizedString(@"是否结束与主播的互动连麦?")destructiveAction:^{
-
- FWStrongify(self)
- [self.linkMicPlayController stopLinkMic];
- // [self.linkMicPlayController startRtmp:self.liveInfo.create_type];
-
- } cancelAction:^{
-
- }];
- }
-
- // if ([self isInteractUser:[[IMAPlatform sharedInstance].host imUserId]])
- // {
- // FWWeakify(self)
- // [FanweMessage alert:nil message:ASLocalizedString(@"是否结束与主播的互动连麦?")destructiveAction:^{
- //
- // FWStrongify(self)
- // [self.linkMicPlayController stopLinkMic];
- // [self.linkMicPlayController startRtmp:self.liveInfo.create_type];
- //
- // } cancelAction:^{
- //
- // }];
- // }
- else
- {
- [self audienceCheckMick];
- }
- }
- #pragma mark 申请连麦中,等待对方应答...
- - (void)alertLinkMicking
- {
- _isApplyMicking = YES;
-
- FWWeakify(self)
- _applyMickingAlert = [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"申请连麦中,等待对方应答...")isHideTitle:NO destructiveTitle:ASLocalizedString(@"取消连麦")destructiveAction:^{
-
- FWStrongify(self)
- self.isApplyMicking = NO;
- [self performSelector:@selector(releaseMickingAlert) withObject:nil afterDelay:0.5];
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
- sendCustomMsgModel.msgReceiver = [self.liveItem liveHost];
- sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
- [self.iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
-
- }];
- }
- #pragma mark 关闭申请连麦中的提示
- - (void)cancelMickingAlert
- {
- if (_applyMickingAlert)
- {
- _isApplyMicking = NO;
- [_applyMickingAlert hide];
-
- [self performSelector:@selector(releaseMickingAlert) withObject:nil afterDelay:0.5];
- }
- }
- - (void)releaseMickingAlert
- {
- if (_applyMickingAlert)
- {
- _applyMickingAlert = nil;
- }
- }
- - (void)releaseHostMickingAlert
- {
- if (_hostMickingAlert)
- {
- _hostMickingAlert = nil;
- }
- }
- #pragma mark 主播获取连麦参数
- - (void)getMickPara:(CustomMessageModel *)customMessageModel
- {
- // _isResponseMicking = YES;
- // _isResponseMicking = YES;
- //检查是否有连麦权限
- NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
- [mDict setObject:@"video" forKey:@"ctl"];
- [mDict setObject:@"start_lianmai" forKey:@"act"];
- [mDict setObject:_roomIDStr forKey:@"room_id"];
- [mDict setObject:customMessageModel.sender.user_id forKey:@"to_user_id"];
-
- __weak typeof(self) ws = self;
- __weak BGIMMsgHandler *wm = (BGIMMsgHandler *)_iMMsgHandler;
-
- [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
-
- if ([responseJson toInt:@"status"] == 1)
- {
- NSString *push_rtmp2 = [responseJson toString:@"push_rtmp2"];
- NSString *play_rtmp_acc = [responseJson toString:@"play_rtmp_acc"];
- if (![BGUtils isBlankString:push_rtmp2] && ![BGUtils isBlankString:play_rtmp_acc])
- {
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_RECEIVE_MIKE;
- sendCustomMsgModel.push_rtmp2 = push_rtmp2;
- sendCustomMsgModel.play_rtmp_acc = play_rtmp_acc;
- sendCustomMsgModel.link_mic_user_id = customMessageModel.sender.user_id;
- sendCustomMsgModel.msgReceiver = customMessageModel.sender;
- sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
- [wm sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
-
- [ws.publishController agreeLinkMick:[responseJson toString:@"play_rtmp2_acc"] applicant:customMessageModel.sender.user_id];
- }
- else
- {
- ws.isResponseMicking = NO;
- [FanweMessage alertHUD:ASLocalizedString(@"获取连麦参数失败")];
- }
- }
- else
- {
- ws.isResponseMicking = NO;
- }
- } FailureBlock:^(NSError *error) {
-
- ws.isResponseMicking = NO;
-
- }];
- }
- #pragma mark 主播收到观众连麦请求
- - (void)onRecvGuestApply:(CustomMessageModel *)customMessageModel
- {
- SenderModel *sender = customMessageModel.sender;
- if ([_publishController.linkMemeberSet count] >= _micMaxNum || _hostMickingAlert || _isResponseMicking)
- {
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_REFUSE_MIKE;
- sendCustomMsgModel.msgReceiver = customMessageModel.sender;
-
- if (_hostMickingAlert || _isResponseMicking)
- {
- sendCustomMsgModel.msg = ASLocalizedString(@"主播有未处理的连麦请求,请稍候再试");
- [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
- }
- else
- {
- DebugLog(@"已达到请求上限,不能再请求");
-
- sendCustomMsgModel.msg = ASLocalizedString(@"当前主播连麦数已上限,请稍后尝试");
- [_iMMsgHandler sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
- }
- }
- else
- {
- __weak BGIMMsgHandler *wm = (BGIMMsgHandler *)_iMMsgHandler;
- NSString *text = [NSString stringWithFormat:ASLocalizedString(@"%@向你发来连麦请求"), [sender imUserName]];
-
- FWWeakify(self)
- _hostMickingAlert = [FanweMessage alert:ASLocalizedString(@"提示")message:text destructiveTitle:ASLocalizedString(@"同意")destructiveAction:^{
-
- FWStrongify(self)
- // 同意
- [self getMickPara:customMessageModel];
-
- [self performSelector:@selector(releaseHostMickingAlert) withObject:nil afterDelay:0.2];
-
- } cancelTitle:ASLocalizedString(@"拒绝")cancelAction:^{
-
- FWStrongify(self)
- // 拒绝
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_REFUSE_MIKE;
- sendCustomMsgModel.msgReceiver = customMessageModel.sender;
- [wm sendCustomC2CMsg:sendCustomMsgModel succ:nil fail:nil];
-
- [self performSelector:@selector(releaseHostMickingAlert) withObject:nil afterDelay:0.2];
- }];
- }
- }
- #pragma mark 主播未处理连麦申请时,kApplyMikeTime秒后关闭申请连麦弹出框
- - (void)closeAlertView
- {
- if (_hostMickingAlert)
- {
- [_hostMickingAlert hide];
- [self performSelector:@selector(releaseHostMickingAlert) withObject:nil afterDelay:0.2];
- }
- }
- - (void)showRefuseHud:(NSString *)refuseStr
- {
- [FanweMessage alert:refuseStr];
- }
- #pragma mark FWTLinkMicPlayControllerDelegate
- /*
- * 观众端连麦结果
- * isSucc:是否上麦
- * userID:当前用户ID
- */
- - (void)pushMickResult:(BOOL)isSucc userID:(NSString *)userID
- {
- if (![BGUtils isBlankString:userID])
- {
- if (isSucc)
- {
- if ([[[IMAPlatform sharedInstance].host imUserId] isEqualToString:userID])
- {
- // [BGLiveSDKViewModel tLiveMixStream:_roomIDStr toUserId:@""];
- }
- }
- else
- {
- if ([[[IMAPlatform sharedInstance].host imUserId] isEqualToString:userID])
- {
- [BGLiveSDKViewModel tLiveStopMick:_roomIDStr toUserId:@""];
- }
-
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
- sendCustomMsgModel.msgReceiver = [self.liveItem liveHost];
- sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
- [_iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
- }
- }
- }
- #pragma mark FWTLinkMicPublishControllerDelegate
- /*
- * 主播端连麦结果
- * isSucc:是否拉取观众连麦加速流成功
- * userID:拉取的连麦观众对应的ID
- */
- - (void)playMickResult:(BOOL)isSucc userID:(NSString *)userID
- {
- _isResponseMicking = NO;
-
- if (![BGUtils isBlankString:userID])
- {
- if (isSucc)
- {
- [BGLiveSDKViewModel tLiveMixStream:_roomIDStr toUserId:userID];
- }
- }
- }
- #pragma mark 主播点击屏幕时,判断是否点击了连麦窗口
- - (void)hostReceiveTouch:(UITouch *)touch
- {
- if ([_publishController.linkMemeberSet count])
- {
- for (NSString *user in _publishController.linkMemeberSet)
- {
- BGTLinkMicPlayItem *playItem = [self.publishController getPlayItemByUserID:user];
- if (playItem)
- {
- if(CGRectContainsPoint(playItem.videoView.frame, [touch locationInView:self.publishController.view]))
- {
- UserModel *userModel;
- for (UserModel *tmpModel in _liveServiceController.liveUIViewController.liveView.topView.userArray)
- {
- if ([tmpModel.user_id isEqualToString:user])
- {
- userModel = tmpModel;
- break;
- }
- }
- if (!userModel)
- {
- userModel = [[UserModel alloc]init];
- userModel.user_id = user;
- }
-
- MMPopupCompletionBlock completeBlock = ^(MMPopupView *popupView, BOOL finished){
- NSLog(@"animation complete");
- };
-
- HostCheckMickAlertView *view = [[HostCheckMickAlertView alloc] initAlertView:userModel closeMickBlock:^(UserModel *userModel) {
-
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
- sendCustomMsgModel.msgReceiver = userModel;
- sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
- [[BGIMMsgHandler sharedInstance] sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
- [BGLiveSDKViewModel tLiveStopMick:_roomIDStr toUserId:userModel.user_id];
-
- }];
- [view showWithBlock:completeBlock];
- }
- }
- }
- }
- }
- #pragma mark - ----------------------- 横竖屏 -----------------------
- - (void)goVerticalScreen
- {
- [self interfaceOrientation:UIInterfaceOrientationPortrait];
- }
- #pragma mark PC直播或者PC回播,观众端的点击全屏事件
- - (void)clickFullScreen
- {
- [self interfaceOrientation:UIInterfaceOrientationLandscapeRight];
- }
- - (void)interfaceOrientation:(UIInterfaceOrientation)orientation
- {
- if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
- {
- SEL selector = NSSelectorFromString(@"setOrientation:");
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
- [invocation setSelector:selector];
- [invocation setTarget:[UIDevice currentDevice]];
- int val = orientation;
- [invocation setArgument:&val atIndex:2];
- [invocation invoke];
- }
- }
- - (void)deviceOrientationDidChange
- {
- if (self.liveInfo.create_type == 1)
- {
- NSLog(@"deviceOrientationDidChange:%ld",(long)[UIDevice currentDevice].orientation);
- if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait)
- {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
- [self orientationChange:kDirectionTypeDefault];
- }
- else if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft)
- {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
- [self orientationChange:kDirectionTypeLeft];
- }
- }
- }
- - (void)orientationChange:(kDirectionType)landscape
- {
- if (landscape == kDirectionTypeDefault)
- {
- [[UIApplication sharedApplication] setStatusBarHidden:NO];
- _liveServiceController.liveUIViewController.liveView.hidden = NO;
- _liveServiceController.closeBtn.hidden = NO;
-
- [UIView animateWithDuration:0.2f animations:^{
- self.view.transform = CGAffineTransformMakeRotation(0);
- self.view.bounds = CGRectMake(0, 0, kScreenW, kScreenH);
-
-
- if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- _linkMicPlayController.videoContrainerView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
- self.backVerticalBtn.hidden = YES;
- }
- }];
- }
- else if (landscape == kDirectionTypeLeft)
- {
- [[UIApplication sharedApplication] setStatusBarHidden:YES];
- _liveServiceController.liveUIViewController.liveView.hidden = YES;
- _liveServiceController.closeBtn.hidden = YES;
-
- [UIView animateWithDuration:0.2f animations:^{
- self.view.transform = CGAffineTransformMakeRotation(M_PI_2);
- self.view.bounds = CGRectMake(0, 0, kScreenW, kScreenH);
-
- if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- _linkMicPlayController.videoContrainerView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
- self.backVerticalBtn.hidden = NO;
- }
- }];
- }
- }
- #pragma mark - ----------------------- 代理方法 -----------------------
- #pragma mark FWLiveServiceControllerDelegate
- #pragma mark 收到自定义C2C消息
- - (void)recvCustomC2C:(id<AVIMMsgAble>)msg
- {
- if (![msg isKindOfClass:[CustomMessageModel class]])
- {
- return;
- }
-
- CustomMessageModel *customMessageModel = (CustomMessageModel *)msg;
- switch (customMessageModel.type)
- {
- case MSG_APPLY_MIKE: // 观众申请连麦(主播收到观众连麦请求消息)
- {
- // 关闭键盘
- [BGUtils closeKeyboard];
-
- _linkMicPlayController.isWaitingResponse = YES;
- [self onRecvGuestApply:customMessageModel];
-
- // [_publishController breakLinkMick:customMessageModel.sender.user_id];
- }
- break;
- case MSG_RECEIVE_MIKE: // 主播接受连麦(观众收到主播接受连麦消息)
- {
- if (_isApplyMicking == NO)
- {
- break;
- }
- // 关闭键盘
- [BGUtils closeKeyboard];
- [self cancelMickingAlert];
-
- if (![BGUtils isBlankString:customMessageModel.push_rtmp2] && ![BGUtils isBlankString:customMessageModel.play_rtmp_acc])
- {
- // [_linkMicPlayController stopRtmp];
-
- //开始连麦,启动推流
- _linkMicPlayController.push_rtmp2 = customMessageModel.push_rtmp2;
- _linkMicPlayController.play_rtmp_acc = customMessageModel.play_rtmp_acc;
- _linkMicPlayController.isWaitingResponse = NO;
- [_linkMicPlayController startVideoLiveLinkMic];
-
- [self cancelMickingAlert];
- }
- else
- {
- [FanweMessage alertHUD:ASLocalizedString(@"获取连麦参数失败")];
- }
-
- }
- break;
- case MSG_REFUSE_MIKE: // 主播拒绝连麦(观众收到主播拒绝连麦消息)
- {
- [self cancelMickingAlert];
-
- _linkMicPlayController.isWaitingResponse = NO;
-
- NSString *refuseStr = ASLocalizedString(@"主播拒绝了您的连麦请求");
-
- if (![BGUtils isBlankString:customMessageModel.msg])
- {
- refuseStr = customMessageModel.msg;
- }
-
- [self showRefuseHud:refuseStr];
- }
- break;
- case MSG_BREAK_MIKE: // 断开连麦(观众收到主播断开连麦消息 或者 主播收到观众主动断开连麦消息)
- {
- if (_isHost) // 主播收到观众主动断开连麦消息
- {
- [self closeAlertView];
- [_publishController breakLinkMick:customMessageModel.sender.user_id];
- }
- else
- {
- [_linkMicPlayController stopLinkMic];
- [_linkMicPlayController startRtmp:self.liveInfo.create_type];
- }
- }
- break;
- case MSG_ACCEPT_PK:
- {
- // if (_isApplyMicking)
- // {
- // 关闭键盘
- [BGUtils closeKeyboard];
- //接受pk!!
- // }
- }
- break;
-
- case MSG_END_PK:
- {
- // if (_isApplyMicking)
- // {
- // 关闭键盘
- [BGUtils closeKeyboard];
- //接受pk!!
-
- // }
- }
- break;
- default:
- break;
- }
- }
- #pragma mark 收到自定义的Group消息
- - (void)recvCustomGroup:(id<AVIMMsgAble>)msg
- {
- if (![msg isKindOfClass:[CustomMessageModel class]])
- {
- return;
- }
- CustomMessageModel *customMessageModel = (CustomMessageModel *)msg;
- switch (customMessageModel.type)
- {
- case MSG_SEND_GIFT_SUCCESS:
- {
- [_linkMicPlayController updateLianMaiCoin];
- [_publishController updateLianMaiCoin];
- }
- break;
- case MSG_LianMai_Mute: // 主播把我静音
- {
- // [_linkMicPlayController muteStatus:customMessageModel.mute_status andUserId:customMessageModel.to_user_id];
- }
- break;
- case MSG_REFRESH_AUDIENCE_LIST: // 主播、所有连麦观众收到的定时连麦消息
- {
- // 当 data_type == 1,主播、所有连麦观众收到的定时连麦消息
- if (customMessageModel.data_type == 1)
- {
- TLiveMickListModel *mickListModel = [TLiveMickListModel mj_objectWithKeyValues:customMessageModel.data];
-
- if (self.liveType == FW_LIVE_TYPE_HOST)
- {
- [_publishController adjustPlayItem:mickListModel];
- }
- else if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController adjustPlayItem:mickListModel];
- }
- }
- }
- break;
-
- case MSG_REFRESH_VOICE_Lianmai:
- {
- NSLog(@"========>>>>>>>>>>>>>>>");
-
- NSLog(@"%@",customMessageModel.dicData);
- NSArray *list = [NSArray modelArrayWithClass:VoiceLianmaiUserModel.class json:customMessageModel.dicData[@"data"]];
-
- if (self.liveType == FW_LIVE_TYPE_HOST)
- {
-
- [_publishController adjustPlayItemVoiceUserList:list];
- }
- else if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController adjustPlayItemVoiceUserList:list];
- }
- NSLog(@"========>>>>>>>>>>>>>>>");
- // 当 data_type == 1,主播、所有连麦观众收到的定时连麦消息
- // if (customMessageModel.data_type == 1)
- // {
- // TLiveMickListModel *mickListModel = [TLiveMickListModel mj_objectWithKeyValues:customMessageModel.data];
- //
- // if (self.liveType == FW_LIVE_TYPE_HOST)
- // {
- // [_publishController adjustPlayItem:mickListModel];
- // }
- // else if(self.liveType == FW_LIVE_TYPE_AUDIENCE)
- // {
- // [_linkMicPlayController adjustPlayItem:mickListModel];
- // }
- // }
- }
- break;
- case MSG_RECEIVE_MIKE: // 主播接受连麦(观众收到主播接受连麦消息)
- {
- _linkMicPlayController.isWaitingResponse = NO;
- if (_isApplyMicking)
- {
- // 关闭键盘
- [BGUtils closeKeyboard];
- [self cancelMickingAlert];
- }
- }
- break;
- case MSG_REFUSE_MIKE: // 主播拒绝连麦(观众收到主播拒绝连麦消息)
- {
- _linkMicPlayController.isWaitingResponse = NO;
-
- // 关闭键盘
- [BGUtils closeKeyboard];
- [self cancelMickingAlert];
- }
- break;
- default:
- break;
- }
-
- // if([customMessageModel.link_mic_user_id isEqualToString:[IMAPlatform sharedInstance].host.userId])
- }
- #pragma mark 请求完接口后,刷新直播间相关信息
- - (void)refreshCurrentLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo
- {
- [self refreshLiveItem:liveItem liveInfo:liveInfo];
- }
- #pragma mark 点击飞屏模式,切换直播间(因切换房间涉及到比较多的逻辑,比如:付费、游戏,所以该方法暂时不用)
- - (void)switchLiveRoom
- {
- [self stopLiveRtmp];
-
- [self startEnterChatGroup:nil succ:^{
- NSLog(@"11111");
- } failed:^(int errId, NSString *errMsg) {
- NSLog(@"22222");
- }];
- }
- #pragma mark 关闭直播间代理事件
- - (void)clickCloseLive:(BOOL)isDirectCloseLive isHostShowAlert:(BOOL)isHostShowAlert
- {
- // [self.linkMicPlayController.agoraKit leaveChannel:^(AgoraChannelStats * _Nonnull stat) {
- //
- // }];
- [self.linkMicPlayController.trtcCloud exitRoom];
- [TRTCCloud destroySharedInstance];
- [self alertExitLive:isDirectCloseLive isHostShowAlert:isHostShowAlert succ:nil failed:nil];
- }
- #pragma mark 结束界面点击“返回首页”
- - (void)finishViewClose:(BGLiveServiceController *)liveServiceController
- {
- UITabBarController *tabBars = [BGTabBarController sharedInstance];
- tabBars.selectedIndex = 0;
- // 已经走到这里了 必然更改记录
- SUS_WINDOW.isDirectCloseLive = YES;
- [self onExitLiveUI];
- }
- #pragma mark PlayControllerDelegate 结束回播,用来判断是否还有下一段回播
- - (void)stopReLive
- {
- // 暂时不用做什么操作
- }
- #pragma mark ToolsViewDelegate
- - (void)selectToolsItemWith:(ToolsView *)toolsView selectIndex:(NSInteger)index isSelected:(BOOL)isSelected
- {
- _toolsView = toolsView;
-
- if (index == 999)
- { // 音乐
- if ([GlobalVariables sharedInstance].isOtherPush) {
- self.otherPushPopView.liveInfo = self.liveInfo;
- [self.otherPushPopView show:self.view type:FDPopTypeCenter];
- }else{
- [[[YunMusicPlayVC alloc] init] showYunMusicPlayInVC:self inview:self.liveServiceController.liveUIViewController.liveView showframe:CGRectMake(0,200, self.view.bounds.size.width,130) myPlayType:0];
- }
- }
- else if (index == 0)
- { // 美颜
- // 如果key不为空就调用笑脸点击后出现的美颜控制台
- NSString* key = [GlobalVariables sharedInstance].appModel.bogo_beauty_key;
- if([BGUtils isBlankString:key])
- {
- _beautyView.hidden = NO;
- }else{
- KPostNotification(@"onMainSwitchButtonClick", nil);
-
- // [self.tiUIView onMainSwitchButtonClick:nil];
- // _beautyPanel.hidden = NO;
- // [[TiUIManager shareManager]showMainMenuView];
- }
- }
-
- else if (index == 1)
- { // 麦克风
- if (isSelected == YES)
- {
- _isMuted = NO;
- [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"已打开麦克风")];
- }
- else
- {
- _isMuted = YES;
- [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"已关闭麦克风")];
- }
-
- if([GlobalVariables sharedInstance].openAgora)
- {
- // [self.publishController.agoraKit muteLocalAudioStream:!isSelected];
- [self.publishController.trtcCloud muteLocalAudio:!isSelected];
- }
-
- }
- else if (index == 2)
- {
- // 切换摄像
- [[self.publishController.trtcCloud getDeviceManager] switchCamera:![[self.publishController.trtcCloud getDeviceManager] isFrontCamera]];
-
- BOOL isFrontCamera = [[self.publishController.trtcCloud getDeviceManager] isFrontCamera];
- toolsView.isRearCamera = !isFrontCamera;
- if (isFrontCamera) {
- toolsView.isClick = NO;
-
- [toolsView.toolsCollectionView deselectItemAtIndexPath:[NSIndexPath indexPathWithIndex:3] animated:NO];
- }
- }
- else if (index == 3) {
- //判断当前是否为前置摄像头(仅适用于移动端)
- BOOL isFrontCamera = [[self.publishController.trtcCloud getDeviceManager] isFrontCamera];
- if (isFrontCamera){
- [FanweMessage alert:ASLocalizedString(@"前置摄像头下暂时不能打开闪光灯")];
- return;
- }
- [[self.publishController.trtcCloud getDeviceManager] enableCameraTorch:isSelected];
- }
- else if (index == 4)
- {
- if (isSelected == YES)
- {
- [FanweMessage alert:ASLocalizedString(@"已打开镜像")];
- }
- else
- {
- [FanweMessage alert:ASLocalizedString(@"已关闭镜像")];
- }
-
- // 设置本地画面的预览模式:开启左右镜像,设置画面为填充模式
- TRTCRenderParams *param = [[TRTCRenderParams alloc] init];
-
- if(isSelected == YES) {
- param.mirrorType = TRTCVideoMirrorTypeEnable;
- } else {
- param.mirrorType = TRTCVideoMirrorTypeDisable;
- }
- [_publishController.trtcCloud setLocalRenderParams:param];
- }
- //音效
-
- }
- #pragma mark TCShowLiveTopViewToSDKDelegate
- #pragma mark 推拉流请求所的码率
- - (void)refreshKBPS:(TCShowLiveTopView *)topView
- {
- NSDictionary *tmpDict;
- if ([self.liveItem liveType] == 0)
- {
- tmpDict = _publishController.qualityDict;
- }
- else if ([self.liveItem liveType] == 1)
- {
- tmpDict = _playController.qualityDict;
- }
- else if ([self.liveItem liveType] == 2)
- {
- tmpDict = _linkMicPlayController.qualityDict;
- }
-
- int totalkb = ([tmpDict toInt:NET_STATUS_VIDEO_BITRATE] + [tmpDict toInt:NET_STATUS_AUDIO_BITRATE])/8;
-
- if (totalkb)
- {
- topView.kbpsSendLabel.hidden = NO;
- topView.kbpsRecvLabel.hidden = YES;
-
- CGRect newFrame = topView.kbpsSendLabel.frame;
- newFrame.origin.y = CGRectGetHeight(topView.kbpsContainerView.frame)/4;
- topView.kbpsSendLabel.frame = newFrame;
- }
- else
- {
- topView.kbpsSendLabel.hidden = YES;
- topView.kbpsRecvLabel.hidden = YES;
- }
-
- topView.kbpsSendLabel.text = [NSString stringWithFormat:@"%@%dk",[self.liveItem liveType] == 0 ? @"↑" : @"↓" ,totalkb];
- }
- #pragma mark FWTPublishControllerDelegate
- #pragma mark 腾讯云直播的主播首帧回调
- - (void)firstIFrame:(BGTPublishController*)publishVC
- {
- if (!_hasShowVagueImg)
- {
- [self hideVagueImgView];
-
- // 设置默认美颜
- [self setCurrentBeautyValue:self.BuguLive.appModel.beauty_ios whiteValue:0];
-
- SUS_WINDOW.isPushStreamIng = YES;
- }
- }
- #pragma mark 推流时,网络断连,且经多次重连抢救无效后退出app
- - (void)exitPublishAndApp:(BGTPublishController *)publishVC
- {
- [self alertExitLive:NO isHostShowAlert:NO succ:nil failed:nil];
- }
- #pragma mark FWTPlayControllerDelegate
- #pragma mark 腾讯云直播的观众、回播首帧回调
- - (void)firstFrame:(BGTPlayController*)playVC
- {
- [self hideVagueImgView];
- }
- #pragma mark 拉流时,网络断连,重连
- - (void)playAgain:(BGTPlayController *)publishVC isHideLeaveTip:(BOOL)isHideLeaveTip
- {
- if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController startRtmp:self.liveInfo.create_type];
- }
-
- if (!_liveServiceController.anchorLeaveTipLabel.isHidden && isHideLeaveTip)
- {
- _liveServiceController.anchorLeaveTipLabel.hidden = YES;
- }
- }
- #pragma mark 拉流时,网络断连,且经多次重连抢救无效后退出app
- - (void)exitPlayAndApp:(BGTPlayController *)publishVC
- {
- [self alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
- }
- #pragma mark livePayDelegate
- #pragma mark 付费直播是否加载直播间视频的代理
- - (void)livePayLoadVedioIsComfirm:(BOOL)isComfirm
- {
- if (isComfirm)
- {
- if (!self.hasEnterChatGroup)
- {
- [self.linkMicPlayController stopRtmp];
- if (self.liveType == FW_LIVE_TYPE_AUDIENCE)
- {
- [self.linkMicPlayController.txLivePlayer setMute:NO];
- }
- [self.liveServiceController.liveUIViewController dealLivepayTComfirm];
- FWWeakify(self)
- [self.liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
- FWStrongify(self)
- self.liveInfo = liveInfo;
- [self beginPlayVideo:liveInfo];
- self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
-
- [super startEnterChatGroup:_liveInfo.group_id succ:nil failed:nil];
-
- } roomID:@"" failed:^(int errId, NSString *errMsg){
-
- }];
- }
- }
- else
- {
- [self alertExitLive:YES isHostShowAlert:NO succ:nil failed:nil];
- }
- }
- -(void)protocolGetVideoWithRoomID:(NSString *)roomID{
-
- FWWeakify(self)
-
- [self.liveServiceController getVideo:^(CurrentLiveInfo *liveInfo) {
- TCShowUser *user = [[TCShowUser alloc] init];
- user.avatar = liveInfo.podcast.user.head_image;
- user.uid = liveInfo.user_id;
- user.username = liveInfo.podcast.user.nick_name;
-
- TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
- liveRoom.host = user;
- liveRoom.avRoomId = [liveInfo.room_id intValue];
- liveRoom.title = [NSString stringWithFormat:@"%d",liveRoom.avRoomId];
- liveRoom.vagueImgUrl = liveInfo.podcast.user.head_image;
- //SUS_WINDOW 去记录直播间类型 这是不是观众
- liveRoom.liveType = SUS_WINDOW.liveType;
- liveRoom.isHost = NO;
-
-
- // TCShowLiveView *liveView = [[TCShowLiveView alloc]initWith:liveRoom liveController:self];
- // _liveServiceController.liveUIViewController.liveView = liveView;
- _liveServiceController.liveUIViewController.liveScrollView.roomID = liveInfo.room_id;
- [_liveServiceController.liveUIViewController.liveView refreshLiveItem:liveRoom liveInfo:liveInfo];
-
- FWStrongify(self)
- self.liveInfo = liveInfo;
- [self beginPlayVideo:liveInfo];
- self.hasVideoControl = liveInfo.has_video_control ? YES : NO;
-
- _linkMicPlayController.videoContrainerView.top = 0;
- _liveServiceController.liveUIViewController.liveScrollView.top = 0;
- _firstImgView.top = _linkMicPlayController.videoContrainerView.bottom;
- _secondImgView.top = _firstImgView.bottom;
-
- NSLog(@"_liveServiceControlle.scrollview%@",_liveServiceController.liveUIViewController.liveScrollView);
- [FanweMessage alert:ASLocalizedString(@"切换直播间成功!")];
-
- [super startEnterChatGroup:liveInfo.group_id succ:nil failed:nil];
-
- } roomID:roomID failed:^(int errId, NSString *errMsg) {
-
- }];
- }
- #pragma mark 付费直播关闭直播间的声音
- - (void)voiceNotice:(NSNotification*)notification
- {
- NSMutableDictionary *dictM = [notification object];
- if ([dictM toInt:@"type"] == 0)//关闭声音
- {
- [self setSDKMute:YES];
- }
- else if ([dictM toInt:@"type"] == 1)//打开声音
- {
- [self setSDKMute:NO];
- }
- }
- #pragma mark ------------------------ 实现FWLiveControllerAble协议 -----------------------
- #pragma mark 开始推流、拉流
- - (void)startLiveRtmp:(NSString *)playUrlStr
- {
- if (![BGUtils isBlankString:playUrlStr])
- {
- if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
- {
- _publishController.pushUrlStr = playUrlStr;
- if (![GlobalVariables sharedInstance].isOtherPush) {
- [_publishController startPushRtmpLiveMethod];
- }
- }
- else if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
- {
- _linkMicPlayController.playUrlStr = playUrlStr;
- [_linkMicPlayController startRtmp:self.liveInfo.create_type];
- }
- }
- }
- #pragma mark 结束推流、拉流
- - (void)stopLiveRtmp
- {
- if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
- {
- [_publishController stopRtmp];
- }
- else if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
- {
- [_linkMicPlayController stopRtmp];
- }
- }
- //#pragma mark 按时付费剩余时间的倒计时
- //- (void)livePayLeftTimeGo
- //{
- // _liveServiceController.liveUIViewController.livePayLeftCount --;
- // if (_liveServiceController.liveUIViewController.livePayLeftCount == 0)
- // {
- // [_liveServiceController.liveUIViewController.livePayLeftTimer invalidate];
- // _liveServiceController.liveUIViewController.livePayLeftTimer =nil;
- // }else
- // {
- // _liveServiceController.liveUIViewController.livePayLabel.text = [NSString stringWithFormat:ASLocalizedString(@"亲,大约%d秒后进入直播间"),_liveServiceController.liveUIViewController.livePayLeftCount];
- // }
- //}
- #pragma mark TCShowLiveViewToSDKDelegate
- - (void)hideReLiveSlide:(BOOL)isHided
- {
- if (isHided)
- {
- _reLiveProgressView.hidden = YES;
- }
- else
- {
- if (self.hasVideoControl)
- {
- _reLiveProgressView.hidden = NO;
- }
- }
- }
- #pragma mark - ----------------------- 美颜 -----------------------
- #pragma mark 设置美颜类型(FWTLiveBeautyViewDelegate)
- - (void)setBeauty:(BGTLiveBeautyView *)beautyView withBeautyName:(NSString *)beautyName
- {
- if (_publishController.txLivePublisher)
- {
- if (![BGUtils isBlankString:beautyName])
- {
- NSString * path = [[NSBundle mainBundle] pathForResource:@"FilterResource" ofType:@"bundle"];
- if(path && ![beautyName isEqualToString:ASLocalizedString(@"普通美颜")])
- {
- path = [path stringByAppendingPathComponent:beautyName];
- UIImage *image = [UIImage imageWithContentsOfFile:path];
- [_publishController.txLivePublisher setFilter:image];
- }
- else if ([beautyName isEqualToString:ASLocalizedString(@"普通美颜")])
- {
- [_publishController.txLivePublisher setFilter:nil];
- }
- }
- else
- {
- [_publishController.txLivePublisher setFilter:nil];
-
- [self setCurrentBeautyValue:0 whiteValue:0];
- }
- }
- }
- #pragma mark - 设置美颜的值
- - (void)setBeautyValue:(BGTLiveBeautyView *)beautyView {
- // if (_publishController.txLivePublisher) {
- // [_publishController.txLivePublisher setBeautyStyle:0 beautyLevel:beautyView.filterParam1.slider.value/10 whitenessLevel:beautyView.filterParam2.slider.value/10 ruddinessLevel:0];
- // }
-
- // AgoraBeautyOptions *option = [[AgoraBeautyOptions alloc] init];
- // option.lighteningLevel = beautyView.filterParam2.slider.value/100;
- // option.smoothnessLevel = beautyView.filterParam1.slider.value/100;
- // option.rednessLevel = beautyView.filterParam3.slider.value/100;
-
- //功能描述:设置美颜级别
- TXBeautyManager *bm = [self.publishController.trtcCloud getBeautyManager];
- [bm setBeautyLevel:beautyView.filterParam1.slider.value/10];
- // 功能描述:设置美颜(磨皮)算法
- [bm setBeautyStyle:TXBeautyStyleNature];
-
- //美白
- [bm setWhitenessLevel:beautyView.filterParam2.slider.value/10];
-
- //功能描述:设置红润级别
- [bm setRuddyLevel:beautyView.filterParam3.slider.value/10];
-
- NSLog(@"红润 = %f",beautyView.filterParam3.slider.value/10);
- NSLog(@"美颜 = %f",beautyView.filterParam1.slider.value/10);
-
- // [_publishController.agoraKit setBeautyEffectOptions:YES options:option];
- }
- - (void)setCurrentBeautyValue:(float)beautyDepth whiteValue:(float)whiteDepth
- {
- _beautyView.filterParam1.slider.value = beautyDepth;
- _beautyView.filterParam2.slider.value = whiteDepth;
- [_beautyView.filterParam1 updateValue];
- [_beautyView.filterParam2 updateValue];
-
- [self setBeautyValue:_beautyView];
- }
- #pragma mark - ----------------------- 其他 -----------------------
- #pragma mark 获取当前直播质量
- - (NSString *)getLiveQuality
- {
- NSDictionary *tmpDict;
- if ([self.liveItem liveType] == 0)
- {
- tmpDict = _publishController.qualityDict;
- }
- else
- {
- tmpDict = _playController.qualityDict;
- }
-
- NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
-
- // 设备类型
- [mDict setObject:@"Ios" forKey:@"device"];
- // app占用CPU
- if ([tmpDict toFloat:NET_STATUS_CPU_USAGE_D])
- {
- [mDict setObject:[NSString stringWithFormat:@"%f",[tmpDict toFloat:NET_STATUS_CPU_USAGE_D]*100] forKey:@"appCPURate"];
- }
- // 系统占用CPU
- if ([tmpDict toFloat:NET_STATUS_CPU_USAGE])
- {
- [mDict setObject:[NSString stringWithFormat:@"%f",[tmpDict toFloat:NET_STATUS_CPU_USAGE]*100] forKey:@"sysCPURate"];
- }
- // 画面帧率,如:25
- if ([tmpDict toString:NET_STATUS_VIDEO_FPS])
- {
- [mDict setObject:[tmpDict toString:NET_STATUS_VIDEO_FPS] forKey:@"fps"];
- }
-
- // 发送、接收码率(每秒钟发送、接收的数据量)
- int totalkbps = [tmpDict toInt:NET_STATUS_VIDEO_BITRATE] + [tmpDict toInt:NET_STATUS_AUDIO_BITRATE];
- int totalkb = totalkbps/8;
- if (totalkb)
- {
- if ([self.liveItem liveType] == 0)
- {
- [mDict setObject:StringFromInt(totalkb) forKey:@"sendKBps"];
- }
- else
- {
- [mDict setObject:StringFromInt(totalkb) forKey:@"recvKBps"];
- }
- }
-
- // 显示网络差的提示
- int netSpeed = [tmpDict toInt:NET_STATUS_NET_SPEED];
- if(netSpeed == 0) {netSpeed = 1;}
- float loss_rate_send = (netSpeed-totalkbps)/netSpeed;
-
- if ([self.liveItem liveType] == 0)
- {
- [mDict setObject:[NSString stringWithFormat:@"%f",loss_rate_send] forKey:@"sendLossRate"];
- }
- else
- {
- [mDict setObject:[NSString stringWithFormat:@"%f",loss_rate_send] forKey:@"recvLossRate"];
- }
-
- if (loss_rate_send <= 0.2)
- {
- _lossRateSendTipLabel.hidden = YES;
- }
- else if(loss_rate_send > 0.2 && loss_rate_send < 0.3)
- {
- _lossRateSendTipLabel.hidden = NO;
- _lossRateSendTipLabel.text = kHostNetLowTip1;
- _lossRateSendTipLabel.textColor = kYellowColor;
- }
- else
- {
- _lossRateSendTipLabel.hidden = NO;
- _lossRateSendTipLabel.text = kHostNetLowTip2;
- _lossRateSendTipLabel.textColor = kRedColor;
- }
-
- NSString *sendMessage = [BGUtils dataTOjsonString:mDict];
-
- if (sendMessage)
- {
- return sendMessage;
- }
- else
- {
- return @"";
- }
- }
- #pragma mark 获取当前视频容器视图的父视图
- - (UIView *)getPlayViewBottomView
- {
- if ([self.liveItem liveType] == FW_LIVE_TYPE_HOST)
- {
- return _publishController.view;
- }
- else if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
- {
- return _linkMicPlayController.view;
- }
- return nil;
- }
- #pragma mark 设置静音 YES:设置为静音
- - (void)setSDKMute:(BOOL)bEnable
- {
- if (bEnable) // 关闭声音
- {
- if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
- {
- [self.linkMicPlayController.txLivePlayer setMute:YES];
- }
- }
- else // 打开声音
- {
- if ([self.liveItem liveType] == FW_LIVE_TYPE_AUDIENCE)
- {
- [self.linkMicPlayController.txLivePlayer setMute:NO];
- }
- }
- }
- #pragma mark - ----------------------- 其他 -----------------------
- #pragma mark 解决不能调为最小音量问题
- - (void)volumeChanged:(NSNotification *)noti
- {
- NSDictionary *tmpDict = noti.userInfo;
- if (tmpDict && [tmpDict isKindOfClass:[NSDictionary class]])
- {
- if ([[tmpDict toString:@"AVSystemController_AudioVolumeChangeReasonNotificationParameter"] isEqualToString:@"ExplicitVolumeChange"] && !_isMuted)
- {
- float volume = [[tmpDict objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
-
- if (volume <= 0.062500)
- {
- [_publishController.txLivePublisher setMute:YES];
- }
- else
- {
- [_publishController.txLivePublisher setMute:NO];
- }
- }
- }
- }
- - (BGOtherPushPopView *)otherPushPopView{
- if (!_otherPushPopView) {
- _otherPushPopView = [[NSBundle mainBundle] loadNibNamed:@"BGOtherPushPopView" owner:nil options:nil].lastObject;
- }
- return _otherPushPopView;
- }
- #pragma mark - 断开连麦
- -(void)clickCloseBtn:(UserView *)view
- {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:ASLocalizedString(@"是否断开与%@连麦"),view.userName.text] message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *sureAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"确定按键被点击");
-
- NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
- [mDict setObject:@"video" forKey:@"ctl"];
- [mDict setObject:@"stop_lianmai" forKey:@"act"];
-
- [mDict setObject:self.roomIDStr forKey:@"room_id"];
-
- [mDict setObject:view.uid forKey:@"to_user_id"];
-
-
- [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
-
- } FailureBlock:^(NSError *error) {
-
- }];
- SendCustomMsgModel *sendCustomMsgModel = [[SendCustomMsgModel alloc] init];
- sendCustomMsgModel.msgType = MSG_BREAK_MIKE;
- sendCustomMsgModel.chatGroupID = [self.liveItem liveIMChatRoomId];
- [self.iMMsgHandler sendCustomGroupMsg:sendCustomMsgModel succ:nil fail:nil];
-
- }];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"取消按键被点击");
- }];
-
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [self presentViewController:alert animated:YES completion:^{
-
- }];
- }
- - (void)dealloc
- {
- [[NSNotificationCenter defaultCenter]removeObserver:self];
- }
- @end
|