PlayerViewController.mm 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909
  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 needToRebootFun];
  1030. }
  1031. break;
  1032. case 12:
  1033. {//退出云机
  1034. [weakSelf exitCloudPhoneFun];
  1035. }
  1036. break;
  1037. case 100:
  1038. {
  1039. self->mPlayerView.controlBtn.userInteractionEnabled = NO;
  1040. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1041. self->mPlayerView.controlBtn.userInteractionEnabled = YES;
  1042. });
  1043. [[webSocketManager shareInstance] onTvFun];
  1044. }
  1045. break;
  1046. case 101:
  1047. {
  1048. self->mPlayerView.controlBtn.userInteractionEnabled = NO;
  1049. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1050. self->mPlayerView.controlBtn.userInteractionEnabled = YES;
  1051. });
  1052. [weakSelf showCloseTVP2PFun];
  1053. }
  1054. break;
  1055. default:
  1056. break;
  1057. }
  1058. };
  1059. //#pragma mark 重启盒子
  1060. // //{"type":"reboot"}
  1061. // nextVC.needToReboot = ^{
  1062. // [weakSelf needToRebootFun];
  1063. // };
  1064. //
  1065. //#pragma mark TV投屏
  1066. // nextVC.needToTVP2P = ^{
  1067. // NSString *commondStr = @"{\"type\":\"wakeupTV\"}";
  1068. // [weakSelf send_data:commondStr];
  1069. // };
  1070. //#pragma mark 关闭TV投屏
  1071. // nextVC.closeTVP2P = ^{
  1072. // NSString *commondStr = @"{\"type\":\"TvOff\"}";
  1073. // [weakSelf send_data:commondStr];
  1074. // };
  1075. //
  1076. //#pragma mark 恢复出厂盒子
  1077. // nextVC.needToReset = ^{
  1078. // [weakSelf needToResetFun];
  1079. // };
  1080. //
  1081. //#pragma mark 恢复出厂盒子 ok
  1082. // nextVC.needToResetAndOk = ^{
  1083. // [weakSelf tryAgainInLinkFailFun];
  1084. // [weakSelf startCheckThridRuiYunTimerFun];
  1085. // };
  1086. //
  1087. //#pragma mark 获取云机版本信息
  1088. // nextVC.getSysInfo = ^{
  1089. // NSString *commondStr = @"{\"type\":\"getSysInfo\"}";
  1090. // [weakSelf send_data:commondStr];
  1091. // };
  1092. //#pragma mark 获取TV投屏状态
  1093. // nextVC.getTvStatus = ^{
  1094. // NSString *commondStr = @"{\"type\":\"TvStatus\"}";
  1095. // [weakSelf send_data:commondStr];
  1096. // };
  1097. }
  1098. #pragma mark 退出云机
  1099. - (void)exitCloudPhoneFun
  1100. {
  1101. [self.navigationController popViewControllerAnimated:YES];
  1102. }
  1103. #pragma mark 显示关闭投屏提示语
  1104. - (void)showCloseTVP2PFun{
  1105. /*弹窗提示TV投屏*/
  1106. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_close_TV_p2p_tip",nil)
  1107. msg:nil
  1108. imageStr:nil
  1109. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  1110. okTitle:NSLocalizedString(@"my_set_TVP2P_Open_sure",nil) isOkBtnHighlight:YES
  1111. didClickOk:^{
  1112. [self gotoCloseTVP2PFun];
  1113. } didClickCancel:^{
  1114. //HLog(@"2222");
  1115. }];
  1116. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  1117. [self presentViewController:nextVC animated:YES completion:^{
  1118. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  1119. }];
  1120. }
  1121. #pragma mark 确认开始TV投屏
  1122. -(void)gotoCloseTVP2PFun
  1123. {
  1124. [[webSocketManager shareInstance] offTvFun];
  1125. }
  1126. - (void)needToRebootFun
  1127. {
  1128. NSString *commondStr = @"{\"type\":\"reboot\"}";
  1129. [self send_data:commondStr];
  1130. [self startForceStartTimerFun];
  1131. //最后一帧 没显示正在重启问题
  1132. _canShowImgAndVoiceType = YES;
  1133. _isRebootIngType = YES;
  1134. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1135. // [self reconnectDevice];
  1136. // });
  1137. }
  1138. - (void)needToResetFun
  1139. {
  1140. NSString *commondStr = @"{\"type\":\"reset\"}";
  1141. [self send_data:commondStr];
  1142. //最后一帧 没显示正在重启问题
  1143. //self->_canShowImgAndVoiceType = YES;
  1144. _isResetingType = YES;
  1145. //添加到任务监听
  1146. //[self addCommandSendTaskFunWithType:@"reset" WithCommandStr:commondStr];
  1147. }
  1148. #pragma mark 启动timer 秒后检查是否软件重启成功
  1149. - (void)startForceStartTimerFun
  1150. {
  1151. if(forceStartTimer){
  1152. [forceStartTimer invalidate];
  1153. forceStartTimer = nil;
  1154. }
  1155. forceStartTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(gotoUpdateForceStartFun) userInfo:nil repeats:NO];
  1156. [[NSRunLoop currentRunLoop] addTimer:forceStartTimer forMode:NSRunLoopCommonModes];
  1157. }
  1158. - (void)gotoUpdateForceStartFun
  1159. {
  1160. [self updateForceStartFun];
  1161. KWeakSelf
  1162. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1163. [weakSelf reconnectDevice];
  1164. [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
  1165. });
  1166. }
  1167. #pragma mark 单点登录被挤下线弹框
  1168. - (void)LogoutByOtherFun
  1169. {
  1170. [self disconnectVideoServer];
  1171. _canShowImgAndVoiceType = NO;
  1172. //yyyy-MM-dd HH:mm:ss
  1173. NSString*dateStr = [iTools getNowTimeString2];
  1174. if(dateStr && dateStr.length == 19){
  1175. dateStr = [dateStr substringWithRange:NSMakeRange(11, 5)];
  1176. }
  1177. if(!_needShowLogoutDelayType){
  1178. _LogoutTimerStr = [[NSString alloc] initWithFormat:@"%@%@%@",NSLocalizedString(@"single_sign_on_Tips_one",nil),dateStr,NSLocalizedString(@"single_sign_on_Tips_two",nil)];
  1179. }
  1180. if(_isPwdVCShow){
  1181. _needShowLogoutDelayType = YES;
  1182. return;
  1183. }
  1184. _needShowLogoutDelayType = NO;
  1185. NSString * loginAgainStr = NSLocalizedString(@"single_sign_on_login_again",nil);
  1186. BOOL isOkBtnHighlight = YES;
  1187. if(![connectDeviceManager shareInstance].DeviceThirdIdMod.data.isPrivacyMode){
  1188. loginAgainStr = @"";
  1189. isOkBtnHighlight = NO;
  1190. }
  1191. /*弹窗提示重启*/
  1192. KWeakSelf
  1193. logoutAlertVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"single_sign_on_Tips_logout",nil)
  1194. msg:_LogoutTimerStr
  1195. imageStr:nil
  1196. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  1197. okTitle:loginAgainStr isOkBtnHighlight:isOkBtnHighlight
  1198. didClickOk:^{
  1199. [weakSelf tryAgain];
  1200. [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
  1201. } didClickCancel:^{
  1202. }];
  1203. logoutAlertVC.modalPresentationStyle = UIModalPresentationCustom;
  1204. logoutAlertVC.delegate = self;
  1205. [[iTools appRootViewController] presentViewController:logoutAlertVC animated:YES completion:^{
  1206. self->logoutAlertVC.view.superview.backgroundColor = [UIColor clearColor];
  1207. }];
  1208. _isLoginAgainType = YES;
  1209. }
  1210. #pragma mark 设置是否可以播放音频和视频
  1211. -(void)setShowPwdVCTypeFun
  1212. {
  1213. _isPwdVCShow = YES;
  1214. }
  1215. -(void)setShowImgAndVoiceTypeFun
  1216. {
  1217. _isPwdVCShow = NO;
  1218. if(logoutAlertVC){
  1219. return;
  1220. }
  1221. [self setShowImgAndVoiceTypeFun:YES];
  1222. if(_needShowLogoutDelayType){
  1223. [self LogoutByOtherFun];
  1224. }
  1225. }
  1226. #pragma mark 判断是否为密码界面登 函数意思写反了 ~~~~
  1227. - (BOOL)isPlayerViewIsTopVCFun
  1228. {
  1229. UIViewController*topVc = self.navigationController.viewControllers.lastObject;
  1230. if(_isPwdVCShow || ![topVc isKindOfClass:[PlayerViewController class]]){
  1231. return YES;
  1232. }
  1233. return NO;
  1234. }
  1235. -(void)setShowImgAndVoiceTypeFun:(bool)isCan
  1236. {
  1237. if(isCan){//判断当前是否为最前面 才能播放
  1238. if(self->logoutAlertVC){
  1239. return;
  1240. }
  1241. if(_isLoginAgainType ){
  1242. [self tryAgain];
  1243. //[self fristConnectNeedGiveAMsgFun];
  1244. }
  1245. if([self isPlayerViewIsTopVCFun]){
  1246. return;
  1247. }
  1248. _canShowImgAndVoiceType = isCan;
  1249. }
  1250. else{
  1251. _canShowImgAndVoiceType = isCan;
  1252. }
  1253. }
  1254. #pragma mark - 显示秘钥 后续忘记密码要
  1255. -(void)showSecretkeyFun
  1256. {
  1257. // V1.4这个版本把密钥弹框去掉 军义20240537 下的需求 防盗
  1258. return;
  1259. mPlayerView.controlBtn.hidden = YES;
  1260. playerShowSecretkeyView *view = [[playerShowSecretkeyView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  1261. [self.view addSubview:view];
  1262. [self.view bringSubviewToFront:view];
  1263. KWeakSelf
  1264. view.didCloseSecretKeyViewTip = ^{
  1265. [HWDataManager setBoolWithKey:Const_need_show_Secret_key value:NO];
  1266. self->mPlayerView.controlBtn.hidden = NO;
  1267. [weakSelf showControlBtnTipFun];
  1268. };
  1269. view.didCopySecretKeyViewTip = ^{
  1270. [weakSelf updateCopydata];
  1271. };
  1272. }
  1273. #pragma mark 显示首次浮标引导操作提示
  1274. - (void)showControlBtnTipFun{
  1275. BOOL didShowControlBtnTip = [HWDataManager getBoolWithKey:Const_did_Show_playView_controlBtn_Tip];
  1276. if(!didShowControlBtnTip && !_PlayerControlButTipV){
  1277. mPlayerView.controlBtn.hidden = YES;
  1278. _PlayerControlButTipV = [[PlayerControlButTipView alloc] init];
  1279. _PlayerControlButTipV.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
  1280. [self.view addSubview:_PlayerControlButTipV];
  1281. [self.view bringSubviewToFront:_PlayerControlButTipV];
  1282. [_PlayerControlButTipV mas_makeConstraints:^(MASConstraintMaker *make) {
  1283. make.right.mas_equalTo(0);
  1284. make.top.mas_equalTo(0.f);
  1285. make.left.mas_equalTo(0.f);
  1286. make.bottom.mas_equalTo(0.f);
  1287. }];
  1288. KWeakSelf
  1289. _PlayerControlButTipV.didKnowPlayerControlButTip = ^{
  1290. [weakSelf setMPlayerViewControlBtnHiddenBy:NO];
  1291. };
  1292. }
  1293. }
  1294. - (void)setMPlayerViewControlBtnHiddenBy:(BOOL)isHide
  1295. {
  1296. mPlayerView.controlBtn.hidden = isHide;
  1297. }
  1298. #pragma mark - PlayerControlViewDelegate---控制器按键
  1299. //- (void)stopShareBtnBePressed:(id)sender
  1300. //{
  1301. // HLog(@"__________%s__________",__func__);
  1302. // /*关闭分享成功后调用*/
  1303. // CloudPhoneModel *deviceDcit = [[UseAccountManage shareInstance].cloudPhoneListModel.diskInfo objectAtIndex:phoneIndex];
  1304. // NSString *userCardId = @"";
  1305. // userCardId = [NSString stringWithFormat:@"%ld",deviceDcit.phoneId];
  1306. //
  1307. // NSString *username = deviceDcit.username;
  1308. //
  1309. // if (0 == deviceShareStates || deviceShareStates == 3)/*分享中*/
  1310. // {
  1311. // /*暂停分享*/
  1312. // NSString *reqsturl = [NSString stringWithFormat:SuspendScreenShareAPI,userCardId,username];
  1313. // [[UseAccountManage shareInstance] CommonGetWithCallBackCode:reqsturl Parameters:nil success:^(id _Nonnull responseObject) {
  1314. // SuperModel *mod = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1315. // [self removeNewIndicator];
  1316. // NSString *showStr = nil;
  1317. // showStr = mod.msg;
  1318. // if (mod.status && mod.status.integerValue == 0)
  1319. // {
  1320. // deviceDcit.screenShareStatus = 1;
  1321. // self->deviceShareStates = 1;
  1322. // [self->controlView pauseShareView];
  1323. // /*刷新视图 更新设备列表*/
  1324. // deviceDcit.screenShareStatus = self->deviceShareStates;
  1325. // }
  1326. // else
  1327. // {
  1328. // if (mod.msg == nil || [mod.msg isEqualToString:@""])
  1329. // {
  1330. // showStr = @"暂停分享失败";
  1331. // }
  1332. // [[iToast makeText:showStr] show];
  1333. // }
  1334. // }
  1335. // failure:^(NSError * _Nonnull error) {
  1336. // [[iToast makeText:@"暂停分享失败"] show];
  1337. // [self removeNewIndicator];
  1338. // }];
  1339. // }
  1340. // else if (1 == deviceShareStates)/*暂停分享*/
  1341. // {
  1342. // /*开启分享*/
  1343. // NSString *reqsturl = [NSString stringWithFormat:StartAgainScreenShareAPI,userCardId,username];
  1344. // [[UseAccountManage shareInstance] CommonGetWithCallBackCode:reqsturl Parameters:nil success:^(id _Nonnull responseObject) {
  1345. // SuperModel *mod = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  1346. // [self removeNewIndicator];
  1347. // NSString *showStr = nil;
  1348. // showStr = mod.msg;
  1349. // if (mod.status && mod.status.integerValue == 0)
  1350. // {
  1351. // self->deviceShareStates = 3;
  1352. // deviceDcit.screenShareStatus = self->deviceShareStates;
  1353. // [self->controlView shareingShareView];
  1354. // }
  1355. // else
  1356. // {
  1357. // if (mod.msg == nil || [mod.msg isEqualToString:@""])
  1358. // {
  1359. // showStr = @"开启分享失败";
  1360. // }
  1361. // [[iToast makeText:showStr] show];
  1362. // }
  1363. // }
  1364. // failure:^(NSError * _Nonnull error) {
  1365. // [[iToast makeText:@"开启分享失败"] show];
  1366. // [self removeNewIndicator];
  1367. // }];
  1368. // }
  1369. //}
  1370. - (void)showAlertToWaitForTrial:(NSInteger)mins {
  1371. NSString *tipsStr = [NSString stringWithFormat:@"由于系统资源繁忙\n请在%ld分钟后再次进入云手机", mins];
  1372. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:tipsStr attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:16],NSForegroundColorAttributeName: HWCFD1D4Color}];
  1373. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1374. }];
  1375. [sureAction setValue:HW3B7FFFColor forKey:@"titleTextColor"];//iOS8.3
  1376. [self showAlertWithTitle:nil message:string tilteAlignment:NSTextAlignmentCenter messageAlignment:NSTextAlignmentCenter sureAction:sureAction cancelAction:nil];
  1377. }
  1378. #pragma mark - 新的手势回调委托
  1379. - (void)playerShowImageViewtouchesStr:(NSString *)commondStr
  1380. {
  1381. if (canControl)
  1382. {
  1383. [self send_data:commondStr];
  1384. }
  1385. }
  1386. -(void)initAlertWithTitle:(NSString *_Nullable)title message:(NSString *)message sureActionBlock:(sureActionBlock)sureActionBlock {
  1387. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  1388. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1389. sureActionBlock(alertController);
  1390. }];
  1391. [alertController addAction:cancelAction];
  1392. // 弹窗边框
  1393. UIView *subview = alertController.view.subviews.firstObject;
  1394. UIView *alertContentView = subview.subviews.firstObject;
  1395. alertContentView.layer.cornerRadius = 10;
  1396. // alertContentView.layer.masksToBounds = YES;
  1397. alertContentView.layer.shadowColor = [UIColor colorWithRed:30/255.0 green:32/255.0 blue:34/255.0 alpha:1.0].CGColor;
  1398. alertContentView.layer.shadowOffset = CGSizeMake(0,0);
  1399. alertContentView.layer.shadowOpacity = 1;
  1400. alertContentView.layer.shadowRadius = 7;
  1401. // 弹窗背景颜色
  1402. if (@available(iOS 13.0, *)) {
  1403. alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
  1404. }
  1405. UIViewController *currentVC = [[ShortcutManager shareInstance] findCurrentShowingViewController];
  1406. [currentVC presentViewController:alertController animated:YES completion:nil];
  1407. // [self presentViewController:alertController animated:YES completion:nil];
  1408. }
  1409. #pragma - mark - 监听网络变化
  1410. - (void)networkStateChange:(NSNotification *)notification
  1411. {
  1412. /*处理*/
  1413. switch ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus)
  1414. {
  1415. case AFNetworkReachabilityStatusUnknown:/*网络状态未知*/
  1416. {
  1417. ;
  1418. }
  1419. break;
  1420. case AFNetworkReachabilityStatusNotReachable:/*网络不可用*/
  1421. {
  1422. //[[iToast makeText:@"网络异常,请稍后重试!"] show];
  1423. // if (_ihandle > 0)
  1424. // {
  1425. [self disconnectVideoServer];
  1426. // }
  1427. [self showNetErrorAlertFun:12];
  1428. }
  1429. break;
  1430. case AFNetworkReachabilityStatusReachableViaWWAN:/*流量*/
  1431. {
  1432. mainBlock(^{
  1433. [self showNewIndicator];
  1434. });
  1435. [self tryAgain];
  1436. }
  1437. break;
  1438. case AFNetworkReachabilityStatusReachableViaWiFi:/*WiFi*/
  1439. {
  1440. mainBlock(^{
  1441. [self showNewIndicator];
  1442. });
  1443. [self tryAgain];
  1444. [[backupsFileManager shareInstance] checkReBackupsFileFun];
  1445. }
  1446. break;
  1447. default:
  1448. break;
  1449. }
  1450. }
  1451. #pragma mark 网络异常弹框
  1452. -(void)showNetErrorAlertFun:(NSInteger)type
  1453. {
  1454. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"showNetErrorAlertFun %ld",type]];
  1455. if(linkFailAlretVC
  1456. ||[connectDeviceManager shareInstance].isReInitType//瑞云重新init 耗时2-7s 他们说的
  1457. ||(ksharedAppDelegate.isWebSockLinkOKAginType && type == 2) //重连上了但是延时消息来了
  1458. ||linkFailAlretType2VC){
  1459. return;
  1460. }
  1461. //重启后重连 出来的
  1462. if(_isRebootIngType){
  1463. if(![self isPlayerViewIsTopVCFun]){
  1464. [[iToast makeText:NSLocalizedString(@"player_link_rebooting_Tips",nil)] show];
  1465. }
  1466. return;
  1467. }
  1468. if(_isResetingType){
  1469. if(![self isPlayerViewIsTopVCFun]){
  1470. [[iToast makeText:NSLocalizedString(@"my_set_no_Restore_Factorying_tips",nil)] show];
  1471. }
  1472. return;
  1473. }
  1474. if([self isPlayerViewIsTopVCFun]){
  1475. //等下再发
  1476. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1477. [self showNetErrorAlertFun:type];
  1478. });
  1479. return;
  1480. }
  1481. //未连接成功过
  1482. if(_isFirstEnterPhone && type == 5){
  1483. type = 1;
  1484. }
  1485. BOOL isPhoneNetWorkWrongType = NO;
  1486. NSString *linkErrTip = NSLocalizedString(@"player_link_fail_tip_type11",nil);
  1487. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  1488. linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  1489. isPhoneNetWorkWrongType = YES;
  1490. }
  1491. if(type == 11 && !isPhoneNetWorkWrongType){
  1492. NSString* linkErrTitle = NSLocalizedString(@"player_link_fail_title_type11",nil);
  1493. linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
  1494. KWeakSelf
  1495. 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:^{
  1496. [weakSelf tryAgainInLinkFailFun];
  1497. [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
  1498. } didClickCancel:^{
  1499. exit(0);
  1500. } didClickOther:^{//硬重启
  1501. [weakSelf needToRebootFun];
  1502. }];
  1503. linkFailAlretType2VC.modalPresentationStyle = UIModalPresentationCustom;
  1504. [self presentViewController:linkFailAlretType2VC animated:YES completion:^{
  1505. self->linkFailAlretType2VC.view.superview.backgroundColor = [UIColor clearColor];
  1506. }];
  1507. }
  1508. else{
  1509. NSString* linkErrTitle = @"";
  1510. if(type == 2
  1511. ||type==5
  1512. ||type==1
  1513. ||type==12){
  1514. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type2",nil);
  1515. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  1516. }
  1517. else{
  1518. linkErrTitle = NSLocalizedString(@"player_link_fail_title_type3",nil);
  1519. linkErrTip = NSLocalizedString(@"player_link_fail_tip_type2",nil);
  1520. }
  1521. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable){
  1522. linkErrTip = NSLocalizedString(@"netWork_error_tip_content",nil);
  1523. }
  1524. linkErrTitle = [[NSString alloc] initWithFormat:@"[%ld]%@",type,linkErrTitle];
  1525. KWeakSelf
  1526. linkFailAlretVC= [[ComontAlretViewController alloc] initWithTiTle:linkErrTitle
  1527. msg:linkErrTip
  1528. imageStr:nil
  1529. cancelTitle:NSLocalizedString(@"single_sign_on_exit",nil)
  1530. okTitle:NSLocalizedString(@"player_link_fail_tryAgain",nil) isOkBtnHighlight:YES
  1531. didClickOk:^{
  1532. [weakSelf tryAgainInLinkFailFun];
  1533. [cachesFileManager writeLogsWithMsg:@"click tryAgain"];
  1534. } didClickCancel:^{
  1535. exit(0);
  1536. }];
  1537. linkFailAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  1538. [linkFailAlretVC setMsgTextAlignment:NSTextAlignmentLeft];
  1539. [self presentViewController:linkFailAlretVC animated:YES completion:^{
  1540. self->linkFailAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  1541. }];
  1542. }
  1543. linkFailAlretVC.view.tag = type;
  1544. }
  1545. - (void)tryAgainInLinkFailFun
  1546. {
  1547. linkFailAlretVC = nil;
  1548. linkFailAlretType2VC = nil;
  1549. if([[connectDeviceManager shareInstance] curConnectDeviceState] <= 3)
  1550. {
  1551. //瑞云发起重连
  1552. NSString *snStr = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.changeSn;
  1553. if(snStr){
  1554. //_checkThridConnectNum = 1;
  1555. [[connectDeviceManager shareInstance] getThridMsgBySN:snStr needReconnect:YES didNetEnd:^(NSInteger didSuc) {
  1556. }];
  1557. }
  1558. return;
  1559. }
  1560. //[[connectDeviceManager shareInstance] tryReconnectFun];
  1561. [self showNewIndicator];
  1562. reConnectAccount = 0;
  1563. [self tryAgain];
  1564. }
  1565. BOOL inReconnect = NO;
  1566. - (void)tryAgain
  1567. {
  1568. HLog(@"yyyyyyyyyyyyy 重连次数 %ld ",reConnectAccount);
  1569. [cachesFileManager writeLogsWithMsg:[[NSString alloc] initWithFormat:@"yyyyyyyyyyyyy 重连次数 %ld ",reConnectAccount]];
  1570. //20231017 修改后台3分钟再次进入 不断转圈圈问题
  1571. if (reConnectAccount >0 && reConnectAccount == 50 )
  1572. {
  1573. mainBlock(^{
  1574. if (self.isFirstEnterPhone) {
  1575. self.isFirstEnterPhone = NO;
  1576. }
  1577. //重启后重连 出来的 不显示
  1578. if(!self->_isRebootIngType && !self->_isResetingType && ![self isPlayerViewIsTopVCFun]){
  1579. /*链接失败*/
  1580. //[[iToast makeText:NSLocalizedString(@"player_link_fail_tip",nil)] show];
  1581. [self showNetErrorAlertFun:5];
  1582. }
  1583. });
  1584. return;
  1585. }
  1586. //hxd add 每次重新连接时间 要间隔3秒
  1587. // NSInteger curTryAginTime = [iTools getNowTimeStamp];
  1588. // if(preTryAginTime > 0
  1589. // && (curTryAginTime - preTryAginTime < 3)){
  1590. // return;
  1591. // }
  1592. //
  1593. // if(RCLiveSteamlinkState == ConnectStateConnected){
  1594. // return;
  1595. // }
  1596. //
  1597. // preTryAginTime = curTryAginTime;
  1598. reConnectAccount++;
  1599. mainBlock(^{
  1600. if(self->linkFailAlretVC && self->linkFailAlretVC.view.tag == 2){
  1601. [[webSocketManager shareInstance] WebSocketNeedRelinkFun];
  1602. }
  1603. });
  1604. [cachesFileManager writeLogsWithMsg:@"reconnectDevice"];
  1605. [self reconnectDevice];
  1606. }
  1607. - (void)reconnectDevice{
  1608. globalBlock(^{
  1609. @synchronized (self) {
  1610. inReconnect = YES;
  1611. [self disconnectVideoServer];
  1612. if ([self initVideoServer])
  1613. {
  1614. [self connectVideoServer];
  1615. }
  1616. }
  1617. });
  1618. }
  1619. #pragma mark -- /*视频码率按钮文字、索引、指令 之间相互转换*/
  1620. - (NSUInteger)resolutionBtnIndexToTypeWithIndex:(NSInteger)index
  1621. {
  1622. NSInteger type = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1623. AFNetworkReachabilityStatus netStatus = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
  1624. if (netWorkStates == AFNetworkReachabilityStatusReachableViaWiFi) {
  1625. type = BITRATE_WIFI_STANDARD_CLEARING;
  1626. }
  1627. switch (index)
  1628. {
  1629. case 2:/*极速*/
  1630. type = BITRATE_EXTREME_SPEED;
  1631. break;
  1632. // case 1:/*高速*/
  1633. // type = BITRATE_HIGH_SPEED;
  1634. // break;
  1635. case 0:/*高清*/
  1636. if (netStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
  1637. type = BITRATE_WIFI_HD;
  1638. } else {
  1639. type = BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/;
  1640. }
  1641. break;
  1642. case 1:/*标清*/
  1643. if (netStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
  1644. type = BITRATE_WIFI_STANDARD_CLEARING;
  1645. } else {
  1646. type = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1647. }
  1648. break;
  1649. case 3:/*自动*/
  1650. type = BITRATE_AUTO;
  1651. break;
  1652. default:
  1653. break;
  1654. }
  1655. return type;
  1656. }
  1657. - (NSInteger)resolutionBtnTypeToIndexWithType:(NSInteger)type
  1658. {
  1659. NSInteger index = 2;
  1660. switch (type)
  1661. {
  1662. case BITRATE_EXTREME_SPEED:
  1663. index = 2;
  1664. break;
  1665. // case BITRATE_HIGH_SPEED:
  1666. // index = 1;
  1667. // break;
  1668. case BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/:
  1669. index = 0;
  1670. break;
  1671. // case BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/:
  1672. // index = 1;
  1673. // break;
  1674. case BITRATE_AUTO:
  1675. index = 3;
  1676. break;
  1677. default:
  1678. index = 2;
  1679. break;
  1680. }
  1681. return index;
  1682. }
  1683. - (NSString *)resolutionBtnIndexToStringWithType:(NSInteger)index
  1684. {
  1685. NSString *qualitySelectBtnString = @"标清";
  1686. switch (index)
  1687. {
  1688. case 2:
  1689. qualitySelectBtnString = @"极速";
  1690. break;
  1691. // case 1:
  1692. // qualitySelectBtnString = @"高速";
  1693. // break;
  1694. case 0:
  1695. qualitySelectBtnString = @"高清";
  1696. break;
  1697. case 1:
  1698. qualitySelectBtnString = @"标清";
  1699. break;
  1700. case 4:
  1701. qualitySelectBtnString = @"自动";
  1702. break;
  1703. default:
  1704. break;
  1705. }
  1706. return qualitySelectBtnString;
  1707. }
  1708. #pragma mark -- /*通知添加与移除*/
  1709. - (void)addNSNotification
  1710. {
  1711. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange:) name:NetWorkChangeNotification object:nil];
  1712. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connectDisconnect:) name:NotNameByCONNECT_DISCONNECT object:nil];
  1713. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
  1714. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
  1715. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
  1716. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
  1717. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
  1718. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:AVSystemController_SystemVolumeDidChangeNotification object:nil];
  1719. outputVolumeKVO = YES;
  1720. [[AVAudioSession sharedInstance] addObserver:self forKeyPath:@"outputVolume" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:(void *)[AVAudioSession sharedInstance]];
  1721. // 控制按钮收拾开始、结束
  1722. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerViewControlBtnTouchBegan) name:PlayerViewControlBtnTouchBeganNotification object:nil];
  1723. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerViewControlBtnTouchEnd) name:PlayerViewControlBtnTouchEndNotification object:nil];
  1724. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setShowImgAndVoiceTypeFun) name:ShowImgAndVoiceNotification object:nil];
  1725. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setShowPwdVCTypeFun) name:ShowPwdVCNotification object:nil];
  1726. //某一个YCDownloadItem下载成功通知
  1727. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskFinishedNoti:) name:nasDownloadTaskFinishedNotification object:nil];
  1728. }
  1729. - (void)removeNSNotification
  1730. {
  1731. [[NSNotificationCenter defaultCenter] removeObserver:self name:NetWorkChangeNotification object:nil];
  1732. [[NSNotificationCenter defaultCenter] removeObserver:self name:NotNameByCONNECT_DISCONNECT object:nil];
  1733. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
  1734. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
  1735. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
  1736. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
  1737. if (outputVolumeKVO)
  1738. {
  1739. [[AVAudioSession sharedInstance] removeObserver:self forKeyPath:@"outputVolume" context:(void *)[AVAudioSession sharedInstance]];
  1740. outputVolumeKVO = NO;
  1741. }
  1742. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1743. }
  1744. #pragma mark -- 音视频数据透传回调
  1745. static double firstTime;
  1746. static double lastTime;
  1747. static int couneeee = 0;
  1748. - (void)videoOutPutH264Data:(void *)h264Data dataLenth:(NSInteger)lenth
  1749. {
  1750. if (couneeee == 0)
  1751. {
  1752. firstTime = [[NSDate date] timeIntervalSince1970];
  1753. }
  1754. couneeee++;
  1755. [self.liveStreamManager rc_sendTransportData:(const char *)h264Data length:(int)lenth dataType:VirtualDataTypeVideo];
  1756. if (couneeee == 100)
  1757. {
  1758. lastTime = [[NSDate date] timeIntervalSince1970];
  1759. HLog(@"\nvideoOutPutH264DataTime --%f",lastTime - firstTime);
  1760. }
  1761. }
  1762. - (void)audioOutPutData:(void *)audioData dataLenth:(NSInteger)lenth
  1763. {
  1764. [self.liveStreamManager rc_sendTransportData:(const char *)audioData length:(int)lenth dataType:VirtualDataTypeAudio];
  1765. }
  1766. -(NSString *)hexStringWithData:(NSData *)data
  1767. {
  1768. const unsigned char* dataBuffer = (const unsigned char*)[data bytes];
  1769. if(!dataBuffer){
  1770. return nil;
  1771. }
  1772. NSUInteger dataLength = [data length];
  1773. NSMutableString* hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
  1774. for(int i = 0; i < dataLength; i++){
  1775. [hexString appendString:[NSString stringWithFormat:@"%02lx", (unsigned long)dataBuffer[i]]];
  1776. }
  1777. NSString* result = [NSString stringWithString:hexString];
  1778. return result;
  1779. }
  1780. - (NSArray *)getAllIvar:(id)object
  1781. {
  1782. NSMutableArray *array = [NSMutableArray array];
  1783. unsigned int count;
  1784. Ivar *ivars = class_copyIvarList([object class], &count);
  1785. for (int i = 0; i < count; i++) {
  1786. Ivar ivar = ivars[i];
  1787. const char *keyChar = ivar_getName(ivar);
  1788. NSString *keyStr = [NSString stringWithCString:keyChar encoding:NSUTF8StringEncoding];
  1789. @try {
  1790. id valueStr = [object valueForKey:keyStr];
  1791. NSDictionary *dic = nil;
  1792. if (valueStr) {
  1793. dic = @{keyStr : valueStr};
  1794. } else {
  1795. dic = @{keyStr : @"值为nil"};
  1796. }
  1797. [array addObject:dic];
  1798. }
  1799. @catch (NSException *exception) {}
  1800. }
  1801. return [array copy];
  1802. }
  1803. //系统声音改变
  1804. #pragma -mark 系统声音改变
  1805. -(void)volumeChanged:(NSNotification *)notification
  1806. {
  1807. if (!self.isNeedShowVoiceBar) { // 不需要展示音量工具条
  1808. return;
  1809. }
  1810. // /*音量开关打开时 允许发送指令 否则直接返回*/
  1811. // NSDictionary *loginDict = [[UseAccountManage shareInstance] getLoginInfo];
  1812. // NSString *account = [loginDict objectForKey:@"account"];
  1813. // NSString *key = [account stringByAppendingString:Const_Volume_Info_Dict];
  1814. //
  1815. // NSDictionary *volumeDict = [[NSUserDefaults standardUserDefaults] objectForKey:key];
  1816. //
  1817. // NSString *volumeStr = [volumeDict safeStringForKey:deviceId];
  1818. //
  1819. // if (!volumeStr || ![volumeStr isEqualToString:@"1"]){
  1820. // return;
  1821. // }
  1822. //
  1823. // float volume = [[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
  1824. // HLog(@"FlyElephant-系统音量:%f", volume);
  1825. //
  1826. // if (volume == 0)
  1827. // {
  1828. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:25];
  1829. //
  1830. // [self send_data:dataStr];
  1831. // }
  1832. // else if (volume == 1)
  1833. // {
  1834. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:24];
  1835. //
  1836. // [self send_data:dataStr];
  1837. // }
  1838. }
  1839. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
  1840. if(context == (__bridge void *)[AVAudioSession sharedInstance])
  1841. {
  1842. // /*音量开关打开时 允许发送指令 否则直接返回*/
  1843. // NSDictionary *loginDict = [[UseAccountManage shareInstance] getLoginInfo];
  1844. // NSString *account = [loginDict objectForKey:@"account"];
  1845. // NSString *key = [account stringByAppendingString:Const_Volume_Info_Dict];
  1846. //
  1847. // NSDictionary *volumeDict = [[NSUserDefaults standardUserDefaults] objectForKey:key];
  1848. //
  1849. // NSString *volumeStr = [volumeDict safeStringForKey:deviceId];
  1850. //
  1851. // if (!volumeStr || ![volumeStr isEqualToString:@"1"]){
  1852. // return;
  1853. // }
  1854. //
  1855. // float newValue = [[change objectForKey:@"new"] floatValue];
  1856. // float oldValue = [[change objectForKey:@"old"] floatValue];
  1857. //
  1858. // if (newValue > oldValue)
  1859. // {
  1860. // HLog(@"\n-----音量增加");
  1861. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:24];
  1862. //
  1863. // [self send_data:dataStr];
  1864. // }
  1865. // else
  1866. // {
  1867. // HLog(@"\n-----音量降低");
  1868. // NSString *dataStr = [RCCommandHelp commandBackOrHomeVolum500WithKeyCode:25];
  1869. //
  1870. // [self send_data:dataStr];
  1871. // }
  1872. }
  1873. }
  1874. #pragma mark-----------------------------------------------------------------------------------------------
  1875. #pragma mark - 画面渲染、画面调整相关
  1876. #pragma mark - 更新网络标识 以及自动码率
  1877. - (void)updateAutoRateAndNetWorkStates
  1878. {
  1879. return;//功能未用到
  1880. int audio_time = 0;
  1881. NSDate *nowTime = [NSDate date];
  1882. NSString *nowTimeStr = [NSString stringWithFormat:@"%f", (double)[nowTime timeIntervalSince1970]];
  1883. NSString *lastTimeStr = [NSString stringWithFormat:@"%f", (double)[lastVideoTome timeIntervalSince1970]];
  1884. audio_time = ([nowTimeStr doubleValue] - [lastTimeStr doubleValue]) * 1000;
  1885. lastVideoTome = nowTime;
  1886. static int frameCount = 200;
  1887. if (0 == frameCount)
  1888. {
  1889. frameCount = 200;
  1890. if (audio_time > 500 && !haveBack && self->netWorkStates != 0)
  1891. {
  1892. self->netWorkStates = 0;
  1893. mainBlock(^{
  1894. [self->mPlayerView.controlBtn setBackgroundImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
  1895. });
  1896. }
  1897. else if (audio_time > 100 && !haveBack && self->netWorkStates != 1)
  1898. {
  1899. self->netWorkStates = 1;
  1900. mainBlock(^{
  1901. [self->mPlayerView.controlBtn setBackgroundImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
  1902. });
  1903. }
  1904. else if (!haveBack && self->netWorkStates != 2)
  1905. {
  1906. self->netWorkStates = 2;
  1907. mainBlock(^{
  1908. [self->mPlayerView.controlBtn setBackgroundImage:[UIImage imageNamed:@"you_icon"] forState:(UIControlStateNormal)];
  1909. });
  1910. }
  1911. }
  1912. else
  1913. {
  1914. frameCount--;
  1915. }
  1916. if (delayVideo < audio_time)
  1917. {
  1918. delayVideo = audio_time;
  1919. }
  1920. if (delayVideo < 80)
  1921. {
  1922. okdelayVideo++;
  1923. }
  1924. else
  1925. {
  1926. okdelayVideo = 0;
  1927. }
  1928. if (delayVideo > 120)
  1929. {
  1930. baddelayVideo++;
  1931. }
  1932. havedelayVideoCount++;
  1933. if (havedelayVideoCount % 1000 == 0)
  1934. {
  1935. baddelayVideo = 0;
  1936. }
  1937. if (!haveBack && self->rate == 3) {
  1938. if (baddelayVideo > 10)
  1939. {
  1940. /*降低码率*/
  1941. if (self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/ || self->rateForAuto == BITRATE_WIFI_HD)
  1942. {
  1943. if (self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/) {
  1944. self->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1945. } else {
  1946. self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING;
  1947. }
  1948. }
  1949. else if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/ || self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING)
  1950. {
  1951. self->rateForAuto = BITRATE_EXTREME_SPEED;
  1952. }
  1953. // else if (mySelf->rateForAuto == BITRATE_HIGH_SPEED)
  1954. // {
  1955. // mySelf->rateForAuto = BITRATE_EXTREME_SPEED;
  1956. // NSString *dataStr = [RCCommandHelp commondResolution500WithType:mySelf->rateForAuto];
  1957. // int result = send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  1958. // }
  1959. NSString *dataStr = [RCCommandHelp commandResolution500WithType:self->rateForAuto];
  1960. // send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  1961. [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
  1962. baddelayVideo = 0;
  1963. }
  1964. if (okdelayVideo > 1000)
  1965. {
  1966. /*上升码率*/
  1967. if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/ || self->rateForAuto == BITRATE_WIFI_STANDARD_CLEARING)
  1968. {
  1969. if (self->rateForAuto == BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/) {
  1970. self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING/*BITRATE_HD*/;
  1971. } else {
  1972. self->rateForAuto = BITRATE_WIFI_HD;
  1973. }
  1974. }
  1975. // else if (mySelf->rateForAuto == BITRATE_HIGH_SPEED)
  1976. // {
  1977. // mySelf->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1978. // NSString *dataStr = [RCCommandHelp commondResolution500WithType:mySelf->rateForAuto];
  1979. // int result = send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  1980. // }
  1981. else if (self->rateForAuto == BITRATE_EXTREME_SPEED)
  1982. {
  1983. if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi) {
  1984. self->rateForAuto = BITRATE_WIFI_STANDARD_CLEARING;
  1985. } else {
  1986. self->rateForAuto = BITRATE_EXTREME_SPEED/*BITRATE_STANDARD_CLEARING*/;
  1987. }
  1988. }
  1989. NSString *dataStr = [RCCommandHelp commandResolution500WithType:self->rateForAuto];
  1990. // send_data(mySelf->_ihandle, [dataStr UTF8String], (int)dataStr.length, 10.f);
  1991. [self.liveStreamManager rc_sendJsonData:[dataStr UTF8String]];
  1992. okdelayVideo = 0;
  1993. }
  1994. }
  1995. }
  1996. #pragma mark - opengl渲染
  1997. - (void)showImageOpenglWithCIImage:(CIImage *)ciImage
  1998. {
  1999. if (USELOCALKEYBOARD){
  2000. ;
  2001. }else{
  2002. CGFloat tempRate = ciImage.extent.size.width/ciImage.extent.size.height;
  2003. if (w_h_rate != tempRate)
  2004. {
  2005. // ksharedAppDelegate.couldPhone_W_PHONE = ciImage.extent.size.width;
  2006. // ksharedAppDelegate.couldPhone_H_PHONE = ciImage.extent.size.height;
  2007. w_h_rate = tempRate;
  2008. mainBlock(^{
  2009. [self updatePlayViewRate:tempRate];
  2010. });
  2011. }
  2012. }
  2013. [mPlayerView glkShowImage:ciImage];
  2014. }
  2015. #pragma mark - UIImageView渲染
  2016. - (void)showImageUIImageViewWithCIImage:(CIImage *)ciImage pixelBufferRef:(CVPixelBufferRef)pixelBuff1
  2017. {
  2018. CGImageRef videoImage = [videoContext createCGImage:ciImage fromRect:CGRectMake(0, 0, CVPixelBufferGetWidth(pixelBuff1), CVPixelBufferGetHeight(pixelBuff1))];
  2019. UIImage *image = [UIImage imageWithCGImage:videoImage];
  2020. CGFloat tempRate = image.size.width/image.size.height;
  2021. mainBlock(^{
  2022. if (image)
  2023. {
  2024. if (USELOCALKEYBOARD){
  2025. ;
  2026. }else{
  2027. if (w_h_rate != tempRate)
  2028. {
  2029. // ksharedAppDelegate.couldPhone_W_PHONE = ciImage.extent.size.width;
  2030. // ksharedAppDelegate.couldPhone_H_PHONE = ciImage.extent.size.height;
  2031. [self updatePlayViewRate:tempRate];
  2032. }
  2033. }
  2034. self->mPlayerView.showImageView.image = image;
  2035. }
  2036. });
  2037. CGImageRelease(videoImage);
  2038. }
  2039. #pragma mark -- /*画面布局调整*/
  2040. - (void)updatePlayViewRate:(CGFloat)tempRate
  2041. {
  2042. /*设置横竖屏*/
  2043. if (tempRate > 1) {/*横屏*/
  2044. [self setDeviceOrientation:(UIDeviceOrientationLandscapeRight)];
  2045. [mPlayerView setLanMas_makeWithImageRate:tempRate isOpenVirtual:YES isUsageMode:NO];
  2046. }else{/*竖屏*/
  2047. [self setDeviceOrientation:(UIDeviceOrientationPortrait)];
  2048. [mPlayerView setPoMas_makeWithImageRate:tempRate isOpenVirtual:YES isUsageMode:NO];
  2049. }
  2050. }
  2051. #pragma mark------------------------------------------------------------------------------------------------------------------
  2052. #pragma mark-提示 loading 相关
  2053. #pragma mark-添加带有文字loading
  2054. - (void)addLoadingWithTipsView:(NSString *)tipsStr
  2055. {
  2056. if (loadingWithTipsView)
  2057. {
  2058. [loadingWithTipsView removeFromSuperview];
  2059. loadingWithTipsView = nil;
  2060. }
  2061. loadingWithTipsView = [self loadingViewWithTipsStr:tipsStr];
  2062. [self.view addSubview:loadingWithTipsView];
  2063. }
  2064. - (void)removeLoadingWithTipsView
  2065. {
  2066. if (loadingWithTipsView)
  2067. {
  2068. [loadingWithTipsView removeFromSuperview];
  2069. loadingWithTipsView = nil;
  2070. }
  2071. }
  2072. - (UIView *)loadingViewWithTipsStr:(NSString*)tipsStr
  2073. {
  2074. UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
  2075. [bgView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
  2076. FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"loadingWhiteGif" withExtension:@"gif"]]];
  2077. FLAnimatedImageView *upView = [[FLAnimatedImageView alloc] init];
  2078. [upView setFrame:CGRectMake((SCREEN_W - 65.f)/2.f, (SCREEN_H - 65.f)/2.f, 65.f, 65.f)];
  2079. [upView setContentMode:UIViewContentModeScaleAspectFill];
  2080. [upView setBackgroundColor:[ UIColor clearColor]];
  2081. upView.animatedImage = image;
  2082. [bgView addSubview:upView];
  2083. /*标签文字*/
  2084. 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)];
  2085. [tipsLabel setText:tipsStr];
  2086. [tipsLabel setBackgroundColor:[UIColor clearColor]];
  2087. [tipsLabel setTextColor:[UIColor whiteColor]];
  2088. [tipsLabel setFont:[UIFont systemFontOfSize:14.f]];
  2089. [tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
  2090. [bgView addSubview:tipsLabel];
  2091. return bgView;
  2092. }
  2093. #pragma mark-添加loading
  2094. -(void)showNewIndicator
  2095. {
  2096. dispatch_async(dispatch_get_main_queue(), ^{
  2097. if (self->wattingView == nil)
  2098. {
  2099. HLog(@"Tan +++++开");
  2100. self->wattingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
  2101. [self->wattingView setBackgroundColor:RGBACOLOR(0.f, 0.f, 0.f, 0.7)];
  2102. [self->wattingView.layer setCornerRadius:10.f];
  2103. self->wattingView.center = [[UIApplication sharedApplication] keyWindow].center;// 将wattingVideoImageindicator放于播放画面的中央位置
  2104. self->wattingView.hidden = NO;
  2105. FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"loadingWhiteGif" withExtension:@"gif"]]];
  2106. FLAnimatedImageView *upView = [[FLAnimatedImageView alloc] init];
  2107. [upView setFrame:CGRectMake((100 - 65.f)/2.f, (100 - 65.f)/2.f, 65.f, 65.f)];
  2108. [upView setContentMode:UIViewContentModeScaleAspectFill];
  2109. [upView setBackgroundColor:[ UIColor clearColor]];
  2110. upView.animatedImage = image;
  2111. [self->wattingView addSubview:upView];
  2112. [self->mPlayerView addSubview:self->wattingView];
  2113. }
  2114. });
  2115. }
  2116. -(void)removeNewIndicator
  2117. {
  2118. if (self->wattingView != nil)
  2119. {
  2120. [[self->wattingView viewWithTag:1111].layer removeAllAnimations];
  2121. self->wattingView.hidden = YES;
  2122. [self->wattingView removeFromSuperview];
  2123. self->wattingView = nil;
  2124. }
  2125. }
  2126. #pragma mark 定时器
  2127. - (void)setTimerCountDown {
  2128. HLog(@"开启一个");
  2129. if (_timer) {
  2130. // 取消定时器
  2131. [self cancelTimer];
  2132. }
  2133. // 初始化值计时数据
  2134. self.adjustTime = 3;
  2135. self.concentTime = [iTools getNowTimeStamp];
  2136. self.currentTime = 0;
  2137. self.webSocketTime = 0;
  2138. self.webSocketTaskTime = 0;
  2139. _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
  2140. [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
  2141. }
  2142. - (void)cancelTimer {
  2143. // 取消定时器
  2144. if(_timer){
  2145. [_timer invalidate];
  2146. _timer = nil;
  2147. }
  2148. }
  2149. - (void)timerChange {
  2150. //self.currentTime++;// 0、定时器计数
  2151. //HLog(@"111111111111111");
  2152. [self extensionAdjustBtnFrameCheckAdjustTime];// 1、悬浮球3s后 自动靠边隐藏
  2153. [self checkConcentTime];// 3、30s之后 没有收到拉流数据 自动断开链接
  2154. }
  2155. // 3、30s之后 没有收到拉流数据 自动断开链接
  2156. - (void)checkConcentTime {
  2157. NSInteger now = [iTools getNowTimeStamp];
  2158. NSInteger timeDiff = now - self.concentTime; // 渲染时间与当前时间 时间差
  2159. if (self.concentTime == 0) { //云手机未连接成功
  2160. HLog(@"云手机未连接成功");
  2161. }else if (timeDiff >= 30) { // 30s 无渲染数据
  2162. if(!_needToDissconnectType && !_isLoginAgainType && [self isPlayerViewIsTopVCFun]){
  2163. HLog(@"云手机30s 无渲染数据 自动断开连接");
  2164. self.concentTime = [iTools getNowTimeStamp];
  2165. //这个赋值不是真的链接中 应该是失联了
  2166. RCLiveSteamlinkState = ConnectStateConnecting;
  2167. [self showNewIndicator];
  2168. [self tryAgain];
  2169. }
  2170. // else if(self.webSocketConcentTime > 0){
  2171. // //后续要跟进
  2172. //
  2173. // if(_isFirstEnterPhone){
  2174. // HLog(@"\n\n\n\n\n 云手机30s 无渲染数据 要跟进 \n\n\n\n\n");
  2175. // [self showNetErrorAlertFun:3];
  2176. // }
  2177. // }
  2178. /*弹窗提示*/
  2179. }else {
  2180. // HLog(@"云手机渲染数据时间差:%zd", timeDiff);
  2181. }
  2182. }
  2183. #pragma mark - 提示框
  2184. - (void)showAlertWithTitle:(NSAttributedString*_Nullable)atbTitle
  2185. message:(NSAttributedString*_Nullable)atbmessage
  2186. tilteAlignment:(NSTextAlignment)tilteAlignment
  2187. messageAlignment:(NSTextAlignment)messageAlignment
  2188. sureAction:(UIAlertAction*_Nullable)sureAction
  2189. cancelAction:(UIAlertAction*_Nullable)cancelAction
  2190. {
  2191. // 当前控制器是UIAlertController 退出
  2192. UIViewController *currentVC = [[ShortcutManager shareInstance] findCurrentShowingViewController];
  2193. if ([currentVC isKindOfClass:[UIAlertController class]]) {
  2194. //获得极致体验服务 请购买云手机(不退出 优先级最高)
  2195. UIAlertController *alertVC = (UIAlertController *)currentVC;
  2196. NSMutableAttributedString *attriMsg = [alertVC valueForKey:@"_attributedMessage"];
  2197. if ([attriMsg.string containsString:@"获得极致体验服务"]) {
  2198. return;
  2199. }
  2200. HLog(@"%@",attriMsg.string);
  2201. [currentVC dismissViewControllerAnimated:NO completion:nil];
  2202. }
  2203. self.alertController = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  2204. if (atbTitle)
  2205. {
  2206. [self.alertController setValue:atbTitle forKey:@"_attributedTitle"];
  2207. }
  2208. if (atbmessage)
  2209. {
  2210. [self.alertController setValue:atbmessage forKey:@"_attributedMessage"];
  2211. }
  2212. UIView *subView1 = self.alertController.view.subviews[0];
  2213. if (subView1 && [subView1 subviews])
  2214. {
  2215. UIView *subView2 = subView1.subviews[0];
  2216. if (subView2 && [subView2 subviews])
  2217. {
  2218. UIView *subView3 = subView2.subviews[0];
  2219. if (subView3 && [subView3 subviews])
  2220. {
  2221. UIView *subView4 = subView3.subviews[0];
  2222. if (subView4 && [subView4 subviews])
  2223. {
  2224. UIView *subView5 = subView4.subviews[0];
  2225. if (subView5 && [[subView5 subviews] count] > 1)
  2226. {
  2227. for (UIView *msg in subView5.subviews)
  2228. {
  2229. if ([msg isKindOfClass:[UILabel class]])
  2230. {
  2231. NSArray *trmp = [self getAllIvar:msg];
  2232. for (NSDictionary *dict in trmp)
  2233. {
  2234. if ([[dict allKeys] containsObject:@"_content"])
  2235. {
  2236. NSAttributedString *dsfds = [dict objectForKey:@"_content"];
  2237. if ([atbTitle.string isEqualToString:dsfds.string])
  2238. {
  2239. [(UILabel*)msg setTextAlignment:(tilteAlignment)];
  2240. }
  2241. else if ([atbmessage.string isEqualToString:dsfds.string])
  2242. {
  2243. if (((UILabel*)msg).numberOfLines == 0)
  2244. {
  2245. [(UILabel*)msg setTextAlignment:(messageAlignment)];
  2246. }
  2247. else if (((UILabel*)msg).numberOfLines == 1)
  2248. {
  2249. [(UILabel*)msg setTextAlignment:NSTextAlignmentCenter];
  2250. }
  2251. else
  2252. {
  2253. [(UILabel*)msg setTextAlignment:(NSTextAlignmentCenter)];
  2254. }
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. }
  2261. }
  2262. }
  2263. }
  2264. }
  2265. if (sureAction)
  2266. {
  2267. [self.alertController addAction:sureAction];
  2268. }
  2269. if (cancelAction)
  2270. {
  2271. [self.alertController addAction:cancelAction];
  2272. }
  2273. // 弹窗边框
  2274. UIView *subview = self.alertController.view.subviews.firstObject;
  2275. UIView *alertContentView = subview.subviews.firstObject;
  2276. alertContentView.layer.cornerRadius = 10;
  2277. // alertContentView.layer.masksToBounds = YES;
  2278. alertContentView.layer.shadowColor = [UIColor colorWithRed:30/255.0 green:32/255.0 blue:34/255.0 alpha:1.0].CGColor;
  2279. alertContentView.layer.shadowOffset = CGSizeMake(0,0);
  2280. alertContentView.layer.shadowOpacity = 1;
  2281. alertContentView.layer.shadowRadius = 7;
  2282. // 弹窗背景颜色
  2283. if (@available(iOS 13.0, *)) {
  2284. self.alertController.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
  2285. }
  2286. [self presentViewController:self.alertController animated:YES completion:nil];
  2287. }
  2288. #pragma mark - 屏幕旋转相关
  2289. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  2290. return UIInterfaceOrientationPortrait;
  2291. }
  2292. - (BOOL)shouldAutorotate {
  2293. if (canRate)/*画面发现变化 状态变为YES*/
  2294. {
  2295. canRate = NO;/*关键点 只能旋转一次*/
  2296. return YES;
  2297. }
  2298. //是否允许转屏
  2299. return NO;/*平时禁止*/
  2300. }
  2301. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  2302. return
  2303. UIInterfaceOrientationMaskPortrait |
  2304. UIInterfaceOrientationMaskLandscapeLeft |
  2305. UIInterfaceOrientationMaskLandscapeRight;
  2306. }
  2307. #pragma mark -- /* 屏幕旋转通知接收函数*/
  2308. - (void)orientationChanged:(NSNotification *)notification
  2309. {
  2310. //KyoLog(@"rotated");
  2311. }
  2312. - (void)setDeviceOrientation:(UIDeviceOrientation)orientationPortrait
  2313. {
  2314. mainBlock(^{
  2315. UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
  2316. //isPortraitMode
  2317. BOOL ScreenMode = ((UIDeviceOrientation)orientation == orientationPortrait);
  2318. NSNumber *value = nil;
  2319. if (ScreenMode)
  2320. {
  2321. }
  2322. else
  2323. {
  2324. self.adjustTime = 3;
  2325. if (orientationPortrait == UIDeviceOrientationLandscapeLeft){
  2326. [self->mPlayerView setLanMas_makeWithImageRate:16.0/9.0 isOpenVirtual:YES isUsageMode:NO];
  2327. // [self.basebgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  2328. // make.left.mas_equalTo(0);
  2329. // make.right.mas_equalTo(0);
  2330. // make.top.mas_equalTo(0);
  2331. // make.bottom.mas_equalTo(0);
  2332. // }];
  2333. /*悬浮按钮旋转*/
  2334. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  2335. [self reSetPlayerViewFloatBtnFrame];
  2336. });
  2337. [self->mPlayerView.controlBtn setHidden:NO];
  2338. }else{
  2339. [self->mPlayerView setPoMas_makeWithImageRate:9.0/16.0 isOpenVirtual:YES isUsageMode:NO];
  2340. // [self.basebgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  2341. // make.left.mas_equalTo(0);
  2342. // make.right.mas_equalTo(0);
  2343. // make.top.mas_equalTo(0);
  2344. // make.bottom.mas_equalTo(0);
  2345. // }];
  2346. }
  2347. self->canRate = YES;/*关键点 设置临时允许*/
  2348. value = [NSNumber numberWithInteger:orientationPortrait];//横竖屏值设置
  2349. [[UIDevice currentDevice] setValue:value forKey:@"orientation"];/*先将状态栏旋转(影响系统通知弹框方向)*/
  2350. [[NSNotificationCenter defaultCenter] postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];/*发送通知*/
  2351. }
  2352. });
  2353. }
  2354. /*切换连接方式*/
  2355. - (void)connectTypeChange{
  2356. [self reconnectDevice];
  2357. }
  2358. #pragma mark - UITextFieldDelegate 透传输入法委托
  2359. //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  2360. //
  2361. // /*长度为0时表示删除内容*/
  2362. // if (string.length > 0){
  2363. // NSString *replaceStr = [textField.text substringWithRange:range];
  2364. // HLog(@"\n000000要增加的文字:--%@-------",replaceStr);
  2365. // replaceStr = [replaceStr stringByReplacingOccurrencesOfString:@" " withString:@""];
  2366. // HLog(@"\n111111要增加的文字:--%@-------",replaceStr);
  2367. // for (NSInteger nFori = 0; nFori < replaceStr.length; nFori++) {
  2368. // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
  2369. // [self.businessCommandChannelManager rc_sendData:dataStr];
  2370. // }
  2371. // HLog(@"\n-----输入内容:--%@-------",string);
  2372. // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:string];
  2373. // [self.businessCommandChannelManager rc_sendData:dataStr];
  2374. // }
  2375. // else{
  2376. // HLog(@"\n-----删除:--%ld-------",range.length);
  2377. // NSInteger needDeleteLength = range.length;
  2378. // for (NSInteger nFori = 0; nFori < needDeleteLength; nFori++) {
  2379. // NSString *dataStr = [RCCommandHelp commandKeyboadInputStr:nil];
  2380. // [self.businessCommandChannelManager rc_sendData:dataStr];
  2381. //
  2382. // /*初始内容无法删除问题处理*/
  2383. // hidenTextField.text = @"1234";
  2384. // hidenTextFieldOldStr = @"1234";
  2385. //
  2386. // /*如果两者内容差距较大 是否会有删除后出现两者内容不一样的情况*/
  2387. // if (![hidenTextField.text isEqualToString:hidenTextFieldOldStr]){
  2388. // /*两者不相等时需要做等值处理*/
  2389. // hidenTextFieldOldStr = hidenTextField.text;
  2390. // }
  2391. // }
  2392. // }
  2393. //
  2394. // return YES;
  2395. //}
  2396. - (void)textFieldDidEndEditing:(UITextField *)textField{
  2397. HLog(@"\n-----输入法透传 1111111 关闭键盘-------");
  2398. NSString *dataStr = [RCCommandHelp commandClosePhoneKeyboad];
  2399. //[self.businessCommandChannelManager rc_sendData:dataStr];
  2400. }
  2401. -(BOOL)prefersHomeIndicatorAutoHidden {
  2402. return YES;
  2403. }
  2404. - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls
  2405. {
  2406. [self documentPicker:controller didPickDocumentsAtURLs:urls];
  2407. }
  2408. @end