PlayerViewController.mm 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993
  1. //
  2. // ViewController.m
  3. // VideoTest
  4. //
  5. // Created by APPLE on 2019/5/29.
  6. // Copyright © 2019 APPLE. All rights reserved.
  7. //
  8. #import "PlayerViewController.h"
  9. #import "PlayerViewController+TouchPointXD.h"
  10. #import "PlayerViewController+AdjustBtnFrame.h"
  11. #import "PlayerViewController+AppDelegate.h"
  12. #import "PlayerViewController+otherDelegate.h"
  13. #import <AVFoundation/AVFoundation.h>
  14. #import <ifaddrs.h>
  15. #import <arpa/inet.h>
  16. #import <SystemConfiguration/CaptiveNetwork.h>
  17. #import <SDWebImage.h>
  18. #import "FLAnimatedImage.h"
  19. #import<objc/runtime.h>
  20. #import "BGTool.h"
  21. #import "AppDelegate.h"
  22. #import <RCCloudPhoneSDK/RCAudioPlayer.h>
  23. #import <RCCloudPhoneSDK/RCRecordManager.h>
  24. //#import <RCCloudPhoneSDK/RCCommandChannel.h>
  25. #import <RCCloudPhoneSDK/RCLiveSteamManager.h>
  26. #import "ShortcutManager.h"
  27. #import "RCCommandHelp.h"
  28. #import "UIView+View.h"
  29. #import "SafeForKey.h"
  30. #import "CloudPhoneAPI.h"
  31. #import "MySetViewController.h"
  32. #import "PhoneTimeInfoModel.h"
  33. #import "connectDeviceManager.h"
  34. #import "commandSendCheckModel.h"
  35. #import "playerSetView.h"
  36. typedef enum : NSUInteger {
  37. BITRATE_EXTREME_SPEED = 2,//极速
  38. // BITRATE_HIGH_SPEED = 843000,//高速
  39. BITRATE_AUTO = 6,//自动
  40. // BITRATE_STANDARD_CLEARING = 2,//wwan标清
  41. // BITRATE_HD = 3,//wwan高清
  42. BITRATE_WIFI_STANDARD_CLEARING = 3, //wifi标清
  43. BITRATE_WIFI_HD = 4, //wifi高清
  44. } BITRATE_TYPE;
  45. //当手机采用wifi时不做码率调整,当手机采用流量时,高清采用2052000,标清采用1652000调整(默认)
  46. ///*测试*/
  47. //#include "socket.h"
  48. CGFloat w_h_rate;
  49. PlayerViewController * _Nullable mySelf;
  50. BOOL isLan;
  51. //PlayerViewController *mySelf;
  52. int portConnect;
  53. NSString *ipConnect;
  54. @interface PlayerViewController ()
  55. <PlayerViewDelegate,
  56. RecoderManagerDelegate,
  57. AudioRecoderMamagerDelegate,
  58. RCLiveSteamManagerDelegate,
  59. UITextFieldDelegate,
  60. ComontAlretViewControllerDelegate,
  61. UIDocumentPickerDelegate>
  62. {
  63. // __block int _ihandle;
  64. int rate;/*0:极速 1:高速 2:高清 3:标清 4:d自动*/
  65. NSUInteger rateForAuto;
  66. BOOL showWattingViewImageView;
  67. RCPCMPlayer *pcmPlayer;
  68. NSInteger gpsOnOff;
  69. BOOL canRate;
  70. CIContext *videoContext;
  71. NSInteger reConnectAccount;/*记录重连次数*/
  72. NSInteger preTryAginTime;//上次重连时间戳
  73. ConnectState RCLiveSteamlinkState;//视频流的链接状态
  74. BOOL isInPan;/*标记是否有手指在活动*/
  75. int socketFortest;
  76. UIView *loadingWithTipsView;
  77. NSInteger netWorkStates;/*0很差 1较差 2流畅*/
  78. BOOL outputVolumeKVO;/*标记声音监听通知*/
  79. NSDate *rootSetTime;
  80. UITextField *hidenTextField;
  81. NSString *hidenTextFieldOldStr;
  82. PhoneTimeInfoDataModel *phoneTimeInfoDataModel;
  83. /*弹窗提示链接失败 网络或者云机*/
  84. ComontAlretViewController *linkFailAlretVC;
  85. ComontAlretType2ViewController * linkFailAlretType2VC;
  86. NSTimer *forceStartTimer;//请知重启timer
  87. int preIFrameNum;
  88. }
  89. @property (nonatomic, strong, nullable) RCVideoRecoderManager *recoderManager;
  90. @property (nonatomic, strong, nullable) RCAudioRecoderMamager *audioRecoderMamager;
  91. //需不需要显示音量条
  92. @property (nonatomic, assign) BOOL isNeedShowVoiceBar;
  93. //切换云手机 保存切换过的云手机数组, 返回的时刷新对应的云机websorket封面
  94. @property (nonatomic, strong) NSMutableArray *switchCloudPhoneArray;
  95. @property (nonatomic, copy) NSString *screenShotFileName;
  96. @property (nonatomic, copy) NSTimer *timer; // 定时器-控制按钮
  97. /**30s后 渲染时间戳无更新 自动断开链接*/
  98. @property (nonatomic, assign) NSInteger concentTime; // 拉流数据 渲染更新时间戳
  99. /**定时器计数*/
  100. @property (nonatomic, assign) NSInteger currentTime;
  101. /**定时器计数*/
  102. @property (nonatomic, assign) NSInteger webSocketTime;
  103. /**定时器计数*/
  104. @property (nonatomic, assign) NSInteger offlineNotTime;
  105. /**定时器计数 任务检测*/
  106. @property (nonatomic, assign) NSInteger webSocketTaskTime;
  107. /**是否是收入进入云手机*/
  108. @property (nonatomic, assign) BOOL isFirstEnterPhone;
  109. @property (nonatomic, strong) NSTimer *checkThridConnectTimer; // 检查瑞云那边连接完成没
  110. @property (nonatomic, assign) NSInteger checkThridConnectNum;//
  111. //音频和图片是否可以刷新
  112. @property (nonatomic, assign) BOOL canShowImgAndVoiceType;
  113. @property (nonatomic, copy) NSString*LogoutTimerStr;//单点登出时间
  114. @property (nonatomic, assign) BOOL needShowLogoutDelayType;//是否是延时显示单点登出
  115. @property (nonatomic, assign) BOOL isRebootIngType;//是否为重启中
  116. @property (nonatomic, assign) BOOL isResetingType;//是否为恢复出厂中
  117. @end
  118. @implementation PlayerViewController
  119. @synthesize internetVideoPort;
  120. @synthesize ip;
  121. @synthesize canControl;
  122. @synthesize deviceId;
  123. @synthesize vpnStatus;
  124. @synthesize internetHttp;
  125. @synthesize rbdNotification;
  126. - (void)viewDidLoad {
  127. [super viewDidLoad];
  128. if (@available(iOS 11.0, *)) { // 兼容低版本ios
  129. [self setNeedsUpdateOfHomeIndicatorAutoHidden];
  130. }
  131. canControl = YES;
  132. _canShowImgAndVoiceType = NO;
  133. portConnect = [self->internetVideoPort intValue];
  134. ipConnect = self->ip;
  135. isLan = NO;
  136. _didRecyclResource = NO;
  137. globalBlock(^{
  138. // 初始化成功后连接
  139. @synchronized (self) {
  140. if ([self initVideoServer])
  141. {
  142. [self connectVideoServer];
  143. }
  144. }
  145. });
  146. outputVolumeKVO = NO;
  147. rbdNotification = 0;
  148. _offlineNotTime = 0;
  149. preIFrameNum = 0;
  150. // 初始化
  151. self.isNeedRecyclResource = YES;
  152. self.isFirstEnterPhone = YES;
  153. [self initData];
  154. self.toolBar.hidden = YES;
  155. self.navigationBar.hidden = YES;
  156. [self drawView];
  157. [self showNewIndicator];
  158. mySelf = self;
  159. haveBack = NO;
  160. [self startCheckThridRuiYunTimerFun];
  161. }
  162. #pragma mark 启动检测瑞云的timer
  163. - (void)startCheckThridRuiYunTimerFun
  164. {
  165. if(_checkThridConnectTimer ){
  166. [_checkThridConnectTimer invalidate];
  167. }
  168. _checkThridConnectNum = 0;
  169. _checkThridConnectTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(checkThridRuiYunFun) userInfo:nil repeats:YES];
  170. [[NSRunLoop currentRunLoop] addTimer:_checkThridConnectTimer forMode:NSRunLoopCommonModes];
  171. }
  172. #pragma mark 检测融云链接是否完成
  173. - (void)checkThridRuiYunFun{
  174. _checkThridConnectNum += 1;
  175. if(_checkThridConnectNum >= 30 && [[connectDeviceManager shareInstance] curConnectDeviceState] <= 3 ){
  176. [[addLogObject shareInstance] gotoAddLogFun];
  177. [self showNetErrorAlertFun:11];
  178. _checkThridConnectNum = 0;
  179. // [_checkThridConnectTimer invalidate];
  180. // return;
  181. }
  182. HLog(@"瑞云连接状态:%d",[[connectDeviceManager shareInstance] curConnectDeviceState]);
  183. //第一次进 先输入密码才能连接
  184. //if([connectDeviceManager shareInstance].isFirstInputPwdDone){
  185. if([connectDeviceManager shareInstance].isPingOk
  186. && [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi){
  187. ip = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.ip;
  188. internetVideoPort = @"9100";
  189. [self didCanConnectServerFun];
  190. }
  191. else{
  192. if([[connectDeviceManager shareInstance] curConnectDeviceState] == DeviceConnectDeciceOk){
  193. ip = ruiyunlinkIp;
  194. internetVideoPort = [[connectDeviceManager shareInstance] tcpPortStr];
  195. [self didCanConnectServerFun];
  196. }
  197. }
  198. //}
  199. }
  200. #pragma mark 走局域网或者瑞云SDK链接OK
  201. - (void)didCanConnectServerFun{
  202. [_checkThridConnectTimer invalidate];
  203. //做版本检测
  204. [self checkVersionFun];
  205. [self connectVideoServer];
  206. }
  207. - (void)initData
  208. {
  209. isInPan = NO;
  210. reConnectAccount = 0;
  211. netWorkStates = 0;
  212. canRate = NO;
  213. rate = -1;
  214. isLan = NO;
  215. // _ihandle = -1;
  216. [hidenTextField resignFirstResponder];
  217. hidenTextField.text = @"";
  218. hidenTextFieldOldStr = nil;
  219. }
  220. - (void)viewWillAppear:(BOOL)animated {
  221. [super viewWillAppear:animated];
  222. // 屏幕常亮
  223. [UIApplication sharedApplication].idleTimerDisabled = YES;
  224. [[UIApplication sharedApplication] setStatusBarHidden:YES];
  225. [self setTimerCountDown];
  226. [self setShowImgAndVoiceTypeFun:YES];
  227. }
  228. - (void)viewDidLayoutSubviews {
  229. [super viewDidLayoutSubviews];
  230. if (mPlayerView.controlBtn) {
  231. [self.navigationController.view bringSubviewToFront:mPlayerView.controlBtn];
  232. }
  233. }
  234. - (void)viewWillDisappear:(BOOL)animated {
  235. //保存最后一帧
  236. [self saveLastImageFun];
  237. // 退出控制器 回收资源
  238. [self recyclResource];
  239. //AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
  240. // app.allowAutoRotate = NO;
  241. [super viewWillDisappear:animated];
  242. [self setShowImgAndVoiceTypeFun:NO];
  243. }
  244. // 退出控制器 回收资源
  245. - (void)recyclResource {
  246. // 移除Alert
  247. if (self.presentedViewController) {
  248. [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
  249. }
  250. [mPlayerView.controlBtn removeFromSuperview];
  251. if ([[[UIApplication sharedApplication] keyWindow] viewWithTag:1235]) {
  252. [[[[UIApplication sharedApplication] keyWindow] viewWithTag:1235] removeFromSuperview];
  253. }
  254. [self enablePanRightBack];
  255. // 屏幕常亮
  256. [UIApplication sharedApplication].idleTimerDisabled = NO;
  257. [[UIApplication sharedApplication] setStatusBarHidden:NO];
  258. // 播放器内部页面跳转-不能回收的资源
  259. if (self.isNeedRecyclResource) {
  260. self.didRecyclResource = YES;
  261. // 销毁定时器
  262. [self cancelTimer];
  263. //globalBlock(^{
  264. [self.liveStreamManager rc_release];
  265. //});
  266. if (USEAAC)
  267. {
  268. if (aacPlayer)
  269. {
  270. [aacPlayer stop];
  271. aacPlayer = nil;
  272. }
  273. }
  274. else
  275. {
  276. if (pcmPlayer)
  277. {
  278. [pcmPlayer stop];
  279. pcmPlayer = nil;
  280. }
  281. }
  282. [self toStopRecoder];
  283. [self toStopAudioRecoder];
  284. [self removeNSNotification];
  285. if(forceStartTimer){
  286. [forceStartTimer invalidate];
  287. forceStartTimer = nil;
  288. }
  289. if(_checkThridConnectTimer){
  290. [_checkThridConnectTimer invalidate];
  291. _checkThridConnectTimer = nil;
  292. }
  293. }
  294. }
  295. - (void)viewDidAppear:(BOOL)animated
  296. {
  297. [super viewDidAppear:animated];
  298. AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
  299. // app.allowAutoRotate = YES;
  300. [[UIApplication sharedApplication] setStatusBarHidden:YES];
  301. [self noEnablePanRightBack];
  302. [self.navigationController.view addSubview:mPlayerView.controlBtn];
  303. [self.navigationController.view bringSubviewToFront:mPlayerView.controlBtn];
  304. if (self.isNeedRecyclResource) {
  305. self.liveStreamManager = [[RCLiveSteamManager alloc] init];
  306. self.liveStreamManager.delegate = self;
  307. portConnect = [internetVideoPort intValue];
  308. ipConnect = ip;
  309. isLan = NO;
  310. globalBlock(^{
  311. // 初始化成功后连接
  312. @synchronized (self) {
  313. if ([self initVideoServer])
  314. {
  315. [self connectVideoServer];
  316. }
  317. }
  318. });
  319. [self addNSNotification];
  320. }
  321. self.isNeedRecyclResource = YES;
  322. //test code
  323. //[self showInsertPopViewFun:@"222"];
  324. //[self showSecretkeyFun];
  325. BOOL isNeedShowSecret = [HWDataManager getBoolWithKey:Const_need_show_Secret_key];
  326. if(isNeedShowSecret){
  327. [self showSecretkeyFun];
  328. }
  329. }
  330. - (void)keepWebSocketOKFun
  331. {
  332. self.webSocketTime = 0;
  333. }
  334. - (void)keyboardFeedbackBeanFun
  335. {
  336. [self->hidenTextField becomeFirstResponder];
  337. // [self->hidenTextField setText:@"1234"];
  338. [self->hidenTextField setEnabled:YES];
  339. }
  340. - (void)textDidChange:(UITextField *)textField{
  341. if (textField.markedTextRange == nil) {
  342. if(!textField.text){
  343. return;
  344. }
  345. /*新内容 完全包含前面的内容 就是删除*/
  346. NSRange newInOld = [hidenTextFieldOldStr rangeOfString:textField.text];
  347. if (newInOld.location == 0 && newInOld.length == textField.text.length){/*删除*/
  348. NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
  349. //[self.businessCommandChannelManager rc_sendData:dataStr];
  350. /*删除以后在输入框前面新增一个字符*/
  351. NSString *tempStr = textField.text;
  352. if (tempStr.length > 0){
  353. }else{
  354. tempStr = @" ";
  355. }
  356. textField.text = tempStr;
  357. }else{
  358. if(!hidenTextFieldOldStr){
  359. return;
  360. }
  361. /*新增*/
  362. NSRange oldInNew = [textField.text rangeOfString:hidenTextFieldOldStr];
  363. if (oldInNew.location == 0 && oldInNew.length == hidenTextFieldOldStr.length){/*新增*/
  364. NSString *addStr = [textField.text substringWithRange:(NSMakeRange(hidenTextFieldOldStr.length, textField.text.length - hidenTextFieldOldStr.length))];
  365. NSLog(@"键盘透传--@@@@新增内容:%@",addStr);
  366. NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:addStr];
  367. //[self.businessCommandChannelManager rc_sendData:dataStr];
  368. }else{/*部分覆盖*/
  369. /*覆盖分为两部分 1、覆盖的内容更长 2、覆盖的内容更短*/
  370. /*删除不同的部分 加上变化的部分*/
  371. /*后面不同内容的长度*/
  372. NSInteger sameLength = 0;
  373. if (hidenTextFieldOldStr.length < textField.text.length){
  374. sameLength = [self sameStrLengthSmallStr:hidenTextFieldOldStr longStr:textField.text];
  375. }else{
  376. sameLength = [self sameStrLengthSmallStr:textField.text longStr:hidenTextFieldOldStr];
  377. }
  378. /*需要删除的长度*/
  379. NSInteger needDeleteLength = hidenTextFieldOldStr.length - sameLength;
  380. for (NSInteger nFori = 0; nFori < needDeleteLength; nFori++) {
  381. NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
  382. //[self.businessCommandChannelManager rc_sendData:dataStr];
  383. }
  384. /*需要增加的内容*/
  385. NSInteger needLength = textField.text.length - sameLength;
  386. NSString *addStr = [textField.text substringWithRange:(NSMakeRange(sameLength, needLength))];
  387. NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:addStr];
  388. //[self.businessCommandChannelManager rc_sendData:dataStr];
  389. }
  390. }
  391. hidenTextFieldOldStr = textField.text;
  392. }
  393. }
  394. - (NSInteger)sameStrLengthSmallStr:(NSString *)litStr longStr:(NSString *)longStr{
  395. NSInteger samenumber = 0;
  396. for (NSInteger nFori = 1; nFori < litStr.length+1; nFori++) {
  397. NSString *temp0 = [litStr substringToIndex:nFori];
  398. NSString *temp1 = [longStr substringToIndex:nFori];
  399. if (![temp0 isEqualToString:temp1]){
  400. break;
  401. }
  402. samenumber++;
  403. }
  404. return samenumber;
  405. }
  406. #pragma mark - UI相关
  407. - (void)drawView
  408. {
  409. hidenTextField = [[UITextField alloc] initWithFrame:(CGRectMake(0, 0, 0, 0))];
  410. hidenTextField.delegate = self;
  411. [hidenTextField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
  412. [self.view addSubview:hidenTextField];
  413. [self.view setBackgroundColor:[UIColor whiteColor]];
  414. mPlayerView = [[PlayerView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  415. //mPlayerView.buyVipType = self.buyVipType;
  416. [mPlayerView initPoMas_makeWithImageRate:YES isUsageMode:NO];
  417. [mPlayerView setBackgroundColor:[UIColor blackColor]];
  418. mPlayerView.delegate = self;
  419. deviceShareStates = 2;
  420. [self.view addSubview:mPlayerView];
  421. [mPlayerView mas_makeConstraints:^(MASConstraintMaker *make) {
  422. make.left.mas_equalTo(0);
  423. make.right.mas_equalTo(0);
  424. make.top.mas_equalTo(0);
  425. make.bottom.mas_equalTo(0);
  426. }];
  427. [self reSetPlayerViewFloatBtnFrame];
  428. if (isLan)/*直接g或者变为横屏*/
  429. {
  430. [mPlayerView setLanMas_makeWithImageRate:ksharedAppDelegate.couldPhone_W_PHONE/ksharedAppDelegate.couldPhone_H_PHONE isOpenVirtual:YES isUsageMode:NO];
  431. }
  432. else
  433. {
  434. [mPlayerView setPoMas_makeWithImageRate:ksharedAppDelegate.couldPhone_W_PHONE/ksharedAppDelegate.couldPhone_H_PHONE isOpenVirtual:YES isUsageMode:NO];
  435. }
  436. [self readLastImageFun];
  437. }
  438. /**
  439. * @brief 漂浮按钮位置初始化
  440. *
  441. *
  442. */
  443. - (void)reSetPlayerViewFloatBtnFrame
  444. {
  445. // [[[UIApplication sharedApplication] keyWindow] addSubview:mPlayerView.controlBtn];
  446. [self.navigationController.view addSubview:mPlayerView.controlBtn];
  447. [self.navigationController.view bringSubviewToFront:mPlayerView.controlBtn];
  448. NSDictionary *dict = nil;
  449. CGFloat h_w_controlBtn = 60.f;
  450. if (dict)
  451. {
  452. CGFloat pointx = [[dict objectForKey:@"pointx"] floatValue];
  453. CGFloat pointy = [[dict objectForKey:@"pointy"] floatValue];
  454. if (mPlayerView.width > mPlayerView.height){
  455. if (pointx < 30)
  456. {
  457. pointx = 30;
  458. }
  459. else if (pointx > mPlayerView.width - h_w_controlBtn - 10.f)
  460. {
  461. pointx = mPlayerView.width - h_w_controlBtn - 10.f;
  462. }
  463. if (pointy < 10)
  464. {
  465. pointy = 10;
  466. }
  467. else if (pointy > mPlayerView.height - h_w_controlBtn - 10.f)
  468. {
  469. pointy = mPlayerView.height - h_w_controlBtn - 10.f;
  470. }
  471. }else{
  472. if (pointx < 10)
  473. {
  474. pointx = 10;
  475. }
  476. else if (pointx > mPlayerView.width - h_w_controlBtn - 10.f)
  477. {
  478. pointx = mPlayerView.width - h_w_controlBtn - 10.f;
  479. }
  480. if (pointy < 10)
  481. {
  482. pointy = 10;
  483. }
  484. else if (pointy > mPlayerView.height - h_w_controlBtn - 10.f)
  485. {
  486. pointy = mPlayerView.height - h_w_controlBtn - 10.f;
  487. }
  488. }
  489. // BOOL hidden = [[dict objectForKey:@"hidden"] boolValue];
  490. [mPlayerView.controlBtn setFrame:CGRectMake(pointx, pointy, h_w_controlBtn, h_w_controlBtn)];
  491. }
  492. else
  493. {
  494. /*区分横竖屏*/
  495. if (mPlayerView.width > mPlayerView.height){
  496. [mPlayerView.controlBtn setFrame:CGRectMake((mPlayerView.width - h_w_controlBtn)/2.f, mPlayerView.height - h_w_controlBtn - 20.f, h_w_controlBtn, h_w_controlBtn)];
  497. }else{
  498. //默认居右
  499. //[mPlayerView.controlBtn setFrame:CGRectMake(mPlayerView.width - h_w_controlBtn - 20.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
  500. //默认居左
  501. [mPlayerView.controlBtn setFrame:CGRectMake( h_w_controlBtn + 10.f, (SCREEN_H - h_w_controlBtn)/2.f, h_w_controlBtn, h_w_controlBtn)];
  502. }
  503. [mPlayerView.controlBtn setHidden:NO];
  504. }
  505. HLog(@"云手机推流界面 控制按钮中点%@",NSStringFromCGPoint(mPlayerView.controlBtn.center));
  506. }
  507. #pragma mark - 手势权限控制处理
  508. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer
  509. *)gestureRecognizer{
  510. return NO; //YES:允许右滑返回 NO:禁止右滑返回
  511. }
  512. - (void)enablePanRightBack
  513. {
  514. if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  515. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  516. }
  517. if ([self.tabBarController.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  518. self.tabBarController.navigationController.interactivePopGestureRecognizer.enabled = YES;
  519. }
  520. }
  521. - (void)noEnablePanRightBack
  522. {
  523. if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  524. self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  525. }
  526. if ([self.tabBarController.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  527. self.tabBarController.navigationController.interactivePopGestureRecognizer.enabled = NO;
  528. }
  529. }
  530. #pragma mark - RCLiveSteamManagerDelegate
  531. - (void)liveStreamManagerOutPut:(RCLiveSteamManager *)manager didOutPutVideoPixelBuffer:(CVPixelBufferRef)pixelBuffer {
  532. mySelf.concentTime = [iTools getNowTimeStamp];
  533. if(!_canShowImgAndVoiceType){
  534. return;
  535. }
  536. if (!mySelf || mySelf->haveBack) {
  537. return;
  538. }
  539. if (!pixelBuffer) {
  540. return;
  541. }
  542. [mySelf updateAutoRateAndNetWorkStates];//更新网络标识 以及自动码率
  543. if (mySelf&&!(mySelf->haveBack))
  544. {
  545. mySelf->reConnectAccount = 0;
  546. @autoreleasepool {
  547. if (!mySelf)
  548. {
  549. return ;
  550. }
  551. CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pixelBuffer];
  552. // if (mySelf->saveCIImage) {
  553. // mySelf->saveCIImage = nil;
  554. // }
  555. mySelf->saveCIImage = ciImage;
  556. if(!savelastImageFirst && mySelf.isConnectSuccess && ciImage){
  557. savelastImageFirst = YES;
  558. [mySelf saveLastImageFun];
  559. }
  560. if(self->needScreenShotType){
  561. self->needScreenShotType = NO;
  562. [self screenShotToPhoneFun];
  563. }
  564. //尝试修复闪一下 没解决
  565. // if(ciImage){
  566. //
  567. // mainBlock(^{
  568. // if(mySelf->preIFrameNum == 0){
  569. // mySelf->mPlayerView.glkshowImageView.hidden = YES;
  570. // }
  571. // else if(mySelf->preIFrameNum == 30){
  572. // mySelf->mPlayerView.glkshowImageView.hidden = NO;
  573. // }
  574. // });
  575. // preIFrameNum ++;
  576. //
  577. // }
  578. if (!mySelf->videoContext) mySelf->videoContext = [CIContext contextWithOptions:nil];
  579. if (USEOPENGL)
  580. {
  581. if (ciImage)
  582. {
  583. [mySelf showImageOpenglWithCIImage:ciImage];/*使用Opengl渲染*/
  584. mySelf.concentTime = [iTools getNowTimeStamp];
  585. mySelf.isConnectSuccess = YES;
  586. }
  587. }
  588. else
  589. {
  590. if (ciImage)
  591. {
  592. [mySelf showImageUIImageViewWithCIImage:ciImage pixelBufferRef:pixelBuffer];/*使用UIImageView渲染*/
  593. //mySelf.concentTime = [iTools getNowTimeStamp];
  594. mySelf.isConnectSuccess = YES;
  595. }
  596. }
  597. if (mySelf&&!mySelf->haveBack && mySelf->wattingView)
  598. {
  599. mainBlock(^{
  600. [mySelf removeNewIndicator];
  601. });
  602. }
  603. }
  604. }
  605. }
  606. - (void)liveStreamManagerOutPut:(RCLiveSteamManager *)manager didOutPutAudioData:(NSData *)pcmData {
  607. @autoreleasepool {
  608. if(!_canShowImgAndVoiceType){
  609. return;
  610. }
  611. if (mySelf&&!(mySelf->haveBack)){
  612. [mySelf->connectLock lock];
  613. if (!mySelf->pcmPlayer){
  614. mySelf->pcmPlayer = [[RCPCMPlayer alloc] initWithAudioBufferSize:4096 mSampleRate:44100 mChannelsPerFrame:2];
  615. mySelf.isNeedShowVoiceBar = NO;
  616. [mySelf->pcmPlayer start];
  617. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  618. mySelf.isNeedShowVoiceBar = YES;
  619. });
  620. }
  621. if (pcmData){
  622. mySelf.isNeedShowVoiceBar = NO;
  623. [mySelf->pcmPlayer play:pcmData];
  624. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  625. mySelf.isNeedShowVoiceBar = YES;
  626. });
  627. }
  628. [mySelf->connectLock unlock];
  629. }
  630. }
  631. }
  632. - (void)liveStreamManager:(RCLiveSteamManager *)manager connectState:(ConnectState)state {
  633. HLog(@"\n------状态回调---state = %d--", state);
  634. //[[VclCrash sharedInstance] writeContent:[NSString stringWithFormat:@"_connectDisconnect连接返回句柄 = %d--state--=%d-",ihandle,state]];
  635. RCLiveSteamlinkState = state;
  636. switch (state){
  637. case 0:/*连接已释放*/{
  638. }
  639. break;
  640. case 1:/*正在连接*/{
  641. }
  642. break;
  643. case 2:/*连接成功*/{
  644. HLog(@"\n-----_%s------SSSSSSSSSSS连接成功",__FUNCTION__);
  645. if (self.isFirstEnterPhone) {
  646. self.isFirstEnterPhone = NO;
  647. }
  648. //重启后重连 出来的
  649. if(_isRebootIngType && !forceStartTimer){
  650. mainBlock(^{
  651. [[iToast makeText:NSLocalizedString(@"player_link_reboot_suc_Tips",nil)] show];
  652. });
  653. _isRebootIngType = NO;
  654. //[self opencommandChannelManagerrc_openURL];
  655. }
  656. //重启后重连 出来的
  657. if(_isResetingType){
  658. mainBlock(^{
  659. [[iToast makeText:NSLocalizedString(@"my_set_no_Restore_Factory_ok_tips",nil)] show];
  660. });
  661. _isResetingType = NO;
  662. //[self opencommandChannelManagerrc_openURL];
  663. }
  664. // 报链接失败 后面又连接上了
  665. if(linkFailAlretVC){
  666. mainBlock(^{
  667. [self->linkFailAlretVC dismissViewControllerAnimated:YES completion:^{
  668. }];
  669. self->linkFailAlretVC = nil;
  670. });
  671. }
  672. }
  673. break;
  674. case 3:/*正在渲染*/{
  675. }
  676. break;
  677. case 4:/*正在关闭*/{
  678. }
  679. break;
  680. case 5:/*已关闭*/{
  681. }
  682. break;
  683. case 6:{
  684. mainBlock(^{
  685. if(!self.didRecyclResource){
  686. [self showNewIndicator];
  687. [self tryAgain];
  688. }
  689. });
  690. }
  691. break;
  692. case ConnectStateVerifyErr:{
  693. HLog(@"\n------token异常----重新超分-----");
  694. /*鉴权失败 进行超分操作*/
  695. /*先清除当前的token*/
  696. // NSDictionary *dictLogin = [[UseAccountManage shareInstance] getLoginInfo];
  697. // if (dictLogin && [[dictLogin allKeys] containsObject:@"userName"])
  698. // {
  699. // /*判断数据库中有没有对应phoneid*/
  700. // NSString* username = [dictLogin objectForKey:@"userName"];
  701. // NSString * bg_tableName = P2PModelList_bg_tableName(username);
  702. // //先显示本地缓存数据
  703. // NSArray* finfAlls = [PhoneP2PListModel bg_findAll:bg_tableName];
  704. // if (finfAlls && finfAlls.count >0) {
  705. // PhoneP2PListModel *listMod = finfAlls[0];
  706. // for (PhoneP2PModel *p2pModel in listMod.data) {
  707. // if (p2pModel.phoneId == self.deviceModel.phoneId){
  708. // [listMod.data removeObject:p2pModel];
  709. // [listMod bg_cover];
  710. // break;
  711. // }
  712. // }
  713. // }
  714. // }
  715. }
  716. break;
  717. default:
  718. break;
  719. }
  720. }
  721. - (void)openVideForLiveStreamManager:(AVCaptureDevicePosition)position needPost:(BOOL)needPost
  722. {
  723. if (mySelf&&!(mySelf->haveBack))
  724. {
  725. if (mySelf->canControl)
  726. {
  727. [mySelf toStopRecoder];
  728. HLog(@"\n-----打开视频透传 后置摄像头-------");
  729. [mySelf toStartRecoderWithAVCaptureDevicePosition:(position)];
  730. // if (needPost) {
  731. // // 云机摄像头使用上报
  732. // [mySelf postCloudCamera];
  733. // }
  734. }
  735. }
  736. }
  737. - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiveEvent:(EventState)event {
  738. EventState state = event;
  739. if (0 == state)/*横屏*/
  740. {
  741. if (USELOCALKEYBOARD){
  742. isLan = YES;
  743. /*横屏处理*/
  744. [self setDeviceOrientation:(UIDeviceOrientationLandscapeLeft)];
  745. HLog(@"\n---000000--横屏--000000-----");
  746. }else{
  747. /*横屏处理*/
  748. isLan = NO;
  749. [self setDeviceOrientation:(UIDeviceOrientationPortrait)];
  750. HLog(@"\n---000000--横屏--000000-----");
  751. }
  752. mySelf->mPlayerView.isLan = YES;
  753. HLog(@"\n---000000--横屏--000000-----");
  754. }
  755. else if (1 == state)/*竖屏*/
  756. {
  757. isLan = NO;
  758. mySelf->mPlayerView.isLan = NO;
  759. /*横屏处理*/
  760. [self setDeviceOrientation:(UIDeviceOrientationPortrait)];
  761. }
  762. else if (2 == state)/*打开音频透传*/
  763. {
  764. if (mySelf&&!(mySelf->haveBack))
  765. {
  766. if (mySelf->canControl)
  767. {
  768. HLog(@"\n-----打开视频透传-------");
  769. [mySelf toStartAudioRecoder];
  770. }
  771. }
  772. }
  773. else if (3 == state)/*关闭音频透传*/
  774. {
  775. [mySelf toStopAudioRecoder];
  776. }
  777. else if (4 == state)/*打开视频透传*/
  778. {
  779. [self openVideForLiveStreamManager:AVCaptureDevicePositionBack needPost:YES];
  780. }
  781. else if (5 == state)/*关闭视频透传*/
  782. {
  783. [mySelf toStopRecoder];
  784. }
  785. else if (7 == state)/*打开视频透传--前置摄像头*/
  786. {
  787. [self openVideForLiveStreamManager:AVCaptureDevicePositionFront needPost:YES];
  788. }
  789. else if (EventStateTurnOnVideoDontNeedToServer == state)/*打开视频透传*/
  790. {
  791. [self openVideForLiveStreamManager:AVCaptureDevicePositionBack needPost:NO];
  792. }
  793. else if (EventStateTurnOnVideoFrontDontNeedToServer == state)/*打开视频透传--前置摄像头*/
  794. {
  795. [self openVideForLiveStreamManager:AVCaptureDevicePositionFront needPost:NO];
  796. }
  797. else if (EventStateTurnOnVideoDontNeedToServer == state)/*打开视频透传*/
  798. {
  799. [self openVideForLiveStreamManager:AVCaptureDevicePositionBack needPost:NO];
  800. }
  801. else if (EventStateTurnOnVideoFrontDontNeedToServer == state)/*打开视频透传--前置摄像头*/
  802. {
  803. [self openVideForLiveStreamManager:AVCaptureDevicePositionFront needPost:NO];
  804. }
  805. }
  806. - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiveMessage:(NSString *)message {
  807. }
  808. - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiNetEstimator:(NetEstimator)estimator{
  809. }
  810. - (void)liveStreamManager:(RCLiveSteamManager *)manager didReceiveJitterDelay:(int)jitterDelayMs{
  811. HLog(@"延时毫秒:%d",jitterDelayMs)
  812. }
  813. #pragma mark - 视频流回调
  814. void connectStateCallBack (void *client, ConnectState state, void *context)
  815. {
  816. NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:1],@"ihandle",[NSNumber numberWithInt:state],@"state" ,nil];
  817. [[NSNotificationCenter defaultCenter] postNotificationName:NotNameByCONNECT_DISCONNECT object:dict];
  818. }
  819. static int delayVideo = 0;/*当前最高延时*/
  820. static int okdelayVideo = 0;/*当前连续延时较好帧数*/
  821. static int baddelayVideo = 0;/*当前较坏延时帧数个数*/
  822. static int havedelayVideoCount = 0;/*当前帧数个数*/
  823. NSDate *lastVideoTome;/*上一帧数据时间*/
  824. - (void)toStartRecoderWithAVCaptureDevicePosition:(AVCaptureDevicePosition)position
  825. {
  826. if (!self.recoderManager)
  827. {
  828. self.recoderManager = [[RCVideoRecoderManager alloc] initWithAVCaptureDevicePosition:position];
  829. self.recoderManager.delegate = self;
  830. }
  831. if (!self.recoderManager.isRecoding)
  832. {
  833. [self.recoderManager startRecording];
  834. }
  835. }
  836. - (void)toStopRecoder
  837. {
  838. if (self.recoderManager)
  839. {
  840. [self.recoderManager stopRecording];
  841. self.recoderManager = nil;
  842. }
  843. }
  844. - (void)toStartAudioRecoder
  845. {
  846. if (!self.audioRecoderMamager)
  847. {
  848. self.audioRecoderMamager = [[RCAudioRecoderMamager alloc] init];
  849. self.audioRecoderMamager.delegate = self;
  850. }
  851. if (!self.audioRecoderMamager.isRecoding)
  852. {
  853. [self.audioRecoderMamager startRecording];
  854. }
  855. }
  856. - (void)toStopAudioRecoder
  857. {
  858. if (self.audioRecoderMamager)
  859. {
  860. [self.audioRecoderMamager stopRecording];
  861. self.audioRecoderMamager = nil;
  862. }
  863. }
  864. /**
  865. * @brief 请求I帧数据
  866. */
  867. - (void)requestIFrame
  868. {
  869. [self.liveStreamManager rc_requestIDFrame];
  870. }
  871. #pragma mark - 流媒体服务器
  872. // 初始化
  873. - (BOOL)initVideoServer {
  874. return YES;
  875. }
  876. // 连接
  877. - (void)connectVideoServer {
  878. if([connectDeviceManager shareInstance].isPingOk
  879. && [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi){
  880. ip = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.ip;
  881. internetVideoPort = @"9100";
  882. }
  883. else{
  884. ip = ruiyunlinkIp;
  885. internetVideoPort = [[connectDeviceManager shareInstance] tcpPortStr];
  886. }
  887. if(self.didRecyclResource){
  888. [cachesFileManager writeLogsWithMsg:@"connectVideoServer didRecyclResource return"];
  889. return;
  890. }
  891. if (!mySelf || haveBack || !ip || !internetVideoPort){
  892. [cachesFileManager writeLogsWithMsg:@"connectVideoServer mySelf haveBack return"];
  893. return;
  894. }
  895. if (!connectLock)
  896. {
  897. connectLock = [[NSLock alloc] init];
  898. }
  899. [connectLock lock];
  900. delayVideo = 0;
  901. okdelayVideo = 0;
  902. havedelayVideoCount = 0;
  903. RCStateInt result = -1;
  904. NSString *tempIP = ip;
  905. HLog(@"__连接ip__%@_端口__%@",ip,internetVideoPort);
  906. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"link ip %@,port %@",ip,internetVideoPort]];
  907. //
  908. RCCloudPhoneConnectType ConnectType = RCCloudPhoneConnectType_websocket;
  909. RCCloudPhoneVideoQuality VideoQuality = RCCloudPhoneVideoQuality_Default;//RCCloudPhoneVideoQuality_High;
  910. if([connectDeviceManager shareInstance].isPingOk
  911. && [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi)
  912. {
  913. ConnectType = RCCloudPhoneConnectType_udp;
  914. VideoQuality = RCCloudPhoneVideoQuality_Default;
  915. }
  916. result = [self.liveStreamManager rc_openWithIp:ip
  917. port:internetVideoPort.intValue
  918. connectType:ConnectType
  919. videoQuality:VideoQuality
  920. verify:@"123456"
  921. streamAESKey:nil];
  922. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"result %ld",(long)result]];
  923. if ([tempIP isEqualToString:ip])
  924. {
  925. if (result < 0)
  926. {
  927. if(result == -5){
  928. [[connectDeviceManager shareInstance] recreateHttpServiceFun];
  929. }
  930. [self tryAgain];
  931. }
  932. else if (result == 12)
  933. {
  934. //[[iToast makeText:@"画面异常,请重新进入"] show];
  935. HLog(@"画面异常,请重新进入");
  936. }
  937. }
  938. HLog(@"______连接____ip = %@ port = %@",ip,internetVideoPort);
  939. HLog(@"__________连接1111111__________");
  940. HLog(@"__________连接成功__________");
  941. lastVideoTome = [NSDate date];
  942. NSString *dataStr = [RCCommandHelp commandResolution500WithType:(NSUInteger)BITRATE_WIFI_HD];
  943. [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
  944. // // 20210305 因为安卓做了分辨率适应 而iOS不需要 所以现在指定接收码率 这个就不用修改对应触摸点的范围比例了 W_PHONE H_PHONE
  945. // // 发送数据
  946. // if ([deviceModel.buyVipType isEqualToString:CloudPhoneTypeWuJiPro]) {
  947. // NSString *commondStr = @"{\"data\":{\"height\":1920,\"width\":1080},\"type\":\"setPhoneSize\"}";
  948. // [self send_data:commondStr];
  949. // }
  950. //
  951. // //记录推流开始时间
  952. // NSString *connectedDataStr = [RCCommandHelp commandConnectedWithDeviceId:deviceId];
  953. // [self send_data:connectedDataStr];
  954. [connectLock unlock];
  955. }
  956. // 断开连接
  957. - (void)disconnectVideoServer {
  958. NSString *commondStr = [RCCommandHelp toStopControllerDevice500];
  959. [self send_data:commondStr];
  960. HLog(@"\n-----...commondStr = %@....",commondStr);
  961. [self.liveStreamManager rc_disconnect];
  962. if (pcmPlayer)
  963. {
  964. [pcmPlayer stop];
  965. pcmPlayer = nil;
  966. }
  967. }
  968. - (void)send_data:(NSString *)dataStr
  969. {
  970. if (canControl)
  971. {
  972. //KyoLog(@"\n-commandChannelManager---%ld--%@",self.commandChannelManager.rc_socketStatus,dataStr);
  973. [[webSocketManager shareInstance] send_data:dataStr];
  974. }
  975. }
  976. #pragma mark - PlayerViewDelegate---下方虚拟按键
  977. - (void)mueBtnBePressed:(id)sender
  978. {
  979. HLog(@"__________%s__________",__func__);
  980. NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:187];
  981. HLog(@"\n-----...dataStr = %@....",dataStr);
  982. [self send_data:dataStr];
  983. }
  984. - (void)homeBtnBePressed:(id)sender
  985. {
  986. HLog(@"__________%s__________",__func__);
  987. NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:3];
  988. HLog(@"\n-----...dataStr = %@....",dataStr);
  989. [self send_data:dataStr];
  990. }
  991. - (void)backBtnBePressed:(id)sender
  992. {
  993. HLog(@"__________%s__________",__func__);
  994. NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:4];
  995. HLog(@"\n-----...dataStr = %@....",dataStr);
  996. [self send_data:dataStr];
  997. }
  998. - (void)useInfoBtnBePressed:(id)sender
  999. {
  1000. HLog(@"云手机推流界面 控制按钮点击手势开始");
  1001. [[NSNotificationCenter defaultCenter] postNotificationName:PlayerViewControlBtnTouchBeganNotification object:nil userInfo:nil];
  1002. HLog(@"云手机推流界面 控制按钮点击手势结束");
  1003. [[NSNotificationCenter defaultCenter] postNotificationName:PlayerViewControlBtnTouchEndNotification object:nil userInfo:nil];
  1004. // [[UIApplication sharedApplication] setStatusBarHidden:NO];
  1005. // MySetViewController *nextVC = [[MySetViewController alloc] init];
  1006. // //nextVC.whetherPhoneStatus = phoneTimeInfoDataModel.data.whetherPhoneStatus;
  1007. // [self.navigationController pushViewController:nextVC animated:YES];
  1008. // self.isNeedRecyclResource = NO;
  1009. playerSetView *nextVC = [[playerSetView alloc] init];
  1010. [ksharedAppDelegate.window addSubview:nextVC];
  1011. //[self.view insertSubview:nextVC atIndex:0];
  1012. [nextVC mas_makeConstraints:^(MASConstraintMaker *make) {
  1013. make.left.mas_equalTo(0);
  1014. make.right.mas_equalTo(0);
  1015. make.top.mas_equalTo(0.f);
  1016. make.bottom.mas_equalTo(0.f);
  1017. }];
  1018. KWeakSelf
  1019. nextVC.didClickButtonFun = ^(NSInteger tag) {
  1020. switch (tag) {
  1021. case 10:
  1022. {//截图
  1023. self->needScreenShotType = YES;
  1024. }
  1025. break;
  1026. #pragma mark 重启盒子
  1027. case 11:
  1028. {
  1029. [weakSelf didClickRestartFun];
  1030. }
  1031. break;
  1032. case 12:
  1033. {//退出云机
  1034. [weakSelf exitCloudPhoneFun];
  1035. }
  1036. break;
  1037. case 100:
  1038. {
  1039. BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  1040. if(fullscreenType){
  1041. [weakSelf showOpenTVP2PFun];
  1042. }
  1043. else{
  1044. [weakSelf openTvShowFun];
  1045. }
  1046. }
  1047. break;
  1048. case 101:
  1049. {
  1050. self->mPlayerView.controlBtn.userInteractionEnabled = NO;
  1051. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1052. self->mPlayerView.controlBtn.userInteractionEnabled = YES;
  1053. });
  1054. [weakSelf showCloseTVP2PFun];
  1055. }
  1056. break;
  1057. default:
  1058. break;
  1059. }
  1060. };
  1061. //#pragma mark 重启盒子
  1062. // //{"type":"reboot"}
  1063. // nextVC.needToReboot = ^{
  1064. // [weakSelf needToRebootFun];
  1065. // };
  1066. //
  1067. //#pragma mark TV投屏
  1068. // nextVC.needToTVP2P = ^{
  1069. // NSString *commondStr = @"{\"type\":\"wakeupTV\"}";
  1070. // [weakSelf send_data:commondStr];
  1071. // };
  1072. //#pragma mark 关闭TV投屏
  1073. // nextVC.closeTVP2P = ^{
  1074. // NSString *commondStr = @"{\"type\":\"TvOff\"}";
  1075. // [weakSelf send_data:commondStr];
  1076. // };
  1077. //
  1078. //#pragma mark 恢复出厂盒子
  1079. // nextVC.needToReset = ^{
  1080. // [weakSelf needToResetFun];
  1081. // };
  1082. //
  1083. //#pragma mark 恢复出厂盒子 ok
  1084. // nextVC.needToResetAndOk = ^{
  1085. // [weakSelf tryAgainInLinkFailFun];
  1086. // [weakSelf startCheckThridRuiYunTimerFun];
  1087. // };
  1088. //
  1089. //#pragma mark 获取云机版本信息
  1090. // nextVC.getSysInfo = ^{
  1091. // NSString *commondStr = @"{\"type\":\"getSysInfo\"}";
  1092. // [weakSelf send_data:commondStr];
  1093. // };
  1094. //#pragma mark 获取TV投屏状态
  1095. // nextVC.getTvStatus = ^{
  1096. // NSString *commondStr = @"{\"type\":\"TvStatus\"}";
  1097. // [weakSelf send_data:commondStr];
  1098. // };
  1099. }
  1100. #pragma mark 退出云机
  1101. - (void)exitCloudPhoneFun
  1102. {
  1103. [self.navigationController popViewControllerAnimated:YES];
  1104. }
  1105. #pragma mark 显示关闭投屏提示语
  1106. - (void)showOpenTVP2PFun{
  1107. /*弹窗提示TV投屏*/
  1108. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  1109. msg:NSLocalizedString(@"cloudPhone_fullscreen_tvshow_tip",nil)
  1110. imageStr:nil
  1111. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  1112. okTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil) isOkBtnHighlight:YES
  1113. didClickOk:^{
  1114. [self openTvShowFun];
  1115. //关闭全屏屏
  1116. [HWDataManager setBoolWithKey:Consn_player_full_screen_show value:NO];
  1117. [[NSNotificationCenter defaultCenter] postNotificationName:setPlayerFullScreenNotification object:nil];
  1118. } didClickCancel:^{
  1119. }];
  1120. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  1121. [self presentViewController:nextVC animated:YES completion:^{
  1122. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  1123. }];
  1124. }
  1125. #pragma mark 开始投屏
  1126. - (void)openTvShowFun
  1127. {
  1128. self->mPlayerView.controlBtn.userInteractionEnabled = NO;
  1129. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1130. self->mPlayerView.controlBtn.userInteractionEnabled = YES;
  1131. });
  1132. [[webSocketManager shareInstance] onTvFun];
  1133. [[iToast makeText:NSLocalizedString(@"cloudPhone_TV_show_tip",nil)] show];
  1134. }
  1135. #pragma mark 显示关闭投屏提示语
  1136. - (void)showCloseTVP2PFun{
  1137. /*弹窗提示TV投屏*/
  1138. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_close_TV_p2p_tip",nil)
  1139. msg:nil
  1140. imageStr:nil
  1141. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  1142. okTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil) isOkBtnHighlight:YES
  1143. didClickOk:^{
  1144. [self gotoCloseTVP2PFun];
  1145. } didClickCancel:^{
  1146. //HLog(@"2222");
  1147. }];
  1148. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  1149. [self presentViewController:nextVC animated:YES completion:^{
  1150. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  1151. }];
  1152. }
  1153. #pragma mark 确认开始TV投屏
  1154. -(void)gotoCloseTVP2PFun
  1155. {
  1156. [[webSocketManager shareInstance] offTvFun];
  1157. }
  1158. - (void)needToRebootFun
  1159. {
  1160. NSString *commondStr = @"{\"type\":\"reboot\"}";
  1161. [self send_data:commondStr];
  1162. [self startForceStartTimerFun];
  1163. //最后一帧 没显示正在重启问题
  1164. _canShowImgAndVoiceType = YES;
  1165. _isRebootIngType = YES;
  1166. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1167. // [self reconnectDevice];
  1168. // });
  1169. }
  1170. #pragma mark 点击了重启云机
  1171. - (void)didClickRestartFun
  1172. {
  1173. KWeakSelf
  1174. /*弹窗提示重启*/
  1175. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_restart_phone_tips",nil)
  1176. msg:nil
  1177. imageStr:nil
  1178. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  1179. okTitle:NSLocalizedString(@"my_set_no_restart_phone_btn_ok",nil) isOkBtnHighlight:NO
  1180. didClickOk:^{
  1181. [weakSelf needToRebootFun];
  1182. //提示语
  1183. [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  1184. } didClickCancel:^{
  1185. }];
  1186. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  1187. [self presentViewController:nextVC animated:YES completion:^{
  1188. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  1189. }];
  1190. }
  1191. - (void)needToResetFun
  1192. {
  1193. NSString *commondStr = @"{\"type\":\"reset\"}";
  1194. [self send_data:commondStr];
  1195. //最后一帧 没显示正在重启问题
  1196. //self->_canShowImgAndVoiceType = YES;
  1197. _isResetingType = YES;
  1198. //添加到任务监听
  1199. //[self addCommandSendTaskFunWithType:@"reset" WithCommandStr:commondStr];
  1200. }
  1201. #pragma mark 启动timer 秒后检查是否软件重启成功
  1202. - (void)startForceStartTimerFun
  1203. {
  1204. if(forceStartTimer){
  1205. [forceStartTimer invalidate];
  1206. forceStartTimer = nil;
  1207. }
  1208. forceStartTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(gotoUpdateForceStartFun) userInfo:nil repeats:NO];
  1209. [[NSRunLoop currentRunLoop] addTimer:forceStartTimer forMode:NSRunLoopCommonModes];
  1210. }
  1211. - (void)gotoUpdateForceStartFun
  1212. {
  1213. [self updateForceStartFun];
  1214. KWeakSelf
  1215. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1216. [weakSelf reconnectDevice];
  1217. [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
  1218. });
  1219. }
  1220. #pragma mark 单点登录被挤下线弹框
  1221. - (void)LogoutByOtherFun
  1222. {
  1223. [self disconnectVideoServer];
  1224. _canShowImgAndVoiceType = NO;
  1225. //yyyy-MM-dd HH:mm:ss
  1226. NSString*dateStr = [iTools getNowTimeString2];
  1227. if(dateStr && dateStr.length == 19){
  1228. dateStr = [dateStr substringWithRange:NSMakeRange(11, 5)];
  1229. }
  1230. if(!_needShowLogoutDelayType){
  1231. _LogoutTimerStr = [[NSString alloc] initWithFormat:@"%@%@%@",NSLocalizedString(@"single_sign_on_Tips_one",nil),dateStr,NSLocalizedString(@"single_sign_on_Tips_two",nil)];
  1232. }
  1233. if(_isPwdVCShow){
  1234. _needShowLogoutDelayType = YES;
  1235. return;
  1236. }
  1237. _needShowLogoutDelayType = NO;
  1238. NSString * loginAgainStr = NSLocalizedString(@"single_sign_on_login_again",nil);
  1239. BOOL isOkBtnHighlight = YES;
  1240. if(![connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode){
  1241. loginAgainStr = @"";
  1242. isOkBtnHighlight = NO;
  1243. }
  1244. /*弹窗提示重启*/
  1245. KWeakSelf
  1246. logoutAlertVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"single_sign_on_Tips_logout",nil)
  1247. msg:_LogoutTimerStr
  1248. imageStr:nil
  1249. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  1250. okTitle:loginAgainStr isOkBtnHighlight:isOkBtnHighlight
  1251. didClickOk:^{
  1252. [weakSelf tryAgain];
  1253. [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
  1254. } didClickCancel:^{
  1255. }];
  1256. logoutAlertVC.modalPresentationStyle = UIModalPresentationCustom;
  1257. logoutAlertVC.delegate = self;
  1258. [[iTools appRootViewController] presentViewController:logoutAlertVC animated:YES completion:^{
  1259. self->logoutAlertVC.view.superview.backgroundColor = [UIColor clearColor];
  1260. }];
  1261. _isLoginAgainType = YES;
  1262. }
  1263. #pragma mark 设置是否可以播放音频和视频
  1264. -(void)setShowPwdVCTypeFun
  1265. {
  1266. _isPwdVCShow = YES;
  1267. }
  1268. -(void)setShowImgAndVoiceTypeFun
  1269. {
  1270. _isPwdVCShow = NO;
  1271. if(logoutAlertVC){
  1272. return;
  1273. }
  1274. [self setShowImgAndVoiceTypeFun:YES];
  1275. if(_needShowLogoutDelayType){
  1276. [self LogoutByOtherFun];
  1277. }
  1278. }
  1279. #pragma mark 判断是否为密码界面登 函数意思写反了 ~~~~
  1280. - (BOOL)isPlayerViewIsTopVCFun
  1281. {
  1282. UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  1283. if(_isPwdVCShow || ![topVc isKindOfClass:[PlayerViewController class]]){
  1284. return YES;
  1285. }
  1286. return NO;
  1287. }
  1288. -(void)setShowImgAndVoiceTypeFun:(bool)isCan
  1289. {
  1290. if(isCan){//判断当前是否为最前面 才能播放
  1291. if(self->logoutAlertVC){
  1292. return;
  1293. }
  1294. if(_isLoginAgainType ){
  1295. [self tryAgain];
  1296. //[self fristConnectNeedGiveAMsgFun];
  1297. }
  1298. if([self isPlayerViewIsTopVCFun]){
  1299. return;
  1300. }
  1301. _canShowImgAndVoiceType = isCan;
  1302. }
  1303. else{
  1304. _canShowImgAndVoiceType = isCan;
  1305. }
  1306. }
  1307. #pragma mark - 显示秘钥 后续忘记密码要
  1308. -(void)showSecretkeyFun
  1309. {
  1310. // V1.4这个版本把密钥弹框去掉 军义20240537 下的需求 防盗
  1311. return;
  1312. mPlayerView.controlBtn.hidden = YES;
  1313. playerShowSecretkeyView *view = [[playerShowSecretkeyView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  1314. [self.view addSubview:view];
  1315. [self.view bringSubviewToFront:view];
  1316. KWeakSelf
  1317. view.didCloseSecretKeyViewTip = ^{
  1318. [HWDataManager setBoolWithKey:Const_need_show_Secret_key value:NO];
  1319. self->mPlayerView.controlBtn.hidden = NO;
  1320. [weakSelf showControlBtnTipFun];
  1321. };
  1322. view.didCopySecretKeyViewTip = ^{
  1323. [weakSelf updateCopydata];
  1324. };
  1325. }
  1326. #pragma mark 显示首次浮标引导操作提示
  1327. - (void)showControlBtnTipFun{
  1328. BOOL didShowControlBtnTip = [HWDataManager getBoolWithKey:Const_did_Show_playView_controlBtn_Tip];
  1329. if(!didShowControlBtnTip && !_PlayerControlButTipV){
  1330. mPlayerView.controlBtn.hidden = YES;
  1331. _PlayerControlButTipV = [[PlayerControlButTipView alloc] init];
  1332. _PlayerControlButTipV.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
  1333. [self.view addSubview:_PlayerControlButTipV];
  1334. [self.view bringSubviewToFront:_PlayerControlButTipV];
  1335. [_PlayerControlButTipV mas_makeConstraints:^(MASConstraintMaker *make) {
  1336. make.right.mas_equalTo(0);
  1337. make.top.mas_equalTo(0.f);
  1338. make.left.mas_equalTo(0.f);
  1339. make.bottom.mas_equalTo(0.f);
  1340. }];
  1341. KWeakSelf
  1342. _PlayerControlButTipV.didKnowPlayerControlButTip = ^{
  1343. [weakSelf setMPlayerViewControlBtnHiddenBy:NO];
  1344. };
  1345. }
  1346. }
  1347. - (void)setMPlayerViewControlBtnHiddenBy:(BOOL)isHide
  1348. {
  1349. mPlayerView.controlBtn.hidden = isHide;
  1350. }
  1351. #pragma mark - PlayerControlViewDelegate---控制器按键
  1352. //- (void)stopShareBtnBePressed:(id)sender
  1353. //{
  1354. // HLog(@"__________%s__________",__func__);
  1355. // /*关闭分享成功后调用*/
  1356. // CloudPhoneModel *deviceDcit = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:phoneIndex];
  1357. // NSString *userCardId = @"";
  1358. // userCardId = [NSString stringWithFormat:@"%ld",deviceDcit.phoneId];
  1359. //
  1360. // NSString *username = deviceDcit.username;
  1361. //
  1362. // if (0 == deviceShareStates || deviceShareStates == 3)/*分享中*/
  1363. // {
  1364. // /*暂停分享*/
  1365. // NSString *reqsturl = [NSString stringWithFormat:SuspendScreenShareAPI,userCardId,username];
  1366. // [[UseAccountManage shareInstance] CommonGetWithCallBackCode:reqsturl Parameters:nil success:^(id _Nonnull responseObject) {
  1367. // SuperModel *mod = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1368. // [self removeNewIndicator];
  1369. // NSString *showStr = nil;
  1370. // showStr = mod.msg;
  1371. // if (mod.status && mod.status.integerValue == 0)
  1372. // {
  1373. // deviceDcit.screenShareStatus = 1;
  1374. // self->deviceShareStates = 1;
  1375. // [self->controlView pauseShareView];
  1376. // /*刷新视图 更新设备列表*/
  1377. // deviceDcit.screenShareStatus = self->deviceShareStates;
  1378. // }
  1379. // else
  1380. // {
  1381. // if (mod.msg == nil || [mod.msg isEqualToString:@""])
  1382. // {
  1383. // showStr = @"暂停分享失败";
  1384. // }
  1385. // [[iToast makeText:showStr] show];
  1386. // }
  1387. // }
  1388. // failure:^(NSError * _Nonnull error) {
  1389. // [[iToast makeText:@"暂停分享失败"] show];
  1390. // [self removeNewIndicator];
  1391. // }];
  1392. // }
  1393. // else if (1 == deviceShareStates)/*暂停分享*/
  1394. // {
  1395. // /*开启分享*/
  1396. // NSString *reqsturl = [NSString stringWithFormat:StartAgainScreenShareAPI,userCardId,username];
  1397. // [[UseAccountManage shareInstance] CommonGetWithCallBackCode:reqsturl Parameters:nil success:^(id _Nonnull responseObject) {
  1398. // SuperModel *mod = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1399. // [self removeNewIndicator];
  1400. // NSString *showStr = nil;
  1401. // showStr = mod.msg;
  1402. // if (mod.status && mod.status.integerValue == 0)
  1403. // {
  1404. // self->deviceShareStates = 3;
  1405. // deviceDcit.screenShareStatus = self->deviceShareStates;
  1406. // [self->controlView shareingShareView];
  1407. // }
  1408. // else
  1409. // {
  1410. // if (mod.msg == nil || [mod.msg isEqualToString:@""])
  1411. // {
  1412. // showStr = @"开启分享失败";
  1413. // }
  1414. // [[iToast makeText:showStr] show];
  1415. // }
  1416. // }
  1417. // failure:^(NSError * _Nonnull error) {
  1418. // [[iToast makeText:@"开启分享失败"] show];
  1419. // [self removeNewIndicator];
  1420. // }];
  1421. // }
  1422. //}
  1423. - (void)showAlertToWaitForTrial:(NSInteger)mins {
  1424. NSString *tipsStr = [NSString stringWithFormat:@"由于系统资源繁忙\n请在%ld分钟后再次进入云手机", mins];
  1425. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:tipsStr attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:16],NSForegroundColorAttributeName: HWCFD1D4Color}];
  1426. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1427. }];
  1428. [sureAction setValue:HW3B7FFFColor forKey:@"titleTextColor"];//iOS8.3
  1429. [self showAlertWithTitle:nil message:string tilteAlignment:NSTextAlignmentCenter messageAlignment:NSTextAlignmentCenter sureAction:sureAction cancelAction:nil];
  1430. }
  1431. #pragma mark - 新的手势回调委托
  1432. - (void)playerShowImageViewtouchesStr:(NSString *)commondStr
  1433. {
  1434. if (canControl)
  1435. {
  1436. [self send_data:commondStr];
  1437. }
  1438. }
  1439. -(void)initAlertWithTitle:(NSString *_Nullable)title message:(NSString *)message sureActionBlock:(sureActionBlock)sureActionBlock {
  1440. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  1441. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1442. sureActionBlock(alertController);
  1443. }];
  1444. [alertController addAction:cancelAction];
  1445. // 弹窗边框
  1446. UIView *subview = alertController.view.subviews.firstObject;
  1447. UIView *alertContentView = subview.subviews.firstObject;
  1448. alertContentView.layer.cornerRadius = 10;
  1449. // alertContentView.layer.masksToBounds = YES;
  1450. alertContentView.layer.shadowColor = [UIColor colorWithRed:30/255.0 green:32/255.0 blue:34/255.0 alpha:1.0].CGColor;
  1451. alertContentView.layer.shadowOffset = CGSizeMake(0,0);
  1452. alertContentView.layer.shadowOpacity = 1;
  1453. alertContentView.layer.shadowRadius = 7;
  1454. // 弹窗背景颜色
  1455. if (@available(iOS 13.0, *)) {
  1456. alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
  1457. }
  1458. UIViewController *currentVC = [[ShortcutManager shareInstance] findCurrentShowingViewController];
  1459. [currentVC presentViewController:alertController animated:YES completion:nil];
  1460. // [self presentViewController:alertController animated:YES completion:nil];
  1461. }
  1462. #pragma - mark - 监听网络变化
  1463. - (void)networkStateChange:(NSNotification *)notification
  1464. {
  1465. /*处理*/
  1466. switch ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus)
  1467. {
  1468. case AFNetworkReachabilityStatusUnknown:/*网络状态未知*/
  1469. {
  1470. ;
  1471. }
  1472. break;
  1473. case AFNetworkReachabilityStatusNotReachable:/*网络不可用*/
  1474. {
  1475. //[[iToast makeText:@"网络异常,请稍后重试!"] show];
  1476. // if (_ihandle > 0)
  1477. // {
  1478. [self disconnectVideoServer];
  1479. // }
  1480. [self showNetErrorAlertFun:12];
  1481. }
  1482. break;
  1483. case AFNetworkReachabilityStatusReachableViaWWAN:/*流量*/
  1484. {
  1485. mainBlock(^{
  1486. [self showNewIndicator];
  1487. });
  1488. [self tryAgain];
  1489. }
  1490. break;
  1491. case AFNetworkReachabilityStatusReachableViaWiFi:/*WiFi*/
  1492. {
  1493. mainBlock(^{
  1494. [self showNewIndicator];
  1495. });
  1496. [self tryAgain];
  1497. [[backupsFileManager shareInstance] checkReBackupsFileFun];
  1498. }
  1499. break;
  1500. default:
  1501. break;
  1502. }
  1503. }
  1504. #pragma mark 网络异常弹框
  1505. -(void)showNetErrorAlertFun:(NSInteger)type
  1506. {
  1507. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"showNetErrorAlertFun %ld",type]];
  1508. if(linkFailAlretVC
  1509. ||[connectDeviceManager shareInstance].isReInitType//瑞云重新init 耗时2-7s 他们说的
  1510. ||(ksharedAppDelegate.isWebSockLinkOKAginType && type == 2) //重连上了但是延时消息来了
  1511. ||linkFailAlretType2VC){
  1512. return;
  1513. }
  1514. //重启后重连 出来的
  1515. if(_isRebootIngType){
  1516. if(![self isPlayerViewIsTopVCFun]){
  1517. [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  1518. }
  1519. return;
  1520. }
  1521. if(_isResetingType){
  1522. if(![self isPlayerViewIsTopVCFun]){
  1523. [[iToast makeText:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil)] show];
  1524. }
  1525. return;
  1526. }
  1527. if([self isPlayerViewIsTopVCFun]){
  1528. //等下再发
  1529. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1530. [self showNetErrorAlertFun:type];
  1531. });
  1532. return;
  1533. }
  1534. //未连接成功过
  1535. if(_isFirstEnterPhone && type == 5){
  1536. type = 1;
  1537. }
  1538. BOOL isPhoneNetWorkWrongType = NO;
  1539. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type11",nil);
  1540. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  1541. linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  1542. isPhoneNetWorkWrongType = YES;
  1543. }
  1544. if(type == 11 && !isPhoneNetWorkWrongType){
  1545. NSString* linkErrTitle = NSLocalizedString(@"player_link_fail_title_type11",nil);
  1546. linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
  1547. KWeakSelf
  1548. linkFailAlretType2VC = [[ComontAlretType2ViewController alloc] initWithTitle:linkErrTitle msg:linkErrTip imageStr:nil cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil) okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) otherTitle:NSLocalizedString(@"my_set_no_restart_phone",nil) isOkBtnHighlight:YES didClickOk:^{
  1549. [weakSelf tryAgainInLinkFailFun];
  1550. [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
  1551. } didClickCancel:^{
  1552. exit(0);
  1553. } didClickOther:^{//硬重启
  1554. [weakSelf needToRebootFun];
  1555. }];
  1556. linkFailAlretType2VC.modalPresentationStyle = UIModalPresentationCustom;
  1557. [self presentViewController:linkFailAlretType2VC animated:YES completion:^{
  1558. self->linkFailAlretType2VC.view.superview.backgroundColor = [UIColor clearColor];
  1559. }];
  1560. }
  1561. else{
  1562. NSString* linkErrTitle = @"";
  1563. if(type == 2
  1564. ||type==5
  1565. ||type==1
  1566. ||type==12){
  1567. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type2",nil);
  1568. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  1569. }
  1570. else{
  1571. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type3",nil);
  1572. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  1573. }
  1574. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  1575. linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  1576. }
  1577. linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
  1578. KWeakSelf
  1579. linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle
  1580. msg:linkErrTip
  1581. imageStr:nil
  1582. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  1583. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  1584. didClickOk:^{
  1585. [weakSelf tryAgainInLinkFailFun];
  1586. [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
  1587. } didClickCancel:^{
  1588. exit(0);
  1589. }];
  1590. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  1591. [linkFailAlretVC setMsgTextAlignment:NSTextAlignmentLeft];
  1592. [self presentViewController:linkFailAlretVC animated:YES completion:^{
  1593. self->linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  1594. }];
  1595. }
  1596. linkFailAlretVC.view.tag = type;
  1597. }
  1598. - (void)tryAgainInLinkFailFun
  1599. {
  1600. linkFailAlretVC = nil;
  1601. linkFailAlretType2VC = nil;
  1602. if([[connectDeviceManager shareInstance] curConnectDeviceState] <= 3)
  1603. {
  1604. //瑞云发起重连
  1605. NSString *snStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  1606. if(snStr){
  1607. //_checkThridConnectNum = 1;
  1608. [[connectDeviceManager shareInstance] getThridMsgBySN:snStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  1609. }];
  1610. }
  1611. return;
  1612. }
  1613. //[[connectDeviceManager shareInstance] tryReconnectFun];
  1614. [self showNewIndicator];
  1615. reConnectAccount = 0;
  1616. [self tryAgain];
  1617. }
  1618. BOOL inReconnect = NO;
  1619. - (void)tryAgain
  1620. {
  1621. HLog(@"yyyyyyyyyyyyy 重连次数 %ld ",reConnectAccount);
  1622. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"yyyyyyyyyyyyy 重连次数 %ld ",reConnectAccount]];
  1623. //20231017 修改后台3分钟再次进入 不断转圈圈问题
  1624. if (reConnectAccount >0 && reConnectAccount == 50 )
  1625. {
  1626. mainBlock(^{
  1627. if (self.isFirstEnterPhone) {
  1628. self.isFirstEnterPhone = NO;
  1629. }
  1630. //重启后重连 出来的 不显示
  1631. if(!self->_isRebootIngType && !self->_isResetingType && ![self isPlayerViewIsTopVCFun]){
  1632. /*链接失败*/
  1633. //[[iToast makeText:NSLocalizedString(@"player_link_fail_tip",nil)] show];
  1634. [self showNetErrorAlertFun:5];
  1635. }
  1636. });
  1637. return;
  1638. }
  1639. //hxd add 每次重新连接时间 要间隔3秒
  1640. // NSInteger curTryAginTime = [iTools getNowTimeStamp];
  1641. // if(preTryAginTime > 0
  1642. // && (curTryAginTime - preTryAginTime < 3)){
  1643. // return;
  1644. // }
  1645. //
  1646. // if(RCLiveSteamlinkState == ConnectStateConnected){
  1647. // return;
  1648. // }
  1649. //
  1650. // preTryAginTime = curTryAginTime;
  1651. reConnectAccount++;
  1652. mainBlock(^{
  1653. if(self->linkFailAlretVC && self->linkFailAlretVC.view.tag == 2){
  1654. [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
  1655. }
  1656. });
  1657. [cachesFileManager writeLogsWithMsg:@"reconnectDevice"];
  1658. [self reconnectDevice];
  1659. }
  1660. - (void)reconnectDevice{
  1661. globalBlock(^{
  1662. @synchronized (self) {
  1663. inReconnect = YES;
  1664. [self disconnectVideoServer];
  1665. if ([self initVideoServer])
  1666. {
  1667. [self connectVideoServer];
  1668. }
  1669. }
  1670. });
  1671. }
  1672. #pragma mark -- /*视频码率按钮文字、索引、指令 之间相互转换*/
  1673. - (NSUInteger)resolutionBtnIndexToTypeWithIndex:(NSInteger)index
  1674. {
  1675. NSInteger type = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1676. AFNetworkReachabilityStatus netStatus = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
  1677. if (netWorkStates == AFNetworkReachabilityStatusReachableViaWiFi) {
  1678. type = BITRATE_WIFI_STANDARD_CLEARING;
  1679. }
  1680. switch (index)
  1681. {
  1682. case 2:/*极速*/
  1683. type = BITRATE_EXTREME_SPEED;
  1684. break;
  1685. // case 1:/*高速*/
  1686. // type = BITRATE_HIGH_SPEED;
  1687. // break;
  1688. case 0:/*高清*/
  1689. if (netStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
  1690. type = BITRATE_WIFI_HD;
  1691. } else {
  1692. type = BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/;
  1693. }
  1694. break;
  1695. case 1:/*标清*/
  1696. if (netStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
  1697. type = BITRATE_WIFI_STANDARD_CLEARING;
  1698. } else {
  1699. type = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1700. }
  1701. break;
  1702. case 3:/*自动*/
  1703. type = BITRATE_AUTO;
  1704. break;
  1705. default:
  1706. break;
  1707. }
  1708. return type;
  1709. }
  1710. - (NSInteger)resolutionBtnTypeToIndexWithType:(NSInteger)type
  1711. {
  1712. NSInteger index = 2;
  1713. switch (type)
  1714. {
  1715. case BITRATE_EXTREME_SPEED:
  1716. index = 2;
  1717. break;
  1718. // case BITRATE_HIGH_SPEED:
  1719. // index = 1;
  1720. // break;
  1721. case BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/:
  1722. index = 0;
  1723. break;
  1724. // case BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/:
  1725. // index = 1;
  1726. // break;
  1727. case BITRATE_AUTO:
  1728. index = 3;
  1729. break;
  1730. default:
  1731. index = 2;
  1732. break;
  1733. }
  1734. return index;
  1735. }
  1736. - (NSString *)resolutionBtnIndexToStringWithType:(NSInteger)index
  1737. {
  1738. NSString *qualitySelectBtnString = @"标清";
  1739. switch (index)
  1740. {
  1741. case 2:
  1742. qualitySelectBtnString = @"极速";
  1743. break;
  1744. // case 1:
  1745. // qualitySelectBtnString = @"高速";
  1746. // break;
  1747. case 0:
  1748. qualitySelectBtnString = @"高清";
  1749. break;
  1750. case 1:
  1751. qualitySelectBtnString = @"标清";
  1752. break;
  1753. case 4:
  1754. qualitySelectBtnString = @"自动";
  1755. break;
  1756. default:
  1757. break;
  1758. }
  1759. return qualitySelectBtnString;
  1760. }
  1761. #pragma mark -- /*通知添加与移除*/
  1762. - (void)addNSNotification
  1763. {
  1764. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange:) name:NetWorkChangeNotification object:nil];
  1765. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connectDisconnect:) name:NotNameByCONNECT_DISCONNECT object:nil];
  1766. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
  1767. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
  1768. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
  1769. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
  1770. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
  1771. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:AVSystemController_SystemVolumeDidChangeNotification object:nil];
  1772. outputVolumeKVO = YES;
  1773. [[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:(void *)[AVAudioSession sharedInstance]];
  1774. // 控制按钮收拾开始、结束
  1775. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerViewControlBtnTouchBegan) name:PlayerViewControlBtnTouchBeganNotification object:nil];
  1776. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerViewControlBtnTouchEnd) name:PlayerViewControlBtnTouchEndNotification object:nil];
  1777. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setShowImgAndVoiceTypeFun) name:ShowImgAndVoiceNotification object:nil];
  1778. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setShowPwdVCTypeFun) name:ShowPwdVCNotification object:nil];
  1779. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPlayerFullScreenNotFun) name:setPlayerFullScreenNotification object:nil];
  1780. }
  1781. - (void)removeNSNotification
  1782. {
  1783. [[NSNotificationCenter defaultCenter] removeObserver:self name:NetWorkChangeNotification object:nil];
  1784. [[NSNotificationCenter defaultCenter] removeObserver:self name:NotNameByCONNECT_DISCONNECT object:nil];
  1785. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
  1786. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
  1787. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
  1788. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
  1789. if (outputVolumeKVO)
  1790. {
  1791. [[AVAudioSession sharedInstance] removeObserver:self forKeyPath:@"outputVolume" context:(void *)[AVAudioSession sharedInstance]];
  1792. outputVolumeKVO = NO;
  1793. }
  1794. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1795. }
  1796. #pragma mark -- 音视频数据透传回调
  1797. static double firstTime;
  1798. static double lastTime;
  1799. static int couneeee = 0;
  1800. - (void)videoOutPutH264Data:(void *)h264Data dataLenth:(NSInteger)lenth
  1801. {
  1802. if (couneeee == 0)
  1803. {
  1804. firstTime = [[NSDate date] timeIntervalSince1970];
  1805. }
  1806. couneeee++;
  1807. [self.liveStreamManager rc_sendTransportData:(const char *)h264Data length:(int)lenth dataType:VirtualDataTypeVideo];
  1808. if (couneeee == 100)
  1809. {
  1810. lastTime = [[NSDate date] timeIntervalSince1970];
  1811. HLog(@"\nvideoOutPutH264DataTime --%f",lastTime - firstTime);
  1812. }
  1813. }
  1814. - (void)audioOutPutData:(void *)audioData dataLenth:(NSInteger)lenth
  1815. {
  1816. [self.liveStreamManager rc_sendTransportData:(const char *)audioData length:(int)lenth dataType:VirtualDataTypeAudio];
  1817. }
  1818. -(NSString *)hexStringWithData:(NSData *)data
  1819. {
  1820. const unsigned char* dataBuffer = (const unsigned char*)[data bytes];
  1821. if(!dataBuffer){
  1822. return nil;
  1823. }
  1824. NSUInteger dataLength = [data length];
  1825. NSMutableString* hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
  1826. for(int i = 0; i < dataLength; i++){
  1827. [hexString appendString:[NSString stringWithFormat:@"%02lx", (unsigned long)dataBuffer[i]]];
  1828. }
  1829. NSString* result = [NSString stringWithString:hexString];
  1830. return result;
  1831. }
  1832. - (NSArray *)getAllIvar:(id)object
  1833. {
  1834. NSMutableArray *array = [NSMutableArray array];
  1835. unsigned int count;
  1836. Ivar *ivars = class_copyIvarList([object class], &count);
  1837. for (int i = 0; i < count; i++) {
  1838. Ivar ivar = ivars[i];
  1839. const char *keyChar = ivar_getName(ivar);
  1840. NSString *keyStr = [NSString stringWithCString:keyChar encoding:NSUTF8StringEncoding];
  1841. @try {
  1842. id valueStr = [object valueForKey:keyStr];
  1843. NSDictionary *dic = nil;
  1844. if (valueStr) {
  1845. dic = @{keyStr : valueStr};
  1846. } else {
  1847. dic = @{keyStr : @"值为nil"};
  1848. }
  1849. [array addObject:dic];
  1850. }
  1851. @catch (NSException *exception) {}
  1852. }
  1853. return [array copy];
  1854. }
  1855. //系统声音改变
  1856. #pragma -mark 系统声音改变
  1857. -(void)volumeChanged:(NSNotification *)notification
  1858. {
  1859. if (!self.isNeedShowVoiceBar) { // 不需要展示音量工具条
  1860. return;
  1861. }
  1862. // /*音量开关打开时 允许发送指令 否则直接返回*/
  1863. // NSDictionary *loginDict = [[UseAccountManage shareInstance] getLoginInfo];
  1864. // NSString *account = [loginDict objectForKey:@"account"];
  1865. // NSString *key = [account stringByAppendingString:Const_Volume_Info_Dict];
  1866. //
  1867. // NSDictionary *volumeDict = [[NSUserDefaults standardUserDefaults] objectForKey:key];
  1868. //
  1869. // NSString *volumeStr = [volumeDict safeStringForKey:deviceId];
  1870. //
  1871. // if (!volumeStr || ![volumeStr isEqualToString:@"1"]){
  1872. // return;
  1873. // }
  1874. //
  1875. // float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
  1876. // HLog(@"FlyElephant-系统音量:%f", volume);
  1877. //
  1878. // if (volume == 0)
  1879. // {
  1880. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:25];
  1881. //
  1882. // [self send_data:dataStr];
  1883. // }
  1884. // else if (volume == 1)
  1885. // {
  1886. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:24];
  1887. //
  1888. // [self send_data:dataStr];
  1889. // }
  1890. }
  1891. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  1892. if(context == (__bridge void *)[AVAudioSession sharedInstance])
  1893. {
  1894. // /*音量开关打开时 允许发送指令 否则直接返回*/
  1895. // NSDictionary *loginDict = [[UseAccountManage shareInstance] getLoginInfo];
  1896. // NSString *account = [loginDict objectForKey:@"account"];
  1897. // NSString *key = [account stringByAppendingString:Const_Volume_Info_Dict];
  1898. //
  1899. // NSDictionary *volumeDict = [[NSUserDefaults standardUserDefaults] objectForKey:key];
  1900. //
  1901. // NSString *volumeStr = [volumeDict safeStringForKey:deviceId];
  1902. //
  1903. // if (!volumeStr || ![volumeStr isEqualToString:@"1"]){
  1904. // return;
  1905. // }
  1906. //
  1907. // float newValue = [[change objectForKey:@"new"] floatValue];
  1908. // float oldValue = [[change objectForKey:@"old"] floatValue];
  1909. //
  1910. // if (newValue > oldValue)
  1911. // {
  1912. // HLog(@"\n-----音量增加");
  1913. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:24];
  1914. //
  1915. // [self send_data:dataStr];
  1916. // }
  1917. // else
  1918. // {
  1919. // HLog(@"\n-----音量降低");
  1920. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:25];
  1921. //
  1922. // [self send_data:dataStr];
  1923. // }
  1924. }
  1925. }
  1926. #pragma mark-----------------------------------------------------------------------------------------------
  1927. #pragma mark - 画面渲染、画面调整相关
  1928. #pragma mark - 更新网络标识 以及自动码率
  1929. - (void)updateAutoRateAndNetWorkStates
  1930. {
  1931. return;//功能未用到
  1932. int audio_time = 0;
  1933. NSDate *nowTime = [NSDate date];
  1934. NSString *nowTimeStr = [NSString stringWithFormat:@"%f", (double)[nowTime timeIntervalSince1970]];
  1935. NSString *lastTimeStr = [NSString stringWithFormat:@"%f", (double)[lastVideoTome timeIntervalSince1970]];
  1936. audio_time = ([nowTimeStr doubleValue] - [lastTimeStr doubleValue]) * 1000;
  1937. lastVideoTome = nowTime;
  1938. static int frameCount = 200;
  1939. if (0 == frameCount)
  1940. {
  1941. frameCount = 200;
  1942. if (audio_time > 500 && !haveBack && self->netWorkStates != 0)
  1943. {
  1944. self->netWorkStates = 0;
  1945. mainBlock(^{
  1946. [self->mPlayerView.controlBtn setBackgroundImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
  1947. });
  1948. }
  1949. else if (audio_time > 100 && !haveBack && self->netWorkStates != 1)
  1950. {
  1951. self->netWorkStates = 1;
  1952. mainBlock(^{
  1953. [self->mPlayerView.controlBtn setBackgroundImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
  1954. });
  1955. }
  1956. else if (!haveBack && self->netWorkStates != 2)
  1957. {
  1958. self->netWorkStates = 2;
  1959. mainBlock(^{
  1960. [self->mPlayerView.controlBtn setBackgroundImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
  1961. });
  1962. }
  1963. }
  1964. else
  1965. {
  1966. frameCount--;
  1967. }
  1968. if (delayVideo < audio_time)
  1969. {
  1970. delayVideo = audio_time;
  1971. }
  1972. if (delayVideo < 80)
  1973. {
  1974. okdelayVideo++;
  1975. }
  1976. else
  1977. {
  1978. okdelayVideo = 0;
  1979. }
  1980. if (delayVideo > 120)
  1981. {
  1982. baddelayVideo++;
  1983. }
  1984. havedelayVideoCount++;
  1985. if (havedelayVideoCount % 1000 == 0)
  1986. {
  1987. baddelayVideo = 0;
  1988. }
  1989. if (!haveBack && self->rate == 3) {
  1990. if (baddelayVideo > 10)
  1991. {
  1992. /*降低码率*/
  1993. if (self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/ || self->rateForAuto == BITRATE_WIFI_HD)
  1994. {
  1995. if (self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/) {
  1996. self->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1997. } else {
  1998. self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING;
  1999. }
  2000. }
  2001. else if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/ || self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING)
  2002. {
  2003. self->rateForAuto = BITRATE_EXTREME_SPEED;
  2004. }
  2005. // else if (mySelf->rateForAuto == BITRATE_HIGH_SPEED)
  2006. // {
  2007. // mySelf->rateForAuto = BITRATE_EXTREME_SPEED;
  2008. // NSString *dataStr = [RCCommandHelp commondResolution500WithType:mySelf->rateForAuto];
  2009. // int result = send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  2010. // }
  2011. NSString *dataStr = [RCCommandHelp commandResolution500WithType:self->rateForAuto];
  2012. // send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  2013. [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
  2014. baddelayVideo = 0;
  2015. }
  2016. if (okdelayVideo > 1000)
  2017. {
  2018. /*上升码率*/
  2019. if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/ || self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING)
  2020. {
  2021. if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/) {
  2022. self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/;
  2023. } else {
  2024. self->rateForAuto = BITRATE_WIFI_HD;
  2025. }
  2026. }
  2027. // else if (mySelf->rateForAuto == BITRATE_HIGH_SPEED)
  2028. // {
  2029. // mySelf->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  2030. // NSString *dataStr = [RCCommandHelp commondResolution500WithType:mySelf->rateForAuto];
  2031. // int result = send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  2032. // }
  2033. else if (self->rateForAuto == BITRATE_EXTREME_SPEED)
  2034. {
  2035. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
  2036. self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING;
  2037. } else {
  2038. self->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  2039. }
  2040. }
  2041. NSString *dataStr = [RCCommandHelp commandResolution500WithType:self->rateForAuto];
  2042. // send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  2043. [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
  2044. okdelayVideo = 0;
  2045. }
  2046. }
  2047. }
  2048. #pragma mark - opengl渲染
  2049. - (void)showImageOpenglWithCIImage:(CIImage *)ciImage
  2050. {
  2051. if (USELOCALKEYBOARD){
  2052. ;
  2053. }else{
  2054. CGFloat tempRate = ciImage.extent.size.width/ciImage.extent.size.height;
  2055. if (w_h_rate != tempRate)
  2056. {
  2057. // ksharedAppDelegate.couldPhone_W_PHONE = ciImage.extent.size.width;
  2058. // ksharedAppDelegate.couldPhone_H_PHONE = ciImage.extent.size.height;
  2059. w_h_rate = tempRate;
  2060. mainBlock(^{
  2061. [self updatePlayViewRate:tempRate];
  2062. });
  2063. }
  2064. }
  2065. [mPlayerView glkShowImage:ciImage];
  2066. }
  2067. #pragma mark - UIImageView渲染
  2068. - (void)showImageUIImageViewWithCIImage:(CIImage *)ciImage pixelBufferRef:(CVPixelBufferRef)pixelBuff1
  2069. {
  2070. CGImageRef videoImage = [videoContext createCGImage:ciImage fromRect:CGRectMake(0, 0, CVPixelBufferGetWidth(pixelBuff1), CVPixelBufferGetHeight(pixelBuff1))];
  2071. UIImage *image = [UIImage imageWithCGImage:videoImage];
  2072. CGFloat tempRate = image.size.width/image.size.height;
  2073. mainBlock(^{
  2074. if (image)
  2075. {
  2076. if (USELOCALKEYBOARD){
  2077. ;
  2078. }else{
  2079. if (w_h_rate != tempRate)
  2080. {
  2081. // ksharedAppDelegate.couldPhone_W_PHONE = ciImage.extent.size.width;
  2082. // ksharedAppDelegate.couldPhone_H_PHONE = ciImage.extent.size.height;
  2083. [self updatePlayViewRate:tempRate];
  2084. }
  2085. }
  2086. self->mPlayerView.showImageView.image = image;
  2087. }
  2088. });
  2089. CGImageRelease(videoImage);
  2090. }
  2091. #pragma mark -- /*画面布局调整*/
  2092. - (void)updatePlayViewRate:(CGFloat)tempRate
  2093. {
  2094. /*设置横竖屏*/
  2095. if (tempRate > 1) {/*横屏*/
  2096. [self setDeviceOrientation:(UIDeviceOrientationLandscapeRight)];
  2097. [mPlayerView setLanMas_makeWithImageRate:tempRate isOpenVirtual:YES isUsageMode:NO];
  2098. }else{/*竖屏*/
  2099. [self setDeviceOrientation:(UIDeviceOrientationPortrait)];
  2100. [mPlayerView setPoMas_makeWithImageRate:tempRate isOpenVirtual:YES isUsageMode:NO];
  2101. }
  2102. }
  2103. #pragma mark------------------------------------------------------------------------------------------------------------------
  2104. #pragma mark-提示 loading 相关
  2105. #pragma mark-添加带有文字loading
  2106. - (void)addLoadingWithTipsView:(NSString *)tipsStr
  2107. {
  2108. if (loadingWithTipsView)
  2109. {
  2110. [loadingWithTipsView removeFromSuperview];
  2111. loadingWithTipsView = nil;
  2112. }
  2113. loadingWithTipsView = [self loadingViewWithTipsStr:tipsStr];
  2114. [self.view addSubview:loadingWithTipsView];
  2115. }
  2116. - (void)removeLoadingWithTipsView
  2117. {
  2118. if (loadingWithTipsView)
  2119. {
  2120. [loadingWithTipsView removeFromSuperview];
  2121. loadingWithTipsView = nil;
  2122. }
  2123. }
  2124. - (UIView *)loadingViewWithTipsStr:(NSString*)tipsStr
  2125. {
  2126. UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  2127. [bgView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
  2128. FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"loadingWhiteGif" withExtension:@"gif"]]];
  2129. FLAnimatedImageView *upView = [[FLAnimatedImageView alloc] init];
  2130. [upView setFrame:CGRectMake((SCREEN_W - 65.f)/2.f, (SCREEN_H - 65.f)/2.f, 65.f, 65.f)];
  2131. [upView setContentMode:UIViewContentModeScaleAspectFill];
  2132. [upView setBackgroundColor:[ UIColor clearColor]];
  2133. upView.animatedImage = image;
  2134. [bgView addSubview:upView];
  2135. /*标签文字*/
  2136. UILabel *tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_W - 100.f)/2.f, (SCREEN_H - 65.f)/2.f + 65.f + 10.f, 100.f*AUTOSCALE, 20.f)];
  2137. [tipsLabel setText:tipsStr];
  2138. [tipsLabel setBackgroundColor:[UIColor clearColor]];
  2139. [tipsLabel setTextColor:[UIColor whiteColor]];
  2140. [tipsLabel setFont:[UIFont systemFontOfSize:14.f]];
  2141. [tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
  2142. [bgView addSubview:tipsLabel];
  2143. return bgView;
  2144. }
  2145. #pragma mark-添加loading
  2146. -(void)showNewIndicator
  2147. {
  2148. dispatch_async(dispatch_get_main_queue(), ^{
  2149. if (self->wattingView == nil)
  2150. {
  2151. HLog(@"Tan +++++开");
  2152. self->wattingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
  2153. [self->wattingView setBackgroundColor:RGBACOLOR(0.f, 0.f, 0.f, 0.7)];
  2154. [self->wattingView.layer setCornerRadius:10.f];
  2155. self->wattingView.center = [[UIApplication sharedApplication] keyWindow].center;// 将wattingVideoImageindicator放于播放画面的中央位置
  2156. self->wattingView.hidden = NO;
  2157. FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"loadingWhiteGif" withExtension:@"gif"]]];
  2158. FLAnimatedImageView *upView = [[FLAnimatedImageView alloc] init];
  2159. [upView setFrame:CGRectMake((100 - 65.f)/2.f, (100 - 65.f)/2.f, 65.f, 65.f)];
  2160. [upView setContentMode:UIViewContentModeScaleAspectFill];
  2161. [upView setBackgroundColor:[ UIColor clearColor]];
  2162. upView.animatedImage = image;
  2163. [self->wattingView addSubview:upView];
  2164. [self->mPlayerView addSubview:self->wattingView];
  2165. }
  2166. });
  2167. }
  2168. -(void)removeNewIndicator
  2169. {
  2170. if (self->wattingView != nil)
  2171. {
  2172. [[self->wattingView viewWithTag:1111].layer removeAllAnimations];
  2173. self->wattingView.hidden = YES;
  2174. [self->wattingView removeFromSuperview];
  2175. self->wattingView = nil;
  2176. }
  2177. }
  2178. #pragma mark 定时器
  2179. - (void)setTimerCountDown {
  2180. HLog(@"开启一个");
  2181. if (_timer) {
  2182. // 取消定时器
  2183. [self cancelTimer];
  2184. }
  2185. // 初始化值计时数据
  2186. self.adjustTime = 3;
  2187. self.concentTime = [iTools getNowTimeStamp];
  2188. self.currentTime = 0;
  2189. self.webSocketTime = 0;
  2190. self.webSocketTaskTime = 0;
  2191. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
  2192. [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
  2193. }
  2194. - (void)cancelTimer {
  2195. // 取消定时器
  2196. if(_timer){
  2197. [_timer invalidate];
  2198. _timer = nil;
  2199. }
  2200. }
  2201. - (void)timerChange {
  2202. //self.currentTime++;// 0、定时器计数
  2203. //HLog(@"111111111111111");
  2204. [self extensionAdjustBtnFrameCheckAdjustTime];// 1、悬浮球3s后 自动靠边隐藏
  2205. [self checkConcentTime];// 3、30s之后 没有收到拉流数据 自动断开链接
  2206. }
  2207. // 3、30s之后 没有收到拉流数据 自动断开链接
  2208. - (void)checkConcentTime {
  2209. NSInteger now = [iTools getNowTimeStamp];
  2210. NSInteger timeDiff = now - self.concentTime; // 渲染时间与当前时间 时间差
  2211. if (self.concentTime == 0) { //云手机未连接成功
  2212. HLog(@"云手机未连接成功");
  2213. }else if (timeDiff >= 30) { // 30s 无渲染数据
  2214. if(!_needToDissconnectType && !_isLoginAgainType && [self isPlayerViewIsTopVCFun]){
  2215. HLog(@"云手机30s 无渲染数据 自动断开连接");
  2216. self.concentTime = [iTools getNowTimeStamp];
  2217. //这个赋值不是真的链接中 应该是失联了
  2218. RCLiveSteamlinkState = ConnectStateConnecting;
  2219. [self showNewIndicator];
  2220. [self tryAgain];
  2221. }
  2222. // else if(self.webSocketConcentTime > 0){
  2223. // //后续要跟进
  2224. //
  2225. // if(_isFirstEnterPhone){
  2226. // HLog(@"\n\n\n\n\n 云手机30s 无渲染数据 要跟进 \n\n\n\n\n");
  2227. // [self showNetErrorAlertFun:3];
  2228. // }
  2229. // }
  2230. /*弹窗提示*/
  2231. }else {
  2232. // HLog(@"云手机渲染数据时间差:%zd", timeDiff);
  2233. }
  2234. }
  2235. #pragma mark - 提示框
  2236. - (void)showAlertWithTitle:(NSAttributedString*_Nullable)atbTitle
  2237. message:(NSAttributedString*_Nullable)atbmessage
  2238. tilteAlignment:(NSTextAlignment)tilteAlignment
  2239. messageAlignment:(NSTextAlignment)messageAlignment
  2240. sureAction:(UIAlertAction*_Nullable)sureAction
  2241. cancelAction:(UIAlertAction*_Nullable)cancelAction
  2242. {
  2243. // 当前控制器是UIAlertController 退出
  2244. UIViewController *currentVC = [[ShortcutManager shareInstance] findCurrentShowingViewController];
  2245. if ([currentVC isKindOfClass:[UIAlertController class]]) {
  2246. //获得极致体验服务 请购买云手机(不退出 优先级最高)
  2247. UIAlertController *alertVC = (UIAlertController *)currentVC;
  2248. NSMutableAttributedString *attriMsg = [alertVC valueForKey:@"_attributedMessage"];
  2249. if ([attriMsg.string containsString:@"获得极致体验服务"]) {
  2250. return;
  2251. }
  2252. HLog(@"%@",attriMsg.string);
  2253. [currentVC dismissViewControllerAnimated:NO completion:nil];
  2254. }
  2255. self.alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  2256. if (atbTitle)
  2257. {
  2258. [self.alertController setValue:atbTitle forKey:@"_attributedTitle"];
  2259. }
  2260. if (atbmessage)
  2261. {
  2262. [self.alertController setValue:atbmessage forKey:@"_attributedMessage"];
  2263. }
  2264. UIView *subView1 = self.alertController.view.subviews[0];
  2265. if (subView1 && [subView1 subviews])
  2266. {
  2267. UIView *subView2 = subView1.subviews[0];
  2268. if (subView2 && [subView2 subviews])
  2269. {
  2270. UIView *subView3 = subView2.subviews[0];
  2271. if (subView3 && [subView3 subviews])
  2272. {
  2273. UIView *subView4 = subView3.subviews[0];
  2274. if (subView4 && [subView4 subviews])
  2275. {
  2276. UIView *subView5 = subView4.subviews[0];
  2277. if (subView5 && [[subView5 subviews] count] > 1)
  2278. {
  2279. for (UIView *msg in subView5.subviews)
  2280. {
  2281. if ([msg isKindOfClass:[UILabel class]])
  2282. {
  2283. NSArray *trmp = [self getAllIvar:msg];
  2284. for (NSDictionary *dict in trmp)
  2285. {
  2286. if ([[dict allKeys] containsObject:@"_content"])
  2287. {
  2288. NSAttributedString *dsfds = [dict objectForKey:@"_content"];
  2289. if ([atbTitle.string isEqualToString:dsfds.string])
  2290. {
  2291. [(UILabel*)msg setTextAlignment:(tilteAlignment)];
  2292. }
  2293. else if ([atbmessage.string isEqualToString:dsfds.string])
  2294. {
  2295. if (((UILabel*)msg).numberOfLines == 0)
  2296. {
  2297. [(UILabel*)msg setTextAlignment:(messageAlignment)];
  2298. }
  2299. else if (((UILabel*)msg).numberOfLines == 1)
  2300. {
  2301. [(UILabel*)msg setTextAlignment:NSTextAlignmentCenter];
  2302. }
  2303. else
  2304. {
  2305. [(UILabel*)msg setTextAlignment:(NSTextAlignmentCenter)];
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. if (sureAction)
  2318. {
  2319. [self.alertController addAction:sureAction];
  2320. }
  2321. if (cancelAction)
  2322. {
  2323. [self.alertController addAction:cancelAction];
  2324. }
  2325. // 弹窗边框
  2326. UIView *subview = self.alertController.view.subviews.firstObject;
  2327. UIView *alertContentView = subview.subviews.firstObject;
  2328. alertContentView.layer.cornerRadius = 10;
  2329. // alertContentView.layer.masksToBounds = YES;
  2330. alertContentView.layer.shadowColor = [UIColor colorWithRed:30/255.0 green:32/255.0 blue:34/255.0 alpha:1.0].CGColor;
  2331. alertContentView.layer.shadowOffset = CGSizeMake(0,0);
  2332. alertContentView.layer.shadowOpacity = 1;
  2333. alertContentView.layer.shadowRadius = 7;
  2334. // 弹窗背景颜色
  2335. if (@available(iOS 13.0, *)) {
  2336. self.alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
  2337. }
  2338. [self presentViewController:self.alertController animated:YES completion:nil];
  2339. }
  2340. #pragma mark - 屏幕旋转相关
  2341. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  2342. return UIInterfaceOrientationPortrait;
  2343. }
  2344. - (BOOL)shouldAutorotate {
  2345. if (canRate)/*画面发现变化 状态变为YES*/
  2346. {
  2347. canRate = NO;/*关键点 只能旋转一次*/
  2348. return YES;
  2349. }
  2350. //是否允许转屏
  2351. return NO;/*平时禁止*/
  2352. }
  2353. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  2354. return
  2355. UIInterfaceOrientationMaskPortrait |
  2356. UIInterfaceOrientationMaskLandscapeLeft |
  2357. UIInterfaceOrientationMaskLandscapeRight;
  2358. }
  2359. #pragma mark -- /* 屏幕旋转通知接收函数*/
  2360. - (void)orientationChanged:(NSNotification *)notification
  2361. {
  2362. //KyoLog(@"rotated");
  2363. }
  2364. - (void)setDeviceOrientation:(UIDeviceOrientation)orientationPortrait
  2365. {
  2366. mainBlock(^{
  2367. UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
  2368. //isPortraitMode
  2369. BOOL ScreenMode = ((UIDeviceOrientation)orientation == orientationPortrait);
  2370. NSNumber *value = nil;
  2371. if (ScreenMode)
  2372. {
  2373. }
  2374. else
  2375. {
  2376. self.adjustTime = 3;
  2377. if (orientationPortrait == UIDeviceOrientationLandscapeLeft){
  2378. [self->mPlayerView setLanMas_makeWithImageRate:16.0/9.0 isOpenVirtual:YES isUsageMode:NO];
  2379. // [self.basebgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  2380. // make.left.mas_equalTo(0);
  2381. // make.right.mas_equalTo(0);
  2382. // make.top.mas_equalTo(0);
  2383. // make.bottom.mas_equalTo(0);
  2384. // }];
  2385. /*悬浮按钮旋转*/
  2386. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2387. [self reSetPlayerViewFloatBtnFrame];
  2388. });
  2389. [self->mPlayerView.controlBtn setHidden:NO];
  2390. }else{
  2391. [self->mPlayerView setPoMas_makeWithImageRate:9.0/16.0 isOpenVirtual:YES isUsageMode:NO];
  2392. // [self.basebgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  2393. // make.left.mas_equalTo(0);
  2394. // make.right.mas_equalTo(0);
  2395. // make.top.mas_equalTo(0);
  2396. // make.bottom.mas_equalTo(0);
  2397. // }];
  2398. }
  2399. self->canRate = YES;/*关键点 设置临时允许*/
  2400. value = [NSNumber numberWithInteger:orientationPortrait];//横竖屏值设置
  2401. [[UIDevice currentDevice] setValue:value forKey:@"orientation"];/*先将状态栏旋转(影响系统通知弹框方向)*/
  2402. [[NSNotificationCenter defaultCenter] postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];/*发送通知*/
  2403. }
  2404. });
  2405. }
  2406. /*切换连接方式*/
  2407. - (void)connectTypeChange{
  2408. [self reconnectDevice];
  2409. }
  2410. #pragma mark - UITextFieldDelegate 透传输入法委托
  2411. //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  2412. //
  2413. // /*长度为0时表示删除内容*/
  2414. // if (string.length > 0){
  2415. // NSString *replaceStr = [textField.text substringWithRange:range];
  2416. // HLog(@"\n000000要增加的文字:--%@-------",replaceStr);
  2417. // replaceStr = [replaceStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  2418. // HLog(@"\n111111要增加的文字:--%@-------",replaceStr);
  2419. // for (NSInteger nFori = 0; nFori < replaceStr.length; nFori++) {
  2420. // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
  2421. // [self.businessCommandChannelManager rc_sendData:dataStr];
  2422. // }
  2423. // HLog(@"\n-----输入内容:--%@-------",string);
  2424. // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:string];
  2425. // [self.businessCommandChannelManager rc_sendData:dataStr];
  2426. // }
  2427. // else{
  2428. // HLog(@"\n-----删除:--%ld-------",range.length);
  2429. // NSInteger needDeleteLength = range.length;
  2430. // for (NSInteger nFori = 0; nFori < needDeleteLength; nFori++) {
  2431. // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
  2432. // [self.businessCommandChannelManager rc_sendData:dataStr];
  2433. //
  2434. // /*初始内容无法删除问题处理*/
  2435. // hidenTextField.text = @"1234";
  2436. // hidenTextFieldOldStr = @"1234";
  2437. //
  2438. // /*如果两者内容差距较大 是否会有删除后出现两者内容不一样的情况*/
  2439. // if (![hidenTextField.text isEqualToString:hidenTextFieldOldStr]){
  2440. // /*两者不相等时需要做等值处理*/
  2441. // hidenTextFieldOldStr = hidenTextField.text;
  2442. // }
  2443. // }
  2444. // }
  2445. //
  2446. // return YES;
  2447. //}
  2448. - (void)textFieldDidEndEditing:(UITextField *)textField{
  2449. HLog(@"\n-----输入法透传 1111111 关闭键盘-------");
  2450. NSString *dataStr = [RCCommandHelp commandClosePhoneKeyboad];
  2451. //[self.businessCommandChannelManager rc_sendData:dataStr];
  2452. }
  2453. -(BOOL)prefersHomeIndicatorAutoHidden {
  2454. return YES;
  2455. }
  2456. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls
  2457. {
  2458. [self documentPicker:controller didPickDocumentsAtURLs:urls];
  2459. }
  2460. - (void)setPlayerFullScreenNotFun
  2461. {
  2462. BOOL fullscreenType = [HWDataManager getBoolWithKey:Consn_player_full_screen_show];
  2463. //重新设置分辨率
  2464. if(fullscreenType){
  2465. NSString *commandStr = [RCCommandHelp commondToSetFullScreenPhoneSize];
  2466. [self send_data:commandStr];
  2467. }
  2468. else{
  2469. NSString *commondStr = @"{\"data\":{\"height\":1920,\"width\":1080},\"type\":\"setPhoneSize\"}";
  2470. [self send_data:commondStr];
  2471. }
  2472. [self updatePlayViewRate:1.0];
  2473. }
  2474. //延迟系统触摸事件
  2475. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures{
  2476. return UIRectEdgeAll;
  2477. }
  2478. @end