// // IfishP2PMonitorController.m // IfihYooeeDemo // // Created by imac on 16/6/7. // Copyright © 2016年 xiang. All rights reserved. // #import "IfishP2PMonitorController.h" #import #import #import #import "P2PClient.h" #import "Toast+UIView.h" #import "AppDelegate.h" //#import "PAIOUnit.h" #import "UDManager.h" #import "Utils.h" #import "TouchButton.h" #import "ContactDAO.h" #import "FListManager.h" #import "Contact.h" #import "UDPManager.h"//rtsp监控界面弹出修改 #import "LocalDevice.h"//rtsp监控界面弹出修改 #import "CustomTopBar.h" #define MAX_VIDEO_RES_SIZE ((1920+32)*1088) #define DeviceId @"3157838" #define DevicePw @"616657769" #import "ShotScreenImgViewController.h" #import "UserModel.h" #import "DeviceCameraModel.h" #import "SetTimeController.h" #import "NoneControlNonetimerViewController.h" #import "TwoControlSetTimeViewController.h" #import "TwoControlnoneTimerViewController.h" #import "TwoControlNinetyninebiteViewController.h" #import "XuToSetViewController.h" #import "XuToLightModel.h" #import "XuToWenDuPicview.h" #import "JiaReWenDuModel.h" #import "FourControlSetViewController.h" #import "IfishMianTabViewController.h" #import "ScanViewController.h" #import "SetNameTextViewController.h" #import "SongNuoSetViewController.h" #import "KeLiAiSetViewController.h" #import "LXADViewTool.h" #import "MineKanHuViewController.h" #import "IfishKanHuServiceViewController.h" #import "LoveFishLiveListBaseViewController.h" #import "MineKankanEditViewController.h" #import "CameraRecordViewController.h" #import "IfishP2PPlayBackListViewController.h" #import "YMsgBox.h" #import "P2PPlaybackController.h" #import "IfishDeviceInfo.h" #import "RusunHaveHeateSetViewController.h" #import "KanHuFuWuViewController.h" //#import "IfishSelectCardViewController.h" #import "IfishBindDeviceSelectViewController.h" #import "MinekanHuNotSelectShopController.h" #import #import "RunSun84CHSetViewController.h" #import "HaveHotCoolWenDuPicview.h" #import "RuSunLightOrder.h" #import "RuiMeiSetViewController.h" //上部分视频封装 下部分分段控制器 封装 (下一步代码优化) @interface IfishP2PMonitorController () { CGFloat _horizontalScreenH; CGFloat _monitorInterfaceW;//rtsp监控界面弹出修改 CGFloat _monitorInterfaceH;//rtsp监控界面弹出修改 UIButton* _btnDefence; BOOL _isPlaying; BOOL _isOkFirstRenderVideoFrame;//YES表示第一次成功渲染图像 BOOL _isOkRenderVideoFrame;//YES表示图像渲染出来了 BOOL _isCanAutoOrientation;//限制屏幕什么时候可以旋转 BOOL _isInItDevice; //是否连接设备 BOOL _isStop;//是否暂停 用于区分是 暂停按钮 还是 连接失败按钮 dispatch_queue_t _xutoMainQueue; BOOL _isPushNextView; //是否push下级界面 } @property(nonatomic,strong) SetTimeController*SetTimeVC; @property(nonatomic,strong) NoneControlNonetimerViewController*noncontrolnonetimerVC; @property(nonatomic,strong) TwoControlSetTimeViewController *twoControlSetTimeVC; @property(nonatomic,strong) TwoControlnoneTimerViewController *twocontrolNonetimerVC; @property(nonatomic,strong) TwoControlNinetyninebiteViewController * twoControlNinetyninebiteVC; @property(nonatomic,strong) XuToSetViewController *xuToSetVC; //无制冷加热 @property(nonatomic,strong) XuToWenDuPicview *wenduPicview; //有制冷加热 @property(nonatomic,strong) HaveHotCoolWenDuPicview *ruSunPicview; @property(nonatomic,strong) FourControlSetViewController *forControlSetVC; @property(nonatomic,strong) SongNuoSetViewController *songNuoSetVC; @property(nonatomic,strong) KeLiAiSetViewController *keLiAiSetVc; @property(nonatomic,strong) RusunHaveHeateSetViewController *rusunSet; @property(nonatomic,strong) RunSun84CHSetViewController *rusun84Set; @property (nonatomic, strong) RuiMeiSetViewController *ruimeiSet; @property(nonatomic,strong) DXPopover *popover; @property(nonatomic,strong) UIButton *rightPopButton; @property (nonatomic,strong) SetNameTextViewController *setNameVC; @property (nonatomic,strong) NSString *xinName; @property (nonatomic,strong) UILabel *nameTitle; @property (strong, nonatomic) UIView *shutterView; @end extern BOOL formLogIn;//连接页面是否来自登录界面 BOOL isfromCameraView;//未绑定鱼缸时,去绑定鱼缸 判断是否从摄像头界面进入 @implementation IfishP2PMonitorController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization _isPlaying = NO; } return self; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //跳转到录制界面会将cameraHViewDelegate 置nil _bottomToolHView.cameraHViewDelegate=self; //扫码激活用 更新isActive //屏幕长亮 [[ UIApplication sharedApplication] setIdleTimerDisabled:YES]; NSArray *yooseeDeviceArr = [[DataCenter defaultDtacenter] valueForKey:@"cameraArr"]; for (IfishCameraModel *camera in yooseeDeviceArr) { if ([camera.cameraId isEqualToString:self.contact.cameraId]) { self.contact = camera; } } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveRemoteMessage:) name:RECEIVE_REMOTE_MESSAGE object:nil]; [self.bottomToolHView addObViserFromSelf]; self.navigationController.navigationBarHidden = NO; _isCanAutoOrientation = YES; //设置默认竖屏 [[AppDelegate sharedDefault] application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[AppDelegate sharedDefault].window]; //先判断是否授权 if (!self.contact.isActive) { [self.view makeToast:@"设备无授权字段"]; return; } if ([self.contact.isActive isEqualToString:@"1"]) { [self cameraConnectSeting]; }else if ([self.contact.isActive isEqualToString:@"0"]){ [[P2PClient sharedClient] setDelegate:self]; UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"请扫描产品外包装上的激活码来激活摄像头" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前往扫描", nil]; alert.tag = WEIJIHUO_ALERT; [alert show]; } } //加tab 栏后新增 -(void)cameraConnectSeting{ //rtsp监控界面弹出修改 [self monitorP2PCall]; //设置代理 [[P2PClient sharedClient] setDelegate:self]; if (_isPushNextView) { return; } [self hiddenMonitoringUI:NO callErrorInfo:nil isReCall:YES]; } -(void)viewDidAppear:(BOOL)animated{ } -(void)testNetStatusByAF{ [[AFNetworkReachabilityManager sharedManager] startMonitoring]; [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { NSLog(@"%ld", (long)status); switch (status) { case AFNetworkReachabilityStatusUnknown: NSLog(@"未知"); [self.view makeToast:@"当前网络环境:未知,请检查网络"]; break; case AFNetworkReachabilityStatusNotReachable: NSLog(@"无连接"); //self.netStateLabel.text = @"当前网络环境:无网络,请检查网络"; [self.view makeToast:@"当前网络环境:无网络,请检查网络"]; break; case AFNetworkReachabilityStatusReachableViaWWAN: //self.netStateLabel.text = @"当前网络环境:3/4G,建议切换到WiFi"; [self.view makeToast:@"当前网络环境:3/4G,建议切换到WiFi"]; NSLog(@"2/3G"); break; case AFNetworkReachabilityStatusReachableViaWiFi: NSLog(@"Wifi"); //self.netStateLabel.text = @"当前网络环境:WiFi,请放心观看"; [self.view makeToast:@"当前网络环境:WiFi,请放心观看"]; break; default: break; } }]; } -(void)initWIFIString{ } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; //屏幕长亮关闭 [[ UIApplication sharedApplication] setIdleTimerDisabled:NO]; [AppDelegate sharedDefault].canFullScreen = NO; self.isReject = YES; [[UIApplication sharedApplication] setStatusBarHidden:NO]; if (self.isFullScreen){ if (self.scrollView){ [self.scrollView setZoomScale:1.0]; } } //[self.remoteView setCaptureFinishScreen:YES]; [[NSNotificationCenter defaultCenter] removeObserver:self name:RECEIVE_REMOTE_MESSAGE object:nil]; [self.bottomToolHView removeObViserFromSelf]; } - (void)viewDidLoad { [super viewDidLoad]; [self testNetStatusByAF]; self.isShowControllerBar = YES; self.isVideoModeHD = NO; _isReject=YES; _isStop = NO; _isOkFirstRenderVideoFrame = YES; _isPushNextView = NO; //监控竖屏时,各控件初始化(先) [self initComponentForPortrait]; //监控横屏时,各控件初始化(后) [self initComponentForHorizontalScreen]; if ([self.contact.isActive isEqualToString:@"1"]) { [self connectDevice]; }else{ [self.yProgressView stop]; } } #pragma mark - 初始化设备 p2pConnect -(void)connectDevice{ //LoginResult *loginResult = [UDManager getLoginInfo]; //8225账号 // NSString * P2PVerifyCode1 = @"1528438234"; // NSString * P2PVerifyCode2 = @"992805759"; // NSString *UserID = @"-2144354932"; UserModel *model=[[DataCenter defaultDtacenter] valueForKey:@"UserLogIn"]; NSString *userIDName=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff]; //初始化设备 if (!_isInItDevice) { NSLog(@"正在初始化设备"); _isInItDevice = [[P2PClient sharedClient] p2pConnectWithId:userIDName codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2]; // _isInItDevice = [[P2PClient sharedClient] p2pConnectWithId:model.gwellUserID codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2]; } if(_isInItDevice){ NSLog(@"p2pConnect success. 成功 可以操作设备了"); //成功 可以操作设备了 usleep(600000); [self startMonitor]; }else{//new added NSLog(@"p2pConnect failure.失败,不能操作设备"); //[self connectDevice]; return; } } -(void)startMonitor{ if (_isReject&&_isInItDevice) { NSLog(@"发送呼叫命令"); [[P2PClient sharedClient] setIsBCalled:NO]; [[P2PClient sharedClient] setP2pCallState:P2PCALL_STATUS_CALLING]; //Contact *contact = self.deviceArr[0]; [[P2PClient sharedClient] p2pCallWithId:self.contact.cameraId password:self.contact.cameraPass callType:P2PCALL_TYPE_MONITOR]; NSLog(@"contact.contactPassword%@",self.contact.cameraPass); } } #pragma mark - 协议的实现 - (void)P2PClientCalling:(nullable NSDictionary*)info{ NSLog(@"正在呼叫"); } - (void)P2PClientReject:(nullable NSDictionary*)info{ _isReject=YES; _isOkRenderVideoFrame = NO; NSLog(@"视频挂断"); //[self addLogs:@"视频挂断"]; while (_isPlaying) { usleep(50*1000); } if (self.isIntoMonitorFromMonitor) { self.isIntoMonitorFromMonitor = NO; [self hiddenMonitoringUI:NO callErrorInfo:nil isReCall:YES]; // [self monitorP2PCall]; }else{ [self hiddenMonitoringUI:NO callErrorInfo:info isReCall:NO]; } } - (void)P2PClientAccept:(nullable NSDictionary*)info{ NSLog(@"接收数据"); } - (void)P2PClientReady:(nullable NSDictionary*)info{ NSLog(@"准备就绪"); [[P2PClient sharedClient] setP2pCallState:P2PCALL_STATUS_READY_P2P]; if([[P2PClient sharedClient] p2pCallType]==P2PCALL_TYPE_MONITOR){ //连接就绪之后就开始启动渲染 [self monitorStartRender]; } } #pragma mark - 准备渲染监控界面 -(void)monitorStartRender{ //[self addLogs:@"渲染>>>你可以看到画面了"]; _isReject = NO; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self renderView]; }); //[[PAIOUnit sharedUnit] setMuteAudio:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; } #pragma mark - 监控竖屏时,各控件初始化 #define BOTTOM_BAR_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 95.0:50.0) #define PRESS_LAYOUT_WIDTH_AND_HEIGHT 38 #define CONTROLLER_BTN_COUNT 5 #define PUBLIC_WIDTH_OR_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 95.0:50.0) #define CONTROLLER_BTN_H_W (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 70.0:40.0) //布防、声音...高度宽度 #define RESOLUTION_BTN_H (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 44.0:30.0) //分辨率按钮高度 #define CONTROLLER_RIGHT_ITEM_WIDTH 70 #define CONTROLLER_RIGHT_ITEM_HEIGHT 40 #define CONTROLLER_LEFT_ITEM_WIDTH 20 #define CONTROLLER_BTN_TAG_HUNGUP 0 #define CONTROLLER_BTN_TAG_SOUND 1 #define CONTROLLER_BTN_TAG_SCREENSHOT 2 #define CONTROLLER_BTN_TAG_PRESS_TALK 3 #define CONTROLLER_BTN_TAG_DEFENCE_LOCK 4 #define CONTROLLER_BTN_TAG_HD 5 #define CONTROLLER_BTN_TAG_SD 6 #define CONTROLLER_BTN_TAG_LD 7 #define CONTROLLER_BTN_TAG_RESOLUTION 8 #define CONTROLLER_LABEL_TAG_HD 10 #define CONTROLLER_LABEL_TAG_SD 11 #define CONTROLLER_LABEL_TAG_LD 12 #define CONTROLLER_BTN_TAG_GPIO1_0 13 //lock #define LEFTVIEW_WIDTH (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 88:88) #define LEFTVIEW_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 120:120) #define CUSTOM_BORDER_BUTTON_WIDTH 20 #define CUSTOM_BORDER_BUTTON_HEIGHT 45 #define LEFT_BAR_BTN_WIDTH (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 90:60) #define LEFT_BAR_BTN_MARGIN (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 15:10) #define LOADINGPRESSVIEW_WIDTH_HEIGHT (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 50:80) -(void)initComponentForPortrait{ //view的背景颜色 [self.view setBackgroundColor:RGB(242, 242, 242)]; //显示状态栏 [[UIApplication sharedApplication] setStatusBarHidden:NO]; //取得竖屏的rect CGRect rect = [AppDelegate getScreenSize:YES isHorizontal:NO]; CGFloat width = rect.size.width; CGFloat height = rect.size.height; if(CURRENT_VERSION<7.0){ height +=20; } //导航栏 NSString *deviceName = [NSString stringWithFormat:@"%@",self.contact.showName]; [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault]; UIButton*leftBtn = [UIButton buttonWithType:UIButtonTypeCustom]; leftBtn.frame = CGRectMake(0, 0, 47,44); [leftBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal]; [leftBtn addTarget: self action: @selector(btnClickToBack:) forControlEvents: UIControlEventTouchUpInside]; UIBarButtonItem * lbbItem=[[UIBarButtonItem alloc]initWithCustomView:leftBtn]; self.navigationItem.leftBarButtonItem=lbbItem; //视频监控连接中的标题 self.nameTitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 44)]; self.nameTitle.text=deviceName; self.nameTitle.textAlignment=NSTextAlignmentCenter; self.nameTitle.textColor=[UIColor whiteColor]; self.navigationItem.titleView=self.nameTitle; //右侧下拉菜单 UIButton*rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; rightButton.frame = CGRectMake(0, 0, 60, 44); [rightButton setImage:[UIImage imageNamed:@"ifishnav_dropview_list"] forState:UIControlStateNormal]; [rightButton addTarget:self action:@selector(popAppear) forControlEvents:UIControlEventTouchUpInside]; self.rightPopButton = rightButton; [self.rightPopButton setImageEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)]; UIBarButtonItem*rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.rightPopButton]; self.navigationItem.rightBarButtonItem = rightItem; //显示监控画面的载体canvasView CGFloat canvasView_h = [UIScreen mainScreen].bounds.size.width * 9/16; UIView *canvasView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, width, canvasView_h)]; canvasView.backgroundColor = [UIColor blackColor]; [self.view addSubview:canvasView]; self.canvasView = canvasView; self.canvasframe = canvasView.frame; //视频监控连接中的背景图片 NSString *filePath = [Utils getHeaderFilePathWithId:self.contact.cameraId]; UIImage *headImg = [UIImage imageWithContentsOfFile:filePath]; if(headImg==nil){ headImg = LXImageWithImageName(@"ic_header.png"); } self.canvasView.layer.contents = (id)headImg.CGImage; //视频监控连接中或者连接失败的文字提示,以及旋转或者重连图片 UIButton *promptButton = [UIButton buttonWithType:UIButtonTypeCustom]; promptButton.frame = CGRectMake(0.0, 0.0, self.canvasView.frame.size.width, self.canvasView.frame.size.height); promptButton.backgroundColor = [UIColor clearColor]; promptButton.tag = PROMPT_BUTTON_TAG; [promptButton addTarget:self action:@selector(onVerticalBtnPress:) forControlEvents:UIControlEventTouchUpInside]; [self.canvasView addSubview:promptButton]; self.promptButton = promptButton; //文字frame NSString *labelTipText = [NSString stringWithFormat:@"%@",NSLocalizedString(@"玩命加载中...", nil)]; CGSize size = [labelTipText sizeWithFont:XFontBold_16]; CGFloat labelTip_w = size.width+10.0; CGFloat labelTip_h = size.height; //图片frame CGFloat progressView_wh = LOADINGPRESSVIEW_WIDTH_HEIGHT; CGFloat progressView_y = (self.canvasView.frame.size.height-labelTip_h-progressView_wh)/2; // 旋转或者重连图片 或者开始监控图片 ProgressImageView *progressView = [[ProgressImageView alloc] initWithFrame:CGRectMake((width-progressView_wh)/2, progressView_y, progressView_wh, progressView_wh)]; progressView.backgroundView.image = LXImageWithImageName(@"monitor_press.png"); [self.promptButton addSubview:progressView]; [progressView start]; self.yProgressView = progressView; //视频监控连接中或者连接失败的文字提示 UILabel* labelTip = [[UILabel alloc] initWithFrame:CGRectMake((width-labelTip_w)/2, progressView_y+progressView_wh, labelTip_w, labelTip_h)]; labelTip.backgroundColor = [UIColor clearColor]; labelTip.text = [NSString stringWithFormat:@"%@",NSLocalizedString(@"monitor_out_prompt", nil)]; labelTip.textAlignment = NSTextAlignmentCenter; labelTip.font = XFontBold_16; labelTip.textColor = XWhite; //打开可以显示监控连接中或者连接失败的文字提示 // [self.promptButton addSubview:labelTip]; self.labelTip = labelTip; //显示监控的画布OpenGLView OpenGLView *glView = [[OpenGLView alloc] init]; glView.frame = CGRectMake(0.0, 0.0, self.canvasView.frame.size.width, self.canvasView.frame.size.height); self.remoteView = glView; self.remoteView.delegate = self; [self.remoteView.layer setMasksToBounds:YES]; [self.canvasView addSubview:self.remoteView]; //上划手势 UISwipeGestureRecognizer *swipeGestureUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUp:)]; [swipeGestureUp setDirection:UISwipeGestureRecognizerDirectionUp]; [swipeGestureUp setCancelsTouchesInView:YES]; [swipeGestureUp setDelaysTouchesEnded:YES]; //[_remoteView addGestureRecognizer:swipeGestureUp]; //下划手势 UISwipeGestureRecognizer *swipeGestureDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)]; [swipeGestureDown setDirection:UISwipeGestureRecognizerDirectionDown]; [swipeGestureDown setCancelsTouchesInView:YES]; [swipeGestureDown setDelaysTouchesEnded:YES]; // [_remoteView addGestureRecognizer:swipeGestureDown]; //左划手势 UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)]; [swipeGestureLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; [swipeGestureLeft setCancelsTouchesInView:YES]; [swipeGestureLeft setDelaysTouchesEnded:YES]; //[_remoteView addGestureRecognizer:swipeGestureLeft]; //右划手势 UISwipeGestureRecognizer *swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)]; [swipeGestureRight setDirection:UISwipeGestureRecognizerDirectionRight]; [swipeGestureRight setCancelsTouchesInView:YES]; [swipeGestureRight setDelaysTouchesEnded:YES]; //[_remoteView addGestureRecognizer:swipeGestureRight]; //左边的按住说话弹出的声音图标 //进入横屏时,调整frame //退出横屏时,也调整frame UIView *pressView = [[UIView alloc] initWithFrame:CGRectMake(10, self.canvasframe.size.height+NAVIGATION_BAR_HEIGHT-PRESS_LAYOUT_WIDTH_AND_HEIGHT, PRESS_LAYOUT_WIDTH_AND_HEIGHT/2, PRESS_LAYOUT_WIDTH_AND_HEIGHT)]; UIImageView *pressLeftView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, PRESS_LAYOUT_WIDTH_AND_HEIGHT/2, PRESS_LAYOUT_WIDTH_AND_HEIGHT)]; pressLeftView.image = LXImageWithImageName(@"ic_voice.png"); [pressView addSubview:pressLeftView]; UIImageView *pressRightView = [[UIImageView alloc] initWithFrame:CGRectMake(PRESS_LAYOUT_WIDTH_AND_HEIGHT/2, 0, PRESS_LAYOUT_WIDTH_AND_HEIGHT/2, PRESS_LAYOUT_WIDTH_AND_HEIGHT)]; NSArray *imagesArray = [NSArray arrayWithObjects:LXImageWithImageName(@"amp1.png"),LXImageWithImageName(@"amp2.png"),LXImageWithImageName(@"amp3.png"),LXImageWithImageName(@"amp4.png"),LXImageWithImageName(@"amp5.png"),LXImageWithImageName(@"amp6.png"),LXImageWithImageName(@"amp7.png"),LXImageWithImageName(@"amp6.png"),LXImageWithImageName(@"amp6.png"),LXImageWithImageName(@"amp3.png"),LXImageWithImageName(@"amp5.png"),LXImageWithImageName(@"amp6.png"),LXImageWithImageName(@"amp6.png"),LXImageWithImageName(@"amp3.png"),LXImageWithImageName(@"amp4.png"),LXImageWithImageName(@"amp5.png"),LXImageWithImageName(@"amp5.png"),nil]; pressRightView.animationImages = imagesArray; pressRightView.animationDuration = ((CGFloat)[imagesArray count])*200.0f/1000.0f; pressRightView.animationRepeatCount = 0; [pressRightView startAnimating]; [pressView addSubview:pressRightView]; [self.view addSubview:pressView]; [pressView setHidden:YES]; self.pressView = pressView; //、横屏工具栏 CGFloat midtH=self.canvasView.frame.size.height/5; UIView *midToolHView = [[UIView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY(self.canvasView.frame), width,0)]; midToolHView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; [self.view addSubview:midToolHView]; [self.view bringSubviewToFront:midToolHView]; self.midToolHView = midToolHView;//全屏时,隐藏 //_remoteView 添加点击手势现实和隐藏 midToolHView UITapGestureRecognizer *appermidToolView=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSingleTap)]; [appermidToolView setCancelsTouchesInView:YES]; [appermidToolView setDelaysTouchesEnded:YES]; [self.canvasView addGestureRecognizer:appermidToolView]; //暂停按钮 self.stopBtnH = [UIButton buttonWithType:UIButtonTypeCustom]; self.stopBtnH.frame = CGRectMake(50.0/SCREEN_SCALE, (midtH - midtH/2)/2, midtH/2, midtH/2); self.stopBtnH.tag = STOPBTN_TAG; [self.stopBtnH addTarget:self action:@selector(onVerticalBtnPress:) forControlEvents:UIControlEventTouchUpInside]; self.stopBtnH.hidden = YES; [self.midToolHView addSubview:self.stopBtnH]; //暂停按钮图片 UIImage *stopImageH = LXImageWithImageName(@"monitor_stop_h"); //self.stopImageViewH = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, (self.stopBtnH.frame.size.height-stopImageH.size.height/SCREEN_SCALE)/2, stopImageH.size.width/SCREEN_SCALE, stopImageH.size.height/SCREEN_SCALE)]; self.stopImageViewH = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, midtH/2, midtH/2)]; self.stopImageViewH.contentMode = UIViewContentModeScaleToFill; self.stopImageViewH.image = stopImageH; [self.stopBtnH addSubview:self.stopImageViewH]; //横屏按钮 self.switchScreenButtonH = [UIButton buttonWithType:UIButtonTypeCustom]; CGFloat BtnH = midtH*2/3; self.switchScreenButtonH.frame = CGRectMake(self.midToolHView.frame.size.width-BtnH -50.0/SCREEN_SCALE, (midtH - BtnH)/2,BtnH + 50.0/SCREEN_SCALE, BtnH); self.switchScreenButtonH.tag = SWITCH_SCREEN_BUTTON_H_TAG; [self.switchScreenButtonH addTarget:self action:@selector(onVerticalBtnPress:) forControlEvents:UIControlEventTouchUpInside]; [self.midToolHView addSubview:self.switchScreenButtonH]; self.switchScreenButtonH.hidden = YES; //self.switchScreenButtonH = switchScreenButtonH; //横屏按钮图片 UIImage *switchScreenImageH = LXImageWithImageName(@"monitor_switch_screen_img_h.png"); UIImageView *switchScreenImageViewH = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, BtnH, BtnH)]; switchScreenImageViewH.contentMode = UIViewContentModeScaleToFill; switchScreenImageViewH.image = switchScreenImageH; [self.switchScreenButtonH addSubview:switchScreenImageViewH]; //选择 /*CGFloat segMentH=midtH; CGFloat controlSegY= CGRectGetMaxY(self.canvasView.frame); NSArray *segArr=[[NSArray alloc] initWithObjects:@"摄像头", @"水族箱", nil]; self.segmentControl = [[UISegmentedControl alloc] initWithItems:segArr]; self.segmentControl.frame=CGRectMake(0.0, controlSegY,kScreenSize.width, segMentH); self.segmentControl.selectedSegmentIndex = 0; self.segmentControl.tintColor=COLOR_LABEL_TITLE; self.segmentControl.backgroundColor = SEGMENT_CONTROLBACK; self.segmentControl.layer.masksToBounds = YES; self.segmentControl.layer.cornerRadius = 0; self.segmentControl.layer.borderColor = [UIColor colorWithRed:65.0/256.0 green:65.0/256.0 blue:65.0/256.0 alpha:1].CGColor; self.segmentControl.layer.borderWidth = 2; [self.segmentControl setTitle:@"摄像头" forSegmentAtIndex:0]; [self.segmentControl setTitle:@"水族箱" forSegmentAtIndex:1]; NSDictionary *attributesString=@{ NSFontAttributeName:[UIFont systemFontOfSize:18], NSForegroundColorAttributeName:[UIColor whiteColor], }; //NSBackgroundColorAttributeName:[UIColor redColor] [self.segmentControl setTitleTextAttributes:attributesString forState:UIControlStateSelected]; [self.segmentControl addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:self.segmentControl];*/ CGFloat segMentH=kScreenSize.width*0.13; CGFloat controlSegY= CGRectGetMaxY(self.canvasView.frame); IifshSegmentView *seg = [[IifshSegmentView alloc] initWithFrame:CGRectMake(0.0, controlSegY,kScreenSize.width, segMentH)]; seg.segDelegate = self; [seg initleftTitle:@"摄像头" addRightTitle:@"水族箱" isSelectStyle:YES]; self.segControl = seg; [self.view addSubview:seg]; //布防撤防、对讲、截图工具栏 ****** 云台 CameraBottomHView *bottomToolHView = [[CameraBottomHView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY(self.segControl.frame) + 10, width, height-CGRectGetMaxY(self.segControl.frame))]; bottomToolHView.cameraHViewDelegate = self; bottomToolHView.camera = self.contact; [self.view addSubview:bottomToolHView]; self.bottomToolHView = bottomToolHView;//全屏时,隐藏 self.bottomToolHView.hidden = NO; //底部view 水族箱view UIView *bottomHView = [[UIView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY(self.segControl.frame) + 10, width, height-CGRectGetMaxY(self.segControl.frame))]; bottomHView.backgroundColor = JWUIColorFromRGB(0xdddddd); [self.view addSubview:bottomHView]; self.bottomFishHView = bottomHView; self.bottomFishHView.hidden = YES; //截图展示 暂未用 //CGFloat contentH=200*0.56; //_shutterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, contentH)]; //_shutterView.backgroundColor = [UIColor clearColor]; } #pragma mark- 下拉菜单 -(void)popAppear{ UIImage *image = [UIImage imageNamed:@"popover_background_image_notrangle"]; BOOL isBind=[self testCameraBindDeviceOrNot]; NSArray *titleImgs =nil; NSArray *titles=nil; CGFloat popRowH=60*(image.size.height/image.size.width); LXPopView *pop=[[LXPopView alloc] init]; if (isBind) { pop.frame = CGRectMake(0, 0, 160, popRowH * 4 +12 ); titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device",@"equipment_icon_equipmentupdate",@"ifish_jieBang_device"]; titles=@[@"修改名称",@"删除设备",@"设备升级",@"解除绑定"]; }else{ pop.frame = CGRectMake(0, 0, 160, popRowH * 3 +12); titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device",@"equipment_icon_equipmentupdate"]; titles=@[@"修改名称",@"删除设备",@"设备升级"]; } pop.delegate = self; pop.backgroundImage =image ; pop.titles = titles; pop.titleImgs =titleImgs; DXPopover *popover = [DXPopover popover]; self.popover = popover; popover.arrowSize = CGSizeMake(0.0,0.0); [popover showAtView:self.rightPopButton withContentView:pop]; } #pragma mark - pop代理 -(void)disSelectedPopViewIndex:(NSIndexPath *)Index{ [self.popover dismiss]; if (Index.row == 0) { //修改设备名 [self sheZhiCameraMing]; }else if (Index.row == 1){ //删除摄像头 [self delectCamera]; }else if (Index.row == 3){ //解除绑定关系 [self jieBangBtnAction]; }else if (Index.row == 2){ //检查设备更新 if (_isOkRenderVideoFrame) { // self.progressAlert.dimBackground = YES; // [self.progressAlert show:YES]; [self.view makeToastActivity]; [[P2PClient sharedClient] checkDeviceUpdateWithId:self.contact.cameraId password:self.contact.cameraPass]; }else{ [self.view makeToast:@"设备已离线"]; } } } //判断摄像头是否有关系设备 #pragma mark - 判断摄像头是否有关系设备 -(BOOL)testCameraBindDeviceOrNot{ NSArray *devicCameraArr = [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"]; NSMutableArray *camerwIdArr = [[NSMutableArray alloc] init]; for (DeviceCameraModel *camera in devicCameraArr) { [camerwIdArr addObject:camera.cameraId]; } BOOL exst=[camerwIdArr containsObject:self.contact.cameraId]; if (exst) { return YES; } return NO; } #pragma mark- 设置设备名称 -(void)sheZhiCameraMing{ self.setNameVC = [[SetNameTextViewController alloc] init]; self.setNameVC.name = self.nameTitle.text; self.setNameVC.cameraModel = self.contact; self.setNameVC.deviceType = 1; __weak typeof (self)wself = self; _setNameVC.NameWithBlock = ^(NSString *nameStr){ wself.nameTitle.text = nameStr; }; if (_isOkRenderVideoFrame) { [self stopGLViewVideo]; } [self.navigationController pushViewController:self.setNameVC animated:YES]; self.navigationController.navigationBarHidden = NO; } #pragma mark - 删除摄像头 -(void)delectCamera{ UIAlertController*ac2=[UIAlertController alertControllerWithTitle:@"提示" message:@"确认删除摄像头?" preferredStyle:UIAlertControllerStyleAlert]; [ac2 addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){ }]]; [ac2 addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){ //删除摄像头 前判断是否有 设备与其绑定关系 有解除关系 从关系数组中删除 NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"]; for (DeviceCameraModel *model in guanxiiArr) { if (self.contact.cameraId == model.cameraId ) { [guanxiiArr removeObject:model]; //保存新关系数组 [[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"]; } } [self deleteCameraAtRequset]; }]]; [self presentViewController:ac2 animated:YES completion:nil]; } -(void)deleteCameraAtRequset{ AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager]; mannager.responseSerializer=[AFHTTPResponseSerializer serializer]; NSMutableDictionary * para = [NSMutableDictionary dictionary]; // NSMutableArray*deviceIdArr=[[NSMutableArray alloc]init]; UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"]; NSString *cameraId=self.contact.cameraId; ; NSNumber *userId=model.userId; [para setValue:cameraId forKey:@"cameraId"]; [para setValue:userId forKey:@"userId"]; __weak typeof (self)weakSelf=self; [mannager POST:IfishdeleteCameraUser parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) { if (responseObject) { NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil]; NSLog(@"result:%@",resultDic[@"result"]); if ([resultDic[@"result"] isEqualToString:@"100"]) { if (_isOkRenderVideoFrame) { [weakSelf stopGLViewVideo]; } [[Socketsingleton sharedInstance] cutOffSocket]; [weakSelf.view makeToast:@"删除成功"]; NSArray*deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"cameraArr"]; NSMutableArray *newArr = [NSMutableArray arrayWithArray:deviceArry]; for (IfishCameraModel *model in deviceArry) { if ([model.cameraId isEqual:self.contact.cameraId]) { [newArr removeObject:model]; } } [[DataCenter defaultDtacenter] setValue: newArr forKey:@"cameraArr"]; [weakSelf setAppTabRoot]; }else if ([resultDic[@"result"] isEqualToString:@"101"]){ [weakSelf.view makeToast:@"删除失败"]; }else if ([resultDic[@"result"] isEqualToString:@"301"]){ [weakSelf.view makeToast:@"请求验证失败,请重新登陆"]; }else if ([resultDic[@"result"] isEqualToString:@"302"]){ [weakSelf.view makeToast:@"请求被舍弃,未执行"]; } } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [weakSelf.view makeToast:@"请求异常"]; }]; } #pragma mark - 关系解绑事件 -(void)jieBangBtnAction{ UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"确定解除摄像头与水族箱的关系吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alert.tag = CAMERA_DEVICE_JIEBANG_ALERT; [alert show]; } #pragma mark- 解除 摄像头设备关系 -(void)camerDeviceDelectRelate{ //解除与当前显示摄像头 相关的 关系设备 NSMutableArray * devicCameraArr = [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"]; NSString *deviceId= nil; for (DeviceCameraModel *camera in devicCameraArr) { if (self.contact.cameraId == camera.cameraId) { deviceId = camera.deviceId; } } [AFNOHeaderHttpTool deleteDeviceCameraWith:self.contact.cameraId deiviceId:deviceId success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; NSString *result= reDic[@"result"] ; if ([result isEqualToString:@"100"]) { [self.view makeToast:@"解除关系成功"]; [devicCameraArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[DeviceCameraModel class]]) { DeviceCameraModel *camera = (DeviceCameraModel *)obj; if (self.contact.cameraId == camera.cameraId) { [devicCameraArr removeObject:camera]; *stop = YES; } } }]; //重置关系数组 [[DataCenter defaultDtacenter] setValue:devicCameraArr forKey:@"devicamerArr"]; if (self.fishControlView) { [self.fishControlView.collectionView removeFromSuperview]; [self.fishControlView setTabViewWithFrame:self.fishControlView.frame]; //_jieBangBtn.hidden = YES; } [[Socketsingleton sharedInstance] cutOffSocket]; }else if ([result isEqualToString:@"101"]){ [self.view makeToast:@"解除关系失败"]; } } failure:^(NSError *err) { [self.view makeToast:@"请检查网络连接"]; }]; } #pragma mark- Segment选择事件 with新UI -(void)segmentSelectAtIndext:(NSInteger)index { switch (index) { //云台 case 0: { self.bottomToolHView.hidden = NO; self.bottomFishHView.hidden = YES; } break; //水族箱 case 1: { self.bottomFishHView.hidden = NO; self.bottomToolHView.hidden = YES; NSLog(@"水族箱"); NSArray*devicearray=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; //self.currentDevice = devicearray[0]; NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults]; [userdefult setObject:self.contact.cameraId forKey:@"OnShowCameraId"]; [userdefult synchronize]; if ([devicearray count]!=0) { CGRect rect = [AppDelegate getScreenSize:YES isHorizontal:NO]; CGFloat width = rect.size.width; CGFloat height = rect.size.height; if (!_fishControlView) { _fishControlView=[[MonitorBootmView alloc] initWithFrame:CGRectMake(0,0, width, height-CGRectGetMaxY(self.segControl.frame) -15)]; _fishControlView.cameraId = self.contact.cameraId; _fishControlView.MonitorBottomDelegate=self; [self.bottomFishHView addSubview:_fishControlView]; } }else{ UIButton *notbindBtn=[UIButton buttonWithType:UIButtonTypeCustom]; NSString *title=@"您暂未绑定水族箱,前往绑定。"; [notbindBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:title]; NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:8]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [title length])]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0 green:170.0/255.0 blue:218.0/255.0 alpha:1] range:NSMakeRange(9,4)]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,9)]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange([title length]-1,1)]; [notbindBtn setAttributedTitle:attributedString forState:UIControlStateNormal]; [notbindBtn sizeToFit]; notbindBtn.titleLabel.textAlignment = NSTextAlignmentCenter; CGFloat btnTitleW =[self widthForString:notbindBtn.titleLabel.text fontSize:20 andHeight:10]; CGFloat btnTitleH = [self heightForString:notbindBtn.titleLabel.text fontSize:20 andWidth:btnTitleW]; notbindBtn.frame =CGRectMake(self.bottomFishHView.frame.size.width/2 -btnTitleW/2,self.bottomFishHView.frame.size.height/2 -btnTitleH/2, btnTitleW, btnTitleH); [notbindBtn addTarget:self action:@selector(notbindClick) forControlEvents:UIControlEventTouchUpInside]; [self.bottomFishHView addSubview:notbindBtn]; } } break; default: break; } } #pragma -mark -functions //获取字符串的宽度 -(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height { CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX, height) lineBreakMode:NSLineBreakByWordWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置 return sizeToFit.width; } //获得字符串的高度 -(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width { CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByCharWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置 return sizeToFit.height; } #pragma mark- 未绑定水族箱 -(void)notbindClick{ //挂断连接 [self stopGLViewVideo]; formLogIn = NO; isfromCameraView = YES; //主动 释放 openGL 内存 以 free buffer [AppDelegate sharedDefault].canFullScreen = NO; [self.remoteView releseromotViewSet]; IfishBindDeviceSelectViewController *connectVC=[[IfishBindDeviceSelectViewController alloc]init]; [self.navigationController pushViewController:connectVC animated:YES]; } #pragma mark 按下按钮时,响应 -(void)onVerticalBtnTouchCancel:(UIButton *)button{ switch(button.tag){ case SOUND_BUTTON_H_TAG://声音 { } break; case SWITCH_SCREEN_BUTTON_H_TAG://横屏 { } break; case DEFENCE_BUTTON_H_TAG://布防撤防 { } break; case TALK_BUTTON_H_TAG: { [self.pressView setHidden:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; } break; case SCREENSHOT_BUTTON_H_TAG://载图 { } break; case PROMPT_BUTTON_TAG://重新连接监控 { } break; } } #pragma mark 点击竖屏上的按钮时,响应 -(void)onVerticalBtnPress:(UIButton *)button{ switch(button.tag){ case SOUND_BUTTON_H_TAG://声音 { if (!_isOkRenderVideoFrame) { //图像渲染出来前,不可以控制声音 return; } // UIImageView *soundImageViewH = (UIImageView *)button.subviews[0]; // BOOL isMute = [[PAIOUnit sharedUnit] muteAudio]; // if(isMute){ // // [[PAIOUnit sharedUnit] setMuteAudio:NO]; // //LXImageWithImageName(@"ic_ctl_new_sound_off.png"); // soundImageViewH.image = LXImageWithImageName(@"monitor_sound_on_h.png"); // //横屏,声音打开 // UIButton *controllerSoundBtn = (UIButton *)[self.controllBar viewWithTag:CONTROLLER_BTN_TAG_SOUND]; // [controllerSoundBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_sound_on.png") forState:UIControlStateNormal]; // }else{ // // // [[PAIOUnit sharedUnit] setMuteAudio:YES]; // soundImageViewH.image = LXImageWithImageName(@"monitor_sound_off_.png"); // //横屏,声音关闭 // UIButton *controllerSoundBtn = (UIButton *)[self.controllBar viewWithTag:CONTROLLER_BTN_TAG_SOUND]; // [controllerSoundBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_sound_off.png") forState:UIControlStateNormal]; // } } break; case SWITCH_SCREEN_BUTTON_H_TAG://切换至横屏或者竖屏 { if (!_isOkFirstRenderVideoFrame) { //第一次成功渲染图像前,不可以切换至横屏 return; } if (!self.isFullScreen) { //设置横屏 [AppDelegate sharedDefault].canFullScreen = YES; static int isFullScreen = 3; // 3 == 全屏 1 == 竖屏 if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { NSNumber *numb=[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight]; [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:numb]; SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; NSLog(@"-%d-",isFullScreen); [invocation setArgument:&isFullScreen atIndex:2]; [invocation invoke]; self.navigationController.navigationBar.hidden = YES; //设置默认全屏 BOOL is16B9 = [[P2PClient sharedClient] is16B9]; if (!is16B9) { self.isFullScreen4B3 = NO; [self onDoubleTap]; } } } else { self.isFullScreen4B3 = !self.isFullScreen4B3; //设置竖屏 [AppDelegate sharedDefault].canFullScreen = NO; static int isFullScreen = 1; // 3 == 全屏 1 == 竖屏 if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { NSLog(@"self.interfaceOrientation%ld",(long)UIDeviceOrientationPortrait); //NSNumber *numb=[NSNumber numberWithInteger:UIDeviceOrientationPortrait]; //[[UIDevice currentDevice] performSelector:@selector(setOrientation:) // withObject:numb]; SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; NSLog(@"-%d-",isFullScreen); [invocation setArgument:&isFullScreen atIndex:2]; [invocation invoke]; } } } break; case DEFENCE_BUTTON_H_TAG://布防撤防 { NSString *contactId = [[P2PClient sharedClient] callId]; NSString *contactPassword = [[P2PClient sharedClient] callPassword]; if (self.isDefenceOn) { [[P2PClient sharedClient] setRemoteDefenceWithId:contactId password:contactPassword state:SETTING_VALUE_REMOTE_DEFENCE_STATE_OFF]; }else{ [[P2PClient sharedClient] setRemoteDefenceWithId:contactId password:contactPassword state:SETTING_VALUE_REMOTE_DEFENCE_STATE_ON]; } } break; case TALK_BUTTON_H_TAG://对讲 { //非本地设备 NSInteger deviceType1 = [AppDelegate sharedDefault].contact.contactType; //本地设备 NSInteger deviceType2 = [[FListManager sharedFList] getType:[[P2PClient sharedClient] callId]]; if (deviceType1 == CONTACT_TYPE_DOORBELL || deviceType2 == CONTACT_TYPE_DOORBELL) {//支持门铃,点按开关说话 if (self.isTalking) { self.isTalking = NO; [self.pressView setHidden:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; //竖屏,对讲关闭 button.selected = NO; //横屏,对讲关闭 //LXImageWithImageName(@"ic_ctl_new_send_audio_p.png") UIButton *controllerTalkBtn = (UIButton *)[self.controllBar viewWithTag:CONTROLLER_BTN_TAG_PRESS_TALK]; [controllerTalkBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_send_audio.png") forState:UIControlStateNormal]; }else{ self.isTalking = YES; [self.pressView setHidden:NO]; // [[PAIOUnit sharedUnit] setSpeckState:NO]; //竖屏,对讲打开 button.selected = YES; //横屏,对讲打开 UIButton *controllerTalkBtn = (UIButton *)[self.controllBar viewWithTag:CONTROLLER_BTN_TAG_PRESS_TALK]; [controllerTalkBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_send_audio_p.png") forState:UIControlStateNormal]; } }else{ //不支持门铃,松开结束对讲 [self.pressView setHidden:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; } } break; case SCREENSHOT_BUTTON_H_TAG://载图 { [self.remoteView setIsScreenShotting:YES]; } break; case PROMPT_BUTTON_TAG://重新连接监控 { [self hiddenMonitoringUI:NO callErrorInfo:nil isReCall:YES]; [self monitorP2PCall]; } break; //暂停按钮 case STOPBTN_TAG: { // if (!_isOkRenderVideoFrame) { // //图像渲染出来前,不可以暂停 // return; // } UIImageView *stopImageViewH = (UIImageView *)button.subviews[0]; if(!_isOkRenderVideoFrame){ [self hiddenMonitoringUI:NO callErrorInfo:nil isReCall:YES]; [self monitorP2PCall]; stopImageViewH.image = LXImageWithImageName(@"monitor_stop_h.png"); //横屏,声音打开 //UIButton *controllerSoundBtn = (UIButton *)[self.controllBar viewWithTag:CONTROLLER_BTN_TAG_SOUND]; //[controllerSoundBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_sound_on.png") forState:UIControlStateNormal]; }else{ [self stopGLViewVideo]; stopImageViewH.image = LXImageWithImageName(@"monitor_on_h.png"); //横屏,声音关闭 // UIButton *controllerSoundBtn = (UIButton *)[self.controllBar viewWithTag:CONTROLLER_BTN_TAG_SOUND]; // [controllerSoundBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_sound_off.png") forState:UIControlStateNormal]; } } break; //图库 case SCREENSHOT_BUTTON_FLIE_TAG: { if (_isOkRenderVideoFrame) { [self stopGLViewVideo]; } usleep(50*1000); ShotScreenImgViewController *shootView=[[ShotScreenImgViewController alloc] init]; [self.navigationController pushViewController:shootView animated:YES]; NSLog(@"图库"); } } } #pragma mark 按下按钮时,响应 -(void)onVerticalBtnTouchDown:(UIButton *)button{ switch(button.tag){ case SOUND_BUTTON_H_TAG://声音 { } break; case SWITCH_SCREEN_BUTTON_H_TAG://横屏 { } break; case DEFENCE_BUTTON_H_TAG://布防撤防 { } break; case TALK_BUTTON_H_TAG://按下开始对讲 { //非本地设备 NSInteger deviceType1 = [AppDelegate sharedDefault].contact.contactType; //本地设备 NSInteger deviceType2 = [[FListManager sharedFList] getType:[[P2PClient sharedClient] callId]]; if (deviceType1 != CONTACT_TYPE_DOORBELL && deviceType2 != CONTACT_TYPE_DOORBELL) {//不支持门铃,按下开始对讲 [self.pressView setHidden:NO]; //[[PAIOUnit sharedUnit] setSpeckState:NO]; } } break; case SCREENSHOT_BUTTON_H_TAG://载图 { } break; case PROMPT_BUTTON_TAG://重新连接监控 { } break; } } #define MESG_SET_GPIO_PERMISSION_DENIED 86 #define MESG_GPIO_CTRL_QUEUE_IS_FULL 87 #define MESG_SET_DEVICE_NOT_SUPPORT 255 #define GPIO0_0 10 #define GPIO0_1 11 #define GPIO0_2 12 #define GPIO0_3 13 #define GPIO0_4 14 #define GPIO2_6 15 - (void)receiveRemoteMessage:(NSNotification *)notification{ NSDictionary *parameter = [notification userInfo]; int key = [[parameter valueForKey:@"key"] intValue]; switch(key){ case RET_GET_FOCUS_ZOOM: { int value = [[parameter valueForKey:@"value"] intValue]; if (value == 3) {//变倍变焦都有 dispatch_async(dispatch_get_main_queue(), ^{ self.isSupportFocalLength = YES; [self.pinchGestureRecognizer addTarget:self action:@selector(localLengthPinchToZoom:)]; }); }else if (value == 2){//只有变焦 dispatch_async(dispatch_get_main_queue(), ^{ self.isSupportFocalLength = YES; }); }else if (value == 1){//只有变倍 dispatch_async(dispatch_get_main_queue(), ^{ [self.pinchGestureRecognizer addTarget:self action:@selector(localLengthPinchToZoom:)]; }); } } break; case RET_SET_GPIO_CTL: { int result = [[parameter valueForKey:@"result"] intValue]; dispatch_async(dispatch_get_main_queue(), ^{ self.clickGPIO0_0Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_1Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_2Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_3Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_4Button.backgroundColor = [UIColor clearColor]; self.clickGPIO2_6Button.backgroundColor = [UIColor clearColor]; }); if (result == 0) { //设置成功 dispatch_async(dispatch_get_main_queue(), ^{ [self.view makeToast:NSLocalizedString(@"operator_success", nil)]; }); }else if (result == MESG_SET_GPIO_PERMISSION_DENIED){ //该GPIO未开放 dispatch_async(dispatch_get_main_queue(), ^{ [self.view makeToast:NSLocalizedString(@"not_open", nil)]; }); }else if (result == MESG_GPIO_CTRL_QUEUE_IS_FULL){ //操作过于频繁,之前的操作未执行完 dispatch_async(dispatch_get_main_queue(), ^{ [self.view makeToast:NSLocalizedString(@"too_frequent", nil)]; }); }else if(result == MESG_SET_DEVICE_NOT_SUPPORT){ //设备不支持此操作 dispatch_async(dispatch_get_main_queue(), ^{ [self.view makeToast:NSLocalizedString(@"not_support_operation", nil)]; }); } } break; case RET_GET_LIGHT_SWITCH_STATE: { int result = [[parameter valueForKey:@"result"] intValue]; if (result == 0) { int state = [[parameter valueForKey:@"state"] intValue]; dispatch_async(dispatch_get_main_queue(), ^{ self.isSupportLightSwitch = YES; if (state == 1) {//灯是开状态 self.isLightSwitchOn = YES; [self.lightButton setBackgroundImage:[UIImage imageNamed:@"lighton.png"] forState:UIControlStateNormal]; }else{ self.isLightSwitchOn = NO; [self.lightButton setBackgroundImage:[UIImage imageNamed:@"lightoff.png"] forState:UIControlStateNormal]; } }); } } break; case RET_SET_LIGHT_SWITCH_STATE: { int result = [[parameter valueForKey:@"result"] intValue]; if (result == 0) { dispatch_async(dispatch_get_main_queue(), ^{ [self.lightButton setHidden:NO]; [self.progressView setHidden:YES]; [self.progressView stopAnimating]; if (self.isLightSwitchOn) {//灯正开着 self.isLightSwitchOn = NO;//关灯 [self.lightButton setBackgroundImage:[UIImage imageNamed:@"lightoff.png"] forState:UIControlStateNormal]; }else{//灯正关着 self.isLightSwitchOn = YES;//开灯 [self.lightButton setBackgroundImage:[UIImage imageNamed:@"lighton.png"] forState:UIControlStateNormal]; } }); } } break; case RET_DEVICE_NOT_SUPPORT: { dispatch_async(dispatch_get_main_queue(), ^{ self.clickGPIO0_0Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_1Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_2Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_3Button.backgroundColor = [UIColor clearColor]; self.clickGPIO0_4Button.backgroundColor = [UIColor clearColor]; self.clickGPIO2_6Button.backgroundColor = [UIColor clearColor]; //[self.view makeToast:NSLocalizedString(@"device_not_support", nil)]; }); } break; case RET_GET_NPCSETTINGS_REMOTE_DEFENCE: { dispatch_async(dispatch_get_main_queue(), ^{ NSInteger state = [[parameter valueForKey:@"state"] intValue]; if(state==SETTING_VALUE_REMOTE_DEFENCE_STATE_ON) { //竖屏 [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_on_h.png")forState:UIControlStateNormal]; [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_on_h_p.png") forState:UIControlStateHighlighted]; //获取到布防状态,设置为可点且显示相应的图标 self.defenceButtonH.enabled = YES; self.isDefenceOn = YES; //横屏 [_btnDefence setBackgroundImage:LXImageWithImageName(@"ic_ctl_lock_on.png") forState:UIControlStateNormal]; } else { //竖屏 [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_off_h.png") forState:UIControlStateNormal]; [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_off_h_p.png") forState:UIControlStateHighlighted]; //获取到布防状态,设置为可点且显示相应的图标 self.defenceButtonH.enabled = YES; self.isDefenceOn = NO; //横屏 [_btnDefence setBackgroundImage:LXImageWithImageName(@"ic_ctl_lock_off.png") forState:UIControlStateNormal]; } if (_btnDefence.hidden == YES) { _btnDefence.hidden = NO; } }); } break; case RET_SET_NPCSETTINGS_REMOTE_DEFENCE: { dispatch_async(dispatch_get_main_queue(), ^{ NSInteger state = [[parameter valueForKey:@"state"] intValue]; if(state==SETTING_VALUE_REMOTE_DEFENCE_STATE_ON){ //竖屏 // LXImageWithImageName(@"ic_ctl_lock_off.png") [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_on_h.png") forState:UIControlStateNormal]; [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_on_h_p.png") forState:UIControlStateHighlighted]; self.isDefenceOn = YES; //横屏 [_btnDefence setBackgroundImage:LXImageWithImageName(@"ic_ctl_lock_on.png") forState:UIControlStateNormal]; }else{ //竖屏 [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_off_h.png") forState:UIControlStateNormal]; [self.defenceButtonH setImage:LXImageWithImageName(@"monitor_defence_off_h_p.png") forState:UIControlStateHighlighted]; self.isDefenceOn = NO; //横屏 [_btnDefence setBackgroundImage:LXImageWithImageName(@"ic_ctl_lock_off.png") forState:UIControlStateNormal]; } }); } break; case RET_CHECK_DEVICE_UPDATE: //检查设备更新 { NSInteger result = [[parameter valueForKey:@"result"] intValue]; NSString *curVersion = [parameter valueForKey:@"curVersion"]; NSString *upgVersion = [parameter valueForKey:@"upgVersion"]; if(result==1){ //读取到了服务器升级文件 dispatch_async(dispatch_get_main_queue(), ^{ [self.view hideToastActivity]; NSString *title = [NSString stringWithFormat:@"%@:%@,%@:%@",NSLocalizedString(@"cur_version_is", nil),curVersion,NSLocalizedString(@"can_update_to", nil),upgVersion]; UIAlertView *deleteAlert = [[UIAlertView alloc] initWithTitle:title message:@"" delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) otherButtonTitles:NSLocalizedString(@"ok", nil),nil]; deleteAlert.tag = ALERT_TAG_UPDATE; [deleteAlert show]; }); }else if(result==72){//sd卡升级文件 //读取到了sd卡升级文件 dispatch_async(dispatch_get_main_queue(), ^{ [self.view hideToastActivity]; NSString *title = [NSString stringWithFormat:@"%@:%@,%@",NSLocalizedString(@"cur_version_is", nil),curVersion,NSLocalizedString(@"can_update_sd", nil)]; UIAlertView *deleteAlert = [[UIAlertView alloc] initWithTitle:title message:@"" delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) otherButtonTitles:NSLocalizedString(@"ok", nil),nil]; deleteAlert.tag = ALERT_TAG_UPDATE; [deleteAlert show]; }); }else if(result==54){ dispatch_async(dispatch_get_main_queue(), ^{ [self.view hideToastActivity]; [self.view makeToast:[NSString stringWithFormat:@"%@:%@",NSLocalizedString(@"now_version_is_latest", nil),curVersion]]; }); }else if(result==58){ dispatch_async(dispatch_get_main_queue(), ^{ [self.view hideToastActivity]; [self.view makeToast:NSLocalizedString(@"other_was_check_device_update", nil)]; }); }else{ dispatch_async(dispatch_get_main_queue(), ^{ [self.view hideToastActivity]; [self.view makeToast:NSLocalizedString(@"update_failed", nil)]; }); } } break; case RET_DO_DEVICE_UPDATE: { NSInteger result = [[parameter valueForKey:@"result"] intValue]; NSInteger value = [[parameter valueForKey:@"value"] intValue]; dispatch_async(dispatch_get_main_queue(), ^{ if(result==1){ self.progressLabel.text = [NSString stringWithFormat:@"%li%%",(long)value];//device update [self.progressMaskView setHidden:NO]; }else if(result==65){ [self.progressMaskView setHidden:YES]; [self.view makeToast:@"升级成功"]; //固件下载成功,并在升级中,弹出一个框 // YMsgBox *yBox = [[YMsgBox alloc] init]; //yBox.yMsgTextField.secureTextEntry = YES; // [yBox addTarget:self withAction:@selector(isUpdateFirmware:) forEvent:YMsgBoxMsgTypeButtonBeClick]; // yBox.yMsgTitle = [YFonc gtTextWithString:NSLocalizedString(@"firmware_is_being_upgraded", nil) // withColor:[UIColor blackColor] // withFont:[UIFont systemFontOfSize:15] // withAlignment:NSTextAlignmentCenter]; // yBox.yMsgTextFieldBorderColor=RGBA(62,156,254,1.0); // yBox.yMsgTextFieldBottomLineColor=[UIColor clearColor]; // yBox.yMsgButtonBorderColor=RGBA(211,211,212,1.0); // UIButton *okBtn= [[UIButton alloc ]init]; // [okBtn setTitleColor:[UIColor colorWithRed:62.0/255.0 green:156.0/255.0 blue:254.0/255.0 alpha:1.0] forState:UIControlStateNormal]; // [okBtn setTitleColor:[UIColor colorWithRed:27.0/255.0 green:122.0/255.0 blue:222.0/255.0 alpha:1.0] forState:UIControlStateHighlighted]; // okBtn.titleLabel.font = [UIFont systemFontOfSize:15]; // [okBtn setTitle:NSLocalizedString(@"i_know",nil) forState:UIControlStateNormal]; // UIButton *cancelBtn= [[UIButton alloc ]init]; // cancelBtn.titleLabel.font = [UIFont systemFontOfSize:15]; // [cancelBtn setTitle:NSLocalizedString(@"no",nil) forState:UIControlStateNormal]; //[cancelBtn setTitleColor:UIColorFromRGB(0x3e9cfe) forState:UIControlStateNormal]; // yBox.yMsgButtons = @[okBtn]; // [yBox showMsgBoxInViewController:self]; }else{ [self.progressMaskView setHidden:YES]; [self.view makeToast:NSLocalizedString(@"update_failed", nil)]; } }); } break; } } #pragma mark - 弹框操作 -(void)isUpdateFirmware:(YMsgBox*)box{ if(box.yMsgButtonIndex == -1){ return; }else if(box.yMsgButtonIndex == -2){ //隐藏键盘 系统键盘return按钮被点击 [box hideKeyBoard]; }else if(box.yMsgButtonIndex == 0){ //确认按钮被点击 // [self.navigationController popToRootViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES]; [box hideMsgBox]; //隐藏输入框 }else{ //取消按钮被点击 [box hideMsgBox]; //隐藏输入框 } } - (void)ack_receiveRemoteMessage:(NSNotification *)notification{ NSDictionary *parameter = [notification userInfo]; int key = [[parameter valueForKey:@"key"] intValue]; int result = [[parameter valueForKey:@"result"] intValue]; switch(key){ case ACK_RET_SET_GPIO_CTL: { dispatch_async(dispatch_get_main_queue(), ^{ if(result==1){ [self.view makeToast:NSLocalizedString(@"device_password_error", nil)]; }else if(result==2){ DLog(@"resend do device update"); NSString *contactId = [[P2PClient sharedClient] callId]; NSString *contactPassword = [[P2PClient sharedClient] callPassword]; [[P2PClient sharedClient] setGpioCtrlWithId:contactId password:contactPassword group:self.lastGroup pin:self.lastPin value:self.lastValue time:self.lastTime]; } }); } break; case ACK_RET_GET_LIGHT_STATE: { dispatch_async(dispatch_get_main_queue(), ^{ if(result==1){ [self.view makeToast:NSLocalizedString(@"device_password_error", nil)]; }else if(result==2){ DLog(@"resend do device update"); NSString *contactId = [[P2PClient sharedClient] callId]; NSString *contactPassword = [[P2PClient sharedClient] callPassword]; [[P2PClient sharedClient] getLightStateWithDeviceId:contactId password:contactPassword]; } }); } break; case ACK_RET_SET_LIGHT_STATE: { dispatch_async(dispatch_get_main_queue(), ^{ if(result==1){ [self.view makeToast:NSLocalizedString(@"device_password_error", nil)]; }else if(result==2){ DLog(@"resend do device update"); NSString *contactId = [[P2PClient sharedClient] callId]; NSString *contactPassword = [[P2PClient sharedClient] callPassword]; if (self.isLightSwitchOn) {//灯正开着 [[P2PClient sharedClient] setLightStateWithDeviceId:contactId password:contactPassword switchState:0];//关灯 }else{ [[P2PClient sharedClient] setLightStateWithDeviceId:contactId password:contactPassword switchState:1];//开灯 } } }); } break; case ACK_RET_GET_DEFENCE_STATE: { if(result==2){ //超时 NSString *callId = [[P2PClient sharedClient] callId]; NSString *callPassword = [[P2PClient sharedClient] callPassword]; [[P2PClient sharedClient]getDefenceState:callId password:callPassword]; } } break; case ACK_RET_SET_NPCSETTINGS_REMOTE_DEFENCE: { if (result == 2) { dispatch_async(dispatch_get_main_queue(), ^{ [self.view makeToast:NSLocalizedString(@"net_exception", nil)]; }); } } break; } } #pragma mark - 监控横屏时,各控件初始化 -(void)initComponentForHorizontalScreen{ CGRect rect = [AppDelegate getScreenSize:NO isHorizontal:YES]; CGFloat width = rect.size.width; _monitorInterfaceW = width; CGFloat height = rect.size.height; if(CURRENT_VERSION<7.0){ height +=20; } _monitorInterfaceH = height; _horizontalScreenH = height; //横屏背景 UIView *fullScreenBgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, width, height)]; fullScreenBgView.backgroundColor = XBlack; self.fullScreenBgView = fullScreenBgView; //进入横屏时,响应onDoubleTap //退出横屏时,响应onDoubleTap 暂停 UITapGestureRecognizer *doubleTapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onDoubleTap)]; doubleTapG.delegate = self; [doubleTapG setNumberOfTapsRequired:2]; [self.remoteView addGestureRecognizer:doubleTapG]; //进入横屏时,响应onSingleTap //退出横屏时,响应onSingleTap UITapGestureRecognizer *singleTapG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSingleTap)]; singleTapG.delegate = self; [singleTapG setNumberOfTapsRequired:1]; [singleTapG requireGestureRecognizerToFail:doubleTapG]; [self.remoteView addGestureRecognizer:singleTapG]; //进入横屏时,响应localLengthPinchToZoom //退出横屏时,不响应localLengthPinchToZoom NSString * plist = [[NSBundle mainBundle] pathForResource:@"Common-Configuration" ofType:@"plist"]; NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:plist]; BOOL isSupportZoom = [dic[@"isSupportZoom"] boolValue]; UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init]; if (!isSupportZoom) {//电子放大与焦距变倍不共存 [_remoteView addGestureRecognizer:pinchGestureRecognizer]; } self.pinchGestureRecognizer = pinchGestureRecognizer; //右边的画质图标 //进入横屏时,显示 //退出横屏时,隐藏 int rightItemCount = 3; //半透明背景 UIView *controllerRightBg = [[UIView alloc] initWithFrame:CGRectMake(5.0, height, CONTROLLER_RIGHT_ITEM_WIDTH, CONTROLLER_RIGHT_ITEM_HEIGHT*rightItemCount)]; controllerRightBg.layer.cornerRadius = 1.0f; [controllerRightBg setAlpha:0.5]; [controllerRightBg setBackgroundColor:XBlack]; self.controllerRightBg = controllerRightBg; [self.view addSubview:controllerRightBg]; [self.controllerRightBg setHidden:YES]; UIView *controllerRight = [[UIView alloc] initWithFrame:CGRectMake(5.0, height, CONTROLLER_RIGHT_ITEM_WIDTH, CONTROLLER_RIGHT_ITEM_HEIGHT*rightItemCount)]; self.controllerRight = controllerRight; [self.view addSubview:controllerRight]; [self.controllerRight setHidden:YES]; //分隔线 for (int i=1; i < rightItemCount; i++) { UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, i*CONTROLLER_RIGHT_ITEM_HEIGHT+1.0*(i-1), CONTROLLER_RIGHT_ITEM_WIDTH, 1.0)]; lineView.backgroundColor = XWhite; [controllerRight addSubview:lineView]; } for(int i=0;i scrollView.contentSize.width)?(scrollView.bounds.size.width - scrollView.contentSize.width)/2 : 0.0; CGFloat offsetY = (scrollView.bounds.size.height > scrollView.contentSize.height)?(scrollView.bounds.size.height - scrollView.contentSize.height)/2 : 0.0; self.remoteView.center = CGPointMake(scrollView.contentSize.width/2 + offsetX,scrollView.contentSize.height/2 + offsetY); } } //监控界面缩放 -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{ if(scale>1.0){ if (self.isShowControllerBar) { self.isShowControllerBar = !self.isShowControllerBar; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; [self.controllerRightBg setAlpha:0.0]; [self.controllerRight setAlpha:0.0]; [self.bottomView setAlpha:0.0]; [self.bottomBarView setAlpha:0.0]; [self.customBorderButton setAlpha:0.0]; [self.leftView setAlpha:0.0]; [UIView commitAnimations]; } } if (self.isFullScreen) { if(scale>1.0){ self.isScale = YES; }else{ self.isScale = NO; } } } #pragma mark - 对讲 -(void)onBegin:(TouchButton *)touchButton widthTouches:(NSSet *)touches withEvent:(UIEvent *)event{ DLog(@"onBegin"); [self.pressView setHidden:NO]; // [[PAIOUnit sharedUnit] setSpeckState:NO]; } -(void)onCancelled:(TouchButton *)touchButton widthTouches:(NSSet *)touches withEvent:(UIEvent *)event{ DLog(@"onCancelled"); [self.pressView setHidden:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; } -(void)onEnded:(TouchButton *)touchButton widthTouches:(NSSet *)touches withEvent:(UIEvent *)event{ DLog(@"onEnded"); [self.pressView setHidden:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; } -(void)onMoved:(TouchButton *)touchButton widthTouches:(NSSet *)touches withEvent:(UIEvent *)event{ DLog(@"onMoved"); } #pragma mark - 横屏时的按钮(画质、声音...) -(void)onControllerBtnPress:(id)sender{ UIButton *button = (UIButton*)sender; switch(button.tag){ case CONTROLLER_BTN_TAG_HUNGUP: { if(!self.isReject){ self.isReject = !self.isReject; while (_isPlaying) { usleep(50*1000); } [[P2PClient sharedClient] p2pHungUp]; self.remoteView.isQuitMonitorInterface = YES;//rtsp监控界面弹出修改 } //[self dismissViewControllerAnimated:YES completion:nil]; } break; case CONTROLLER_BTN_TAG_SOUND: { //BOOL isMute = [[PAIOUnit sharedUnit] muteAudio]; DLog(@"onControllerBtnPress:CONTROLLER_BTN_TAG_SOUND"); // if(isMute){ // [[PAIOUnit sharedUnit] setMuteAudio:NO]; // [sender setBackgroundImage:[UIImage imageNamed:@"ic_ctl_new_sound_on.png"] forState:UIControlStateNormal]; // //竖屏,声音打开 // UIButton *soundButtonH = (UIButton *)[self.midToolHView viewWithTag:SOUND_BUTTON_H_TAG]; // UIImageView *soundImageViewH = (UIImageView *)soundButtonH.subviews[0]; // soundImageViewH.image = [UIImage imageNamed:@"monitor_sound_on_h.png"]; // }else{ // // [[PAIOUnit sharedUnit] setMuteAudio:YES]; // [sender setBackgroundImage:[UIImage imageNamed:@"ic_ctl_new_sound_off.png"] forState:UIControlStateNormal]; // //竖屏,声音关闭 // UIButton *soundButtonH = (UIButton *)[self.midToolHView viewWithTag:SOUND_BUTTON_H_TAG]; // UIImageView *soundImageViewH = (UIImageView *)soundButtonH.subviews[0]; // soundImageViewH.image = [UIImage imageNamed:@"monitor_sound_off_h.png"]; // } } break; case CONTROLLER_BTN_TAG_SCREENSHOT: { [self.remoteView setIsScreenShotting:YES]; } break; case CONTROLLER_BTN_TAG_GPIO1_0: { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"door_bell", nil) message:NSLocalizedString(@"confirm_open", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", nil) otherButtonTitles:NSLocalizedString(@"ok", nil), nil]; alertView.tag = DOOR_BELLALERT; [alertView show]; } break; case CONTROLLER_BTN_TAG_PRESS_TALK://支持门铃,点按开关说话 { if (self.isTalking) { //竖屏,对讲关闭 UIButton *talkButtonH = (UIButton *)[self.bottomToolHView viewWithTag:TALK_BUTTON_H_TAG]; talkButtonH.selected = NO; //横屏,对讲关闭 [sender setBackgroundImage:[UIImage imageNamed:@"ic_ctl_new_send_audio.png"] forState:UIControlStateNormal]; self.isTalking = NO; [self.pressView setHidden:YES]; //[[PAIOUnit sharedUnit] setSpeckState:YES]; }else{ UIButton *talkButtonH = (UIButton *)[self.bottomToolHView viewWithTag:TALK_BUTTON_H_TAG]; //竖屏,对讲打开 talkButtonH.selected = YES; //横屏,对讲打开 [sender setBackgroundImage:[UIImage imageNamed:@"ic_ctl_new_send_audio_p.png"] forState:UIControlStateNormal]; self.isTalking = YES; [self.pressView setHidden:NO]; //[[PAIOUnit sharedUnit] setSpeckState:NO]; } } break; case CONTROLLER_BTN_TAG_DEFENCE_LOCK://重新调整监控画面 { NSString *contactId = [[P2PClient sharedClient] callId]; NSString *contactPassword = [[P2PClient sharedClient] callPassword]; if (self.isDefenceOn) { [[P2PClient sharedClient] setRemoteDefenceWithId:contactId password:contactPassword state:SETTING_VALUE_REMOTE_DEFENCE_STATE_OFF]; }else{ [[P2PClient sharedClient] setRemoteDefenceWithId:contactId password:contactPassword state:SETTING_VALUE_REMOTE_DEFENCE_STATE_ON]; } } break; case CONTROLLER_BTN_TAG_HD: { [[P2PClient sharedClient] sendCommandType:USR_CMD_VIDEO_CTL andOption:7]; [self updateRightButtonState:CONTROLLER_BTN_TAG_HD]; } break; case CONTROLLER_BTN_TAG_SD: { [[P2PClient sharedClient] sendCommandType:USR_CMD_VIDEO_CTL andOption:5]; [self updateRightButtonState:CONTROLLER_BTN_TAG_SD]; } break; case CONTROLLER_BTN_TAG_LD: { [[P2PClient sharedClient] sendCommandType:USR_CMD_VIDEO_CTL andOption:6]; [self updateRightButtonState:CONTROLLER_BTN_TAG_LD]; } break; } } #pragma mark - UIAlertViewDelegate(开门) -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (alertView.tag == XUANDUO_GUANSHUIBENG_ALERT) { //解绑关系弹窗 if ( buttonIndex ==1 ) { [self guanbiShuiBeng]; } }else if(alertView.tag == CAMERA_DEVICE_JIEBANG_ALERT) { //解绑关系弹窗 if ( buttonIndex ==1 ) { [self camerDeviceDelectRelate]; } }else if (alertView.tag == DOOR_BELLALERT){ if (buttonIndex==1) { //GPIO口开锁 int time[8] = {0}; time[0] = -15; time[1] = 6000; time[2] = -1; //记录当前的GPIO设置参数 self.lastGroup = 1; self.lastPin = 0; self.lastValue = 3; self.lastTime = time; NSString *contactId = [[P2PClient sharedClient] callId]; NSString *contactPassword = [[P2PClient sharedClient] callPassword]; [[P2PClient sharedClient] setGpioCtrlWithId:contactId password:contactPassword group:1 pin:0 value:3 time:time]; //透传开锁 [[P2PClient sharedClient] sendCustomCmdWithId:contactId password:contactPassword cmd:@"IPC1anerfa:unlock"]; } }else if (alertView.tag == WEIJIHUO_ALERT){ if (buttonIndex ==0) { //取消 [self stopGLViewVideo]; [Socketsingleton sharedInstance].communiteDelegate=nil; [[Socketsingleton sharedInstance] cutOffSocket]; [self.remoteView getLastImgGoback]; [AppDelegate sharedDefault].canFullScreen = NO; [self.remoteView releseromotViewSet]; [self setAppTabRoot]; }else if (buttonIndex ==1){ //扫码激活 [self stopGLViewVideo]; ScanViewController*scanVC=[[ScanViewController alloc]init]; scanVC.cameraModel = self.contact ; UINavigationController * nVC = [[UINavigationController alloc]initWithRootViewController:scanVC]; [self presentViewController: nVC animated:YES completion:^{ }]; } }else if (alertView.tag == ALERT_TAG_UPDATE){ if(buttonIndex==1){ //确定固件升级 UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"提示" message:@"正在升级中,升级过程中摄像头会离线,两分钟后摄像头会自动重连,再点击播放按钮即可。" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil]; alert.tag = ALERT_UPDATE_SURE; [alert show]; [[P2PClient sharedClient] doDeviceUpdateWithId:self.contact.cameraId password:self.contact.cameraPass]; }else{ [[P2PClient sharedClient] cancelDeviceUpdateWithId:self.contact.cameraId password:self.contact.cameraPass]; } }else if (alertView.tag == ALERT_TAG_UPDATE){ } } #pragma mark-OPENGL 代理 截图 -(void)onScreenShotted:(UIImage *)image{ UIImage *tempImage = [[UIImage alloc] initWithCGImage:image.CGImage]; NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(tempImage)]; [Utils saveScreenshotFile:imgData]; //[self popLXAdViewWith:tempImage]; dispatch_async(dispatch_get_main_queue(), ^{ //[self.view makeToast:NSLocalizedString(@"screenshot_success", nil)]; [self.view makeToast:@"截图成功,请在图库中查看"]; }); } -(void)popLXAdViewWith:(UIImage*)image{ // 关闭pop效果添加按钮 // [_contentView addSubview:_popBtn]; UIImageView *imageV = [[UIImageView alloc]initWithFrame:_shutterView.bounds]; imageV.image = image ; [_shutterView addSubview:imageV]; [LXADViewTool sharedInstance].shadeBackgroundType = ShadeBackgroundTypeSolid; [LXADViewTool sharedInstance].closeButtonType = ButtonPositionTypeRight; [[LXADViewTool sharedInstance] showWithPresentView:_shutterView animated:YES]; AudioServicesPlaySystemSound (1108); [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(closeLXAdView) userInfo:nil repeats:NO]; } - (void)closeLXAdView{ [[LXADViewTool sharedInstance] closeWithBlcok:^{ }]; } #pragma mark - 隐藏监控连接中的UI -(void)hiddenMonitoringUI:(BOOL)isHidden callErrorInfo:(NSDictionary*)info isReCall:(BOOL)isReCall{ if (isHidden) { [self.yProgressView stop]; [self.yProgressView setHidden:YES]; [self.labelTip setHidden:YES]; [self.promptButton setEnabled:NO]; [self.promptButton setHidden:YES]; [self.stopBtnH setEnabled:YES]; }else{ if (isReCall) { self.yProgressView.backgroundView.image = LXImageWithImageName(@"monitor_press.png"); [self.yProgressView start]; self.labelTip.text = [NSString stringWithFormat:@"%@",NSLocalizedString(@"monitor_out_prompt", nil)]; [self.promptButton setEnabled:NO]; self.stopImageViewH.image = LXImageWithImageName(@"monitor_stop_h.png"); // 禁用 底部栏暂停按钮 [self.stopBtnH setEnabled:NO]; }else{ if (_isStop) { //暂停 self.yProgressView.angle = 0.0f; self.yProgressView.backgroundView.image = LXImageWithImageName(@"ifishCamera_start"); int errorFlag = [[info objectForKey:@"errorFlag"] intValue]; self.labelTip.text = [self getCallErrorStringWith:errorFlag]; self.stopImageViewH.image = LXImageWithImageName(@"monitor_on_h.png"); }else{ self.yProgressView.angle = 0.0f; self.yProgressView.backgroundView.image = LXImageWithImageName(@"ifishCamera_start"); int errorFlag = [[info objectForKey:@"errorFlag"] intValue]; //int errorFlag = CALL_ERROR_HANGUP ; self.labelTip.text = [self getCallErrorStringWith:errorFlag]; self.stopImageViewH.image = LXImageWithImageName(@"monitor_on_h.png"); } self.yProgressView.angle = 0.0f; [self.yProgressView stop]; int errorFlag = [[info objectForKey:@"errorFlag"] intValue]; self.labelTip.text = [self getCallErrorStringWith:errorFlag]; [self.promptButton setEnabled:YES]; [self.stopBtnH setEnabled:YES]; } [self.yProgressView setHidden:NO]; [self.labelTip setHidden:NO]; [self.promptButton setHidden:NO]; [self.canvasView bringSubviewToFront:self.promptButton]; } } -(NSString *)getCallErrorStringWith:(int)errorFlag{ switch(errorFlag) { case CALL_ERROR_NONE: { return NSLocalizedString(@"id_unknown_error", nil); } break; case CALL_ERROR_DESID_NOT_ENABLE: { return NSLocalizedString(@"id_disabled", nil); } break; case CALL_ERROR_DESID_OVERDATE: { return NSLocalizedString(@"id_overdate", nil); } break; case CALL_ERROR_DESID_NOT_ACTIVE: { return NSLocalizedString(@"id_inactived", nil); } break; case CALL_ERROR_DESID_OFFLINE: { return NSLocalizedString(@"id_offline", nil); } break; case CALL_ERROR_DESID_BUSY: { return NSLocalizedString(@"id_busy", nil); } break; case CALL_ERROR_DESID_POWERDOWN: { return NSLocalizedString(@"id_powerdown", nil); } break; case CALL_ERROR_NO_HELPER: { return NSLocalizedString(@"id_connect_failed", nil); } break; case CALL_ERROR_HANGUP: { return NSLocalizedString(@"id_hangup", nil); break; } case CALL_ERROR_TIMEOUT: { return NSLocalizedString(@"id_timeout", nil); } break; case CALL_ERROR_INTER_ERROR: { return NSLocalizedString(@"id_internal_error", nil); } break; case CALL_ERROR_RING_TIMEOUT: { return NSLocalizedString(@"id_no_accept", nil); } break; case CALL_ERROR_PW_WRONG: { return NSLocalizedString(@"id_password_error", nil); } break; case CALL_ERROR_CONN_FAIL: { return NSLocalizedString(@"id_connect_failed", nil); } break; case CALL_ERROR_NOT_SUPPORT: { return NSLocalizedString(@"id_not_support", nil); } break; default: { return NSLocalizedString(@"id_unknown_error", nil); } break; } } -(void)didHiddenMonitorUIWith:(BOOL)isAfterRender{ if (!isAfterRender) { [self.controllerRightBg setAlpha:0.0]; [self.controllerRight setAlpha:0.0]; [self.bottomView setAlpha:0.0]; [self.bottomBarView setAlpha:0.0]; [self.customBorderButton setAlpha:0.0]; [self.leftView setAlpha:0.0]; [self.focalLengthView setAlpha:0.0]; [self.pressView setAlpha:0.0]; }else{ [self.controllerRightBg setAlpha:0.5]; [self.controllerRight setAlpha:1.0]; [self.bottomView setAlpha:0.5]; [self.bottomBarView setAlpha:1.0]; [self.customBorderButton setAlpha:0.5]; [self.leftView setAlpha:0.5]; [self.focalLengthView setAlpha:1.0]; [self.pressView setAlpha:1.0]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (TouchButton *)getControllerButton { TouchButton *button = [TouchButton buttonWithType:UIButtonTypeCustom]; [button setFrame:CGRectMake(0, 0, 50, 38)]; [button setAlpha:0.5]; [button setOpaque:YES]; [button setBackgroundColor:[UIColor darkGrayColor]]; [button.layer setBorderColor:[[UIColor blackColor] CGColor]]; [button.layer setBorderWidth:2.0f]; return button; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ #pragma mark - 设置高清、标清选中 -(void)updateRightButtonState:(NSInteger)tag{ for(UIView *view in self.controllerRight.subviews){ UILabel *labelHD = (UILabel *)[view viewWithTag:CONTROLLER_LABEL_TAG_HD]; if (labelHD) { labelHD.textColor = XWhite; } UILabel *labelSD = (UILabel *)[view viewWithTag:CONTROLLER_LABEL_TAG_SD]; if (labelSD) { labelSD.textColor = XWhite; } UILabel *labelLD = (UILabel *)[view viewWithTag:CONTROLLER_LABEL_TAG_LD]; if (labelLD) { labelLD.textColor = XWhite; } } UIButton *button = (UIButton*)[self.controllerRight viewWithTag:tag]; //重新调整监控画面 UIButton *rButton = (UIButton *)[self.bottomBarView viewWithTag:CONTROLLER_BTN_TAG_RESOLUTION]; if (tag == CONTROLLER_BTN_TAG_HD) { UILabel *label = (UILabel *)[button viewWithTag:CONTROLLER_LABEL_TAG_HD]; label.textColor = XBlue; //[rButton setTitle:NSLocalizedString(@"HD", nil) forState:UIControlStateNormal]; [rButton setTitle:NSLocalizedString(@"高清", nil) forState:UIControlStateNormal]; }else if(tag == CONTROLLER_BTN_TAG_SD){ UILabel *label = (UILabel *)[button viewWithTag:CONTROLLER_LABEL_TAG_SD]; label.textColor = XBlue; //[rButton setTitle:NSLocalizedString(@"SD", nil) forState:UIControlStateNormal]; [rButton setTitle:NSLocalizedString(@"标清", nil) forState:UIControlStateNormal]; }else if (tag == CONTROLLER_BTN_TAG_LD){ UILabel *label = (UILabel *)[button viewWithTag:CONTROLLER_LABEL_TAG_LD]; label.textColor = XBlue; //[rButton setTitle:NSLocalizedString(@"LD", nil) forState:UIControlStateNormal]; [rButton setTitle:NSLocalizedString(@"流畅", nil) forState:UIControlStateNormal]; } [self didHiddenResolutionInterface]; } - (void)swipeUp:(id)sender { [[P2PClient sharedClient] sendCommandType:USR_CMD_PTZ_CTL andOption:USR_CMD_OPTION_PTZ_TURN_DOWN]; } - (void)swipeDown:(id)sender { [[P2PClient sharedClient] sendCommandType:USR_CMD_PTZ_CTL andOption:USR_CMD_OPTION_PTZ_TURN_UP]; } - (void)swipeLeft:(id)sender { [[P2PClient sharedClient] sendCommandType:USR_CMD_PTZ_CTL andOption:USR_CMD_OPTION_PTZ_TURN_LEFT]; } - (void)swipeRight:(id)sender { [[P2PClient sharedClient] sendCommandType:USR_CMD_PTZ_CTL andOption:USR_CMD_OPTION_PTZ_TURN_RIGHT]; } //竖屏幕 时 -(void)dismissMidToolView{ __weak typeof(self) wself = self; if (wself.stopBtnH.hidden == YES) { [UIView animateWithDuration:0.5 animations:^{ CGFloat midtH=wself.canvasView.frame.size.height/5; wself.midToolHView.frame = CGRectMake(0.0, CGRectGetMaxY(wself.canvasView.frame) - midtH, kScreenSize.width, midtH); wself.stopBtnH.hidden = NO; wself.switchScreenButtonH.hidden = NO; wself.isShowVToolBar = YES; } completion:^(BOOL finished) { [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(dismissMidToolView) userInfo:nil repeats:NO]; }]; }else{ [UIView animateWithDuration:0.5 animations:^{ wself.midToolHView.frame = CGRectMake(0.0, CGRectGetMaxY(wself.canvasView.frame), kScreenSize.width, 0); wself.stopBtnH.hidden = YES; wself.switchScreenButtonH.hidden = YES; wself.isShowVToolBar = NO; } completion:^(BOOL finished) { }]; } } -(void)onSingleTap{ if (!self.isFullScreen) { //竖屏时点击屏幕 弹出工具栏打开下面方法 5s 自动消失 if (self.isShowVToolBar) { return; } [self dismissMidToolView]; }else{ if (!self.isShowControllerBar) { [self hidHbottomView]; } } } #pragma mark - 隐藏横屏底部控件 -(void)hidHbottomView{ if (self.isShowControllerBar) { self.isShowControllerBar = !self.isShowControllerBar; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; [self.controllerRightBg setAlpha:0.0];//重新调整监控画面 [self.controllerRight setAlpha:0.0]; [self.bottomView setAlpha:0.0];//重新调整监控画面 [self.bottomBarView setAlpha:0.0];//重新调整监控画面 [self.customBorderButton setAlpha:0.0]; [self.leftView setAlpha:0.0]; [self.focalLengthView setAlpha:0.0]; [UIView commitAnimations]; }else{ self.isShowControllerBar = !self.isShowControllerBar; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; [self.controllerRightBg setAlpha:0.5];//重新调整监控画面 [self.controllerRight setAlpha:1.0];//重新调整监控画面 [self.bottomView setAlpha:0.5];//重新调整监控画面 [self.bottomBarView setAlpha:1.0];//重新调整监控画面 [self.customBorderButton setAlpha:0.5]; [self.leftView setAlpha:0.5]; [self.focalLengthView setAlpha:1.0]; [UIView commitAnimations]; [self hideBootommViewAfterSecondes]; } //重新调整监控画面 [self didHiddenResolutionInterface]; } -(void)onDoubleTap{ if (!self.isFullScreen) { // if (_isStop == NO) { // [self hiddenMonitoringUI:NO callErrorInfo:nil isReCall:NO]; // _isStop = YES; // } // // [self stopGLViewVideo]; return; } if (self.isScale) { //处于电子放大时,不往下执行 return; } BOOL is16B9 = [[P2PClient sharedClient] is16B9]; if(!is16B9){ //渲染画面4:3 CGRect rect = [AppDelegate getScreenSize:NO isHorizontal:YES]; CGFloat width = rect.size.width; CGFloat height = rect.size.height; if(CURRENT_VERSION<7.0){ height +=20; } if (self.isFullScreen4B3) { self.isFullScreen4B3 = !self.isFullScreen4B3; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; CGAffineTransform transform; transform = CGAffineTransformMakeScale(1.0, 1.0f); self.remoteView.transform = transform; [UIView commitAnimations]; }else{ self.isFullScreen4B3 = !self.isFullScreen4B3; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; if (CURRENT_VERSION>=8.0) { CGAffineTransform transform = CGAffineTransformMakeScale(height/(width*4/3),1.0f); self.remoteView.transform = transform; }else{ CGAffineTransform transform = CGAffineTransformMakeScale(width/(height*4/3),1.0f); self.remoteView.transform = transform; } [UIView commitAnimations]; } } } #pragma mark- 暂停 挂断 -(void)stopGLViewVideo{ if(!self.isReject){ self.isReject = !self.isReject; while (_isPlaying) { usleep(50*1000); } [[P2PClient sharedClient] p2pHungUp]; self.remoteView.isQuitMonitorInterface = NO;//rtsp监控界面弹出修改 } } #pragma mark- 回放挂断 -(void)palyBackStopGLView { //self.remoteView.isQuitMonitorInterface = NO;//rtsp监控界面弹出修改 //[self.remoteView releseromotViewSet]; } #pragma mark - 计算文本的尺寸 -(CGSize)sizeWithString:(NSString*)string font:(UIFont*)font maxWidth:(CGFloat)maxWidth{ if ([UIDevice currentDevice].systemVersion.floatValue < 7.0) { CGSize sizeToFit = [string sizeWithFont:font constrainedToSize:CGSizeMake(maxWidth, MAXFLOAT)]; return sizeToFit; }else{ NSDictionary *dict = @{NSFontAttributeName : font}; CGRect rectToFit = [string boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil]; return rectToFit.size; } } //rtsp监控界面弹出修改 #pragma mark - 渲染监控界面 -(void)monitorStartRender:(NSNotification*)notification{ //监控横屏rect CGFloat height = _monitorInterfaceH; BOOL is16B9 = [[P2PClient sharedClient] is16B9]; BOOL is960P = [[P2PClient sharedClient] is960P]; //右边的画质图标 //进入横屏时,显示 //退出横屏时,隐藏 UIView *lineView1 = self.controllerRight.subviews[0]; UIButton *buttonHD = (UIButton *)[self.controllerRight viewWithTag:CONTROLLER_BTN_TAG_HD]; UIButton *buttonSD = (UIButton *)[self.controllerRight viewWithTag:CONTROLLER_BTN_TAG_SD]; UILabel *labelSD = (UILabel *)[buttonSD viewWithTag:CONTROLLER_LABEL_TAG_SD]; UIButton *buttonLD = (UIButton *)[self.controllerRight viewWithTag:CONTROLLER_BTN_TAG_LD]; UILabel *labelLD = (UILabel *)[buttonLD viewWithTag:CONTROLLER_LABEL_TAG_LD]; UILabel *labelHD = (UILabel *)[buttonLD viewWithTag:CONTROLLER_LABEL_TAG_HD]; if(is16B9 || is960P){//支持高清 //半透明背景 self.controllerRightBg.frame = CGRectMake(5.0, height, CONTROLLER_RIGHT_ITEM_WIDTH, CONTROLLER_RIGHT_ITEM_HEIGHT*3); //分隔线 [lineView1 setHidden:NO]; //高清按钮 [buttonHD setHidden:NO]; //标清文本 labelSD.textColor = XWhite; //流畅文本 labelLD.textColor = XWhite; //高清文本 labelHD.textColor = XBlue; }else{//不支持高清 self.controllerRightBg.frame = CGRectMake(5.0, height, CONTROLLER_RIGHT_ITEM_WIDTH, CONTROLLER_RIGHT_ITEM_HEIGHT*2); //分隔线 [lineView1 setHidden:YES]; //高清按钮 [buttonHD setHidden:YES]; //标清文本 labelSD.textColor = XWhite; //流畅文本 labelLD.textColor = XBlue; } UIButton *resolutionButton = (UIButton *)[self.bottomBarView viewWithTag:CONTROLLER_BTN_TAG_RESOLUTION]; if(is16B9 || is960P){//支持高清 [resolutionButton setTitle:NSLocalizedString(@"HD", nil) forState:UIControlStateNormal]; }else{//不支持高清 [resolutionButton setTitle:NSLocalizedString(@"LD", nil) forState:UIControlStateNormal]; } //开始渲染 self.isReject = NO; [NSThread detachNewThreadSelector:@selector(renderView) toTarget:self withObject:nil]; //根据访客密码监控、门铃监控来重新布局controllBar上的按钮 [self reLayoutButtonInControlBar]; [self doOperationsAfterMonitorStartRender]; } #pragma mark - 改变焦距 -(void)btnClickToChangeFocalLength:(id)sender{ UIView *view = (UIView *)sender; if (view.tag == FocalLength_Elongation_btnTag) { //焦距变长 BYTE cmdData[5] = {0}; cmdData[0] = 0x05; fgSendUserData(9, 1, cmdData, sizeof(cmdData)); }else if (view.tag == FocalLength_Shorten_btnTag){ //焦距变短 BYTE cmdData[5] = {0}; cmdData[0] = 0x15; fgSendUserData(9, 1, cmdData, sizeof(cmdData)); }else{ UISlider *focalLengthSlider = (UISlider *)view; if (focalLengthSlider.value < 7.5) { //焦距变长 BYTE cmdData[5] = {0}; cmdData[0] = 0x05; fgSendUserData(9, 1, cmdData, sizeof(cmdData)); }else{ //焦距变短 BYTE cmdData[5] = {0}; cmdData[0] = 0x15; fgSendUserData(9, 1, cmdData, sizeof(cmdData)); } focalLengthSlider.value = 7.5; } } #pragma mark - 焦距变倍 -(void)localLengthPinchToZoom:(id)sender { if (!self.isFullScreen) { return; } if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { if ([(UIPinchGestureRecognizer*)sender scale] > 1.0) { BYTE cmdData[5] = {0}; cmdData[0] = 0x05; fgSendUserData(9, 2, cmdData, sizeof(cmdData)); }else{ BYTE cmdData[5] = {0}; cmdData[0] = 0x15; fgSendUserData(9, 2, cmdData, sizeof(cmdData)); } } } #pragma mark - 监控开始渲染后,此处执行相关操作 -(void)doOperationsAfterMonitorStartRender{//rtsp监控界面弹出修改 /* *1. 应该放在监控准备就绪之后(即渲染之后) */ //[[PAIOUnit sharedUnit] setMuteAudio:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; //放在渲染之后 if([AppDelegate sharedDefault].isDoorBellAlarm){//门铃推送,点按开关说话 self.isTalking = YES; [self.pressView setHidden:NO]; // [[PAIOUnit sharedUnit] setSpeckState:NO]; }else{ self.isTalking = NO; [self.pressView setHidden:YES]; // [[PAIOUnit sharedUnit] setSpeckState:YES]; } // //竖屏对讲按钮 // UIButton *talkButtonH = (UIButton *)[self.bottomToolHView viewWithTag:TALK_BUTTON_H_TAG]; // if([AppDelegate sharedDefault].isDoorBellAlarm){//门铃推送 // talkButtonH.selected = YES; // }else{ // talkButtonH.selected = NO; // } // //横屏对讲按钮 // TouchButton *controllerTalkBtn = (TouchButton *)[self.controllBar viewWithTag:CONTROLLER_BTN_TAG_PRESS_TALK]; // //非本地设备 // NSInteger deviceType1 = [AppDelegate sharedDefault].contact.contactType; // //本地设备 // NSInteger deviceType2 = [[FListManager sharedFList] getType:[[P2PClient sharedClient] callId]]; // if (deviceType1 == CONTACT_TYPE_DOORBELL || deviceType2 == CONTACT_TYPE_DOORBELL) {//支持门铃,点按开关说话 // if([AppDelegate sharedDefault].isDoorBellAlarm){//门铃推送 // // [controllerTalkBtn setBackgroundImage:[UIImage imageNamed:@"ic_ctl_new_send_audio_p.png"] forState:UIControlStateNormal]; // } // if (controllerTalkBtn.delegate) { // controllerTalkBtn.delegate = nil; // } // [controllerTalkBtn addTarget:self action:@selector(onControllerBtnPress:) forControlEvents:UIControlEventTouchUpInside]; // }else{ // //不是门铃,则按住说话 // [controllerTalkBtn setBackgroundImage:[UIImage imageNamed:@"ic_ctl_new_send_audio.png"] forState:UIControlStateNormal]; // [controllerTalkBtn removeTarget:self action:@selector(onControllerBtnPress:) forControlEvents:UIControlEventTouchUpInside]; // controllerTalkBtn.delegate = self; // } //放在渲染之后 //获取当前被监控帐号的灯状态 //若设备支持灯设备时,则显示开关按钮;若不支持,则隐藏 // NSString *contactId = [[P2PClient sharedClient] callId]; // NSString *contactPassword = [[P2PClient sharedClient] callPassword]; // [[P2PClient sharedClient] getLightStateWithDeviceId:contactId password:contactPassword]; NSString *callId = [[P2PClient sharedClient] callId]; NSString *callPassword = [[P2PClient sharedClient] callPassword]; [[P2PClient sharedClient]getDefenceState:callId password:callPassword]; //判断设备是否支持变倍变焦(38) [[P2PClient sharedClient] getNpcSettingsWithId:callId password:callPassword]; } #pragma mark - 竖屏时,显示状态栏 -(BOOL)prefersStatusBarHidden { return NO; } #pragma mark - 屏幕Autorotate -(BOOL)shouldAutorotate{ return YES; } #pragma mark 屏幕支持的旋转方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface { return (interface == UIInterfaceOrientationPortrait || interface == UIInterfaceOrientationLandscapeRight); } // #ifdef IOS6 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; } #endif // #pragma mark 支持哪些方向 -(UIInterfaceOrientationMask)supportedInterfaceOrientations{ if (_isCanAutoOrientation) { return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeRight; } return UIInterfaceOrientationMaskPortrait; } #pragma mark 一开始希望的屏幕方向 -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationPortrait; } #pragma mark - 屏幕旋转 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { [self quitFullController]; } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { [self enterFullController]; } } #pragma mark 屏幕旋转(退出全屏) -(void)quitFullController{ if (self.scrollView){ [self.scrollView setZoomScale:1.0]; } self.isFullScreen = NO; [[UIApplication sharedApplication] setStatusBarHidden:NO]; self.navigationController.navigationBar.hidden = NO; //隐藏横屏里的控件 [self.controllerRightBg setHidden:YES]; [self.controllerRight setHidden:YES]; [self.bottomView setHidden:YES]; [self.bottomBarView setHidden:YES]; [self.customBorderButton setHidden:YES]; [self.leftView setHidden:YES]; if (self.isSupportLightSwitch) { [self.lightButton setHidden:YES]; } if (self.isSupportFocalLength) { [self.focalLengthView setHidden:YES]; } //显示竖屏里的控件 //[self.topBar setHidden:NO]; [self.midToolHView setHidden:NO]; [self.bottomToolHView setHidden:NO]; [self.segControl setHidden:NO]; [self.fishControlView setHidden:NO]; //视频监控连接中的背景图片 //进入竖屏时,调整frame self.canvasView.frame = self.canvasframe; //视频监控连接中的背景图片 NSString *filePath = [Utils getHeaderFilePathWithId:[[P2PClient sharedClient] callId]]; UIImage *headImg = [UIImage imageWithContentsOfFile:filePath]; if(headImg==nil){ headImg = [UIImage imageNamed:@"ic_header.png"]; } self.canvasView.layer.contents = (id)headImg.CGImage; self.remoteView.frame = CGRectMake(0.0, 0.0, self.canvasframe.size.width, self.canvasframe.size.height); // BOOL is16B9 = [[P2PClient sharedClient] is16B9]; // if (is16B9) { // [UIView beginAnimations:nil context:nil]; // [UIView setAnimationDuration:0.2]; // // if (CURRENT_VERSION>=8.0) { // // self.remoteView.layer.contentsScale = [UIScreen mainScreen].scale; //// CGRect rect = [AppDelegate getScreenSize:YES isHorizontal:NO]; //// CGFloat width = rect.size.width; // // //// CGAffineTransform transform = CGAffineTransformMakeScale(16/9,16/9); //// self.remoteView.transform = transform; //// // // // }else{ // CGAffineTransform transform = CGAffineTransformMakeScale(1.0f,1.0f); // self.remoteView.transform = transform; // } // [UIView commitAnimations]; // // } NSString * plist = [[NSBundle mainBundle] pathForResource:@"Common-Configuration" ofType:@"plist"]; NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:plist]; BOOL isSupportZoom = [dic[@"isSupportZoom"] boolValue]; if (isSupportZoom) { //退出全屏时,要将remoteView添加回到canvasView if (self.remoteView.superview) { [self.remoteView removeFromSuperview]; } //监控界面缩放 if (self.scrollView){ if (self.scrollView.superview) { [self.scrollView removeFromSuperview]; } _scrollView = nil; } [self.canvasView addSubview:self.remoteView]; } //视频监控连接中的文字提示,以及旋转 //进入横屏时,调整frame self.promptButton.frame = CGRectMake(0.0, 0.0, self.canvasView.frame.size.width, self.canvasView.frame.size.height); //上面的canvasView重新add了remoteView [self.canvasView bringSubviewToFront:self.promptButton]; NSString *labelTipText = [NSString stringWithFormat:@"%@",NSLocalizedString(@"玩命加载中...", nil)]; CGSize size = [labelTipText sizeWithFont:XFontBold_16]; //旋转图片 CGFloat tipHeight = size.height + LOADINGPRESSVIEW_WIDTH_HEIGHT; self.yProgressView.frame = CGRectMake((self.canvasView.frame.size.width-LOADINGPRESSVIEW_WIDTH_HEIGHT)/2, (self.canvasView.frame.size.height-tipHeight)/2, LOADINGPRESSVIEW_WIDTH_HEIGHT, LOADINGPRESSVIEW_WIDTH_HEIGHT); //文字 self.labelTip.frame = CGRectMake((self.canvasView.frame.size.width-size.width)/2, CGRectGetMaxY(self.yProgressView.frame), size.width+10.0, size.height); //左边的按住说话弹出的声音图标 //退出横屏时,调整frame self.pressView.frame = CGRectMake(10, self.canvasframe.size.height+NAVIGATION_BAR_HEIGHT-PRESS_LAYOUT_WIDTH_AND_HEIGHT, PRESS_LAYOUT_WIDTH_AND_HEIGHT/2, PRESS_LAYOUT_WIDTH_AND_HEIGHT); } #pragma mark - 屏幕旋转(进入全屏) -(void)enterFullController{ //ios 9 self.isFullScreen = YES; [[UIApplication sharedApplication] setStatusBarHidden:YES]; //隐藏竖屏里的控件 [self.midToolHView setHidden:YES]; [self.segControl setHidden:YES]; [self.bottomToolHView setHidden:YES]; [self.fishControlView setHidden:YES]; //显示横屏里的控件 [self.controllerRightBg setHidden:NO]; [self.controllerRight setHidden:NO]; [self.bottomView setHidden:NO]; [self.bottomBarView setHidden:NO]; [self.customBorderButton setHidden:NO]; [self.leftView setHidden:NO]; if (self.isSupportLightSwitch) { [self.lightButton setHidden:NO]; } if (self.isSupportFocalLength) { [self.focalLengthView setHidden:YES];//横屏也隐藏变焦控件 } //监控横屏rect CGFloat width = _monitorInterfaceW; CGFloat height = _monitorInterfaceH; //视频监控连接中的背景图片 //进入横屏时,调整frame self.canvasView.frame = CGRectMake(0.0, 0.0, width, height); self.canvasView.layer.contents = (id)self.fullScreenBgView; //视频监控连接中的文字提示,以及旋转 //进入横屏时,调整frame self.promptButton.frame = self.canvasView.frame; NSString *labelTipText = [NSString stringWithFormat:@"%@",NSLocalizedString(@"玩命加载中...", nil)]; CGSize size = [labelTipText sizeWithFont:XFontBold_16]; //旋转图片 CGFloat tipHeight = size.height + LOADINGPRESSVIEW_WIDTH_HEIGHT; self.yProgressView.frame = CGRectMake((width-LOADINGPRESSVIEW_WIDTH_HEIGHT)/2, (height-tipHeight)/2, LOADINGPRESSVIEW_WIDTH_HEIGHT, LOADINGPRESSVIEW_WIDTH_HEIGHT); //文字 self.labelTip.frame = CGRectMake((width-size.width)/2, CGRectGetMaxY(self.yProgressView.frame), size.width+10.0, size.height); //进入横屏,修改remoteView的frame BOOL is16B9 = [[P2PClient sharedClient] is16B9]; if(is16B9){ CGFloat finalWidth = height*16/9; CGFloat finalHeight = height; if(finalWidth>width){ finalWidth = width; finalHeight = width*9/16; }else{ finalWidth = height*16/9; finalHeight = height; } self.remoteView.frame = CGRectMake((width-finalWidth)/2, (height-finalHeight)/2, finalWidth, finalHeight); }else{ self.remoteView.frame = CGRectMake((width-height*4/3)/2, 0, height*4/3, height); } /* *1. 进入全屏时,创建一个缩放控件 *2. 将remoteView添加到scrollView上面(注意,退出全屏时,要将remoteView添加回到canvasView) */ NSString * plist = [[NSBundle mainBundle] pathForResource:@"Common-Configuration" ofType:@"plist"]; NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:plist]; BOOL isSupportZoom = [dic[@"isSupportZoom"] boolValue]; if (isSupportZoom) { UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; scrollView.multipleTouchEnabled = YES; scrollView.minimumZoomScale = 1.0; scrollView.maximumZoomScale = 4.0; scrollView.delegate = self; scrollView.backgroundColor = [UIColor clearColor]; if (self.remoteView.superview) { [self.remoteView removeFromSuperview]; } [scrollView addSubview:self.remoteView]; [self.canvasView addSubview:scrollView]; self.scrollView = scrollView; } //进入横屏,修改lightButton和progressView的frame self.progressView.frame = CGRectMake(self.remoteView.frame.size.width-30.0-20.0, (self.remoteView.frame.size.height-30.0)/2, 30.0, 30.0); self.lightButton.frame = CGRectMake(self.remoteView.frame.size.width-30.0-20.0, (self.remoteView.frame.size.height-30.0)/2, 30.0, 30.0); //进入横屏,修改焦距控件的frame //宽、高 CGFloat focalLengthView_w = 40.0; CGFloat focalLengthView_h = 180.0; //焦距控件与屏幕右边框的间距 CGFloat space_FocalLView_Screen = (width - self.remoteView.frame.size.width)/2+20+focalLengthView_w; self.focalLengthView.frame = CGRectMake(width-space_FocalLView_Screen, height-self.bottomBarView.frame.size.height-20.0-focalLengthView_h, focalLengthView_w, focalLengthView_h); //左边的按住说话弹出的声音图标 //进入横屏时,调整frame self.pressView.frame = CGRectMake(10, height-PRESS_LAYOUT_WIDTH_AND_HEIGHT-BOTTOM_BAR_HEIGHT, PRESS_LAYOUT_WIDTH_AND_HEIGHT/2, PRESS_LAYOUT_WIDTH_AND_HEIGHT); //设置横屏底部工具栏5秒隐藏 [self hideBootommViewAfterSecondes]; } -(void)hideBootommViewAfterSecondes{ [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(dismissHbtoomToolView) userInfo:nil repeats:NO]; } -(void)dismissHbtoomToolView{ if (self.isShowControllerBar) { [self hidHbottomView]; } } #pragma mark - 爱鱼控制器分底部协议****************************************************# -(void)didselectCollectionIex:(NSIndexPath *)indexPath withData:(DeviceModel *)dmodel addMassglength:(NSUInteger)bufferlenth{ NSLog(@"indexPath%ld",(long)indexPath.row); if (indexPath.row ==0) { //品牌 [self stopGLViewVideo]; usleep(50*1000); SongBaoViewController*brand=[[SongBaoViewController alloc]init]; brand.brandIntroduce=dmodel.brandIntroduce; [self.navigationController pushViewController:brand animated:YES]; }else if (indexPath.row ==1){ }else if (indexPath.row ==2){ //设置 [self stopGLViewVideo]; if ([dmodel.type isEqualToString:DECICE_TYPE_THREETMP]) { _rusunSet = [[RusunHaveHeateSetViewController alloc] init]; _rusunSet.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_rusunSet animated:YES]; }else if ([dmodel.type isEqualToString:DECICE_TYPE_RUSUN2A]){ _rusun84Set = [[RunSun84CHSetViewController alloc] init]; _rusun84Set.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_rusun84Set animated:YES]; }else if ([dmodel.type isEqualToString:DECICE_TYPE_RUIMEI]){ _ruimeiSet = [[RuiMeiSetViewController alloc] init]; _ruimeiSet.currentdevice = dmodel; NSString*stateString=[self.fishControlView.ruiMeiBack.customModel substringWithRange:NSMakeRange(2, 2)]; if ([stateString isEqualToString:@"01"]) { _ruimeiSet.customModeOn=YES; }else{ _ruimeiSet.customModeOn=NO; } usleep(50*1000); [self.navigationController pushViewController:_ruimeiSet animated:YES]; }else if ([dmodel.type isEqualToString:DECICE_TYPE_JUNENGCC]){ }else if ([dmodel.type isEqualToString:DECICE_TYPE_SONGNEWBD]){ }else{ int controlAmount=[dmodel.controlAmount intValue]; switch (controlAmount) { case IFISH_DEVICE_CONTROLAMOUNT0: { _noncontrolnonetimerVC = [[NoneControlNonetimerViewController alloc] init]; _noncontrolnonetimerVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_noncontrolnonetimerVC animated:YES]; } break; case IFISH_DEVICE_CONTROLAMOUNT2: { int timerAmount= [dmodel.timerAmount intValue]; if (bufferlenth == IFISH_BACKMASGTYAP57) { //57 字节 if (timerAmount == 0) { //两控零定时器 _twocontrolNonetimerVC = [[TwoControlnoneTimerViewController alloc] init]; _twocontrolNonetimerVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_twocontrolNonetimerVC animated:YES]; }else if (timerAmount == 4){ //两控四定时器 _twoControlSetTimeVC = [[TwoControlSetTimeViewController alloc] init]; _twoControlSetTimeVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_twoControlSetTimeVC animated:YES]; } }else if (bufferlenth == IFISH_BACKMASGTYAP99){ //两控四定时器99 字节 _twoControlNinetyninebiteVC = [[TwoControlNinetyninebiteViewController alloc] init]; _twoControlNinetyninebiteVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_twoControlNinetyninebiteVC animated:YES]; } } break; case IFISH_DEVICE_CONTROLAMOUNT3: { _SetTimeVC = [[SetTimeController alloc] init]; _SetTimeVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_SetTimeVC animated:YES]; } break; case IFISH_DEVICE_CONTROLAMOUNT4: { int timerAmount= [dmodel.timerAmount intValue]; if (timerAmount ==8) { _forControlSetVC = [[FourControlSetViewController alloc] init]; _forControlSetVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_forControlSetVC animated:YES]; }else if (timerAmount ==6){ _keLiAiSetVc = [[KeLiAiSetViewController alloc] init]; _keLiAiSetVc.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController: _keLiAiSetVc animated:YES]; } } break; case IFISH_DEVICE_CONTROLAMOUNT5: { if (bufferlenth == IFISH_BACKMASGTYAP73) { _xuToSetVC= [[XuToSetViewController alloc] init]; _xuToSetVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_xuToSetVC animated:YES]; } } break; case IFISH_DEVICE_CONTROLAMOUNT6: { } break; case IFISH_DEVICE_CONTROLAMOUNT8: { //松诺设置按钮 if (bufferlenth == IFISH_BACKMASGTYAP128) { _songNuoSetVC = [[SongNuoSetViewController alloc] init]; _songNuoSetVC.currentdevice = dmodel; usleep(50*1000); [self.navigationController pushViewController:_songNuoSetVC animated:YES]; } } break; default: break; } } } } -(void)setTimeVCReloadDatawithTimerArr:(NSArray*) timerArr withData:(DeviceModel *)dmodel addMassglength:(NSUInteger) bufferlenth { // 可以去掉最初 使用属性控制器 实现 两个手机 绑定统一设备(分享出去)控制其中一个手机设置界面的按钮时 另一个手机的设置界面也会同步更新 下一步改进放入设置界面 if ([dmodel.type isEqualToString:DECICE_TYPE_THREETMP]) { _rusunSet.timeArr = timerArr; [_rusunSet.indicatorView stopAnimating]; [_rusunSet.tableView reloadData]; }else if ([dmodel.type isEqualToString:DECICE_TYPE_RUSUN2A]){ _rusun84Set.timeArr = timerArr; [_rusun84Set.indicatorView stopAnimating]; [_rusun84Set.tableView reloadData]; }else if ([dmodel.type isEqualToString:DECICE_TYPE_RUIMEI]){ _ruimeiSet.timeArr = timerArr; [_ruimeiSet.indicatorView stopAnimating]; NSString*stateString=[self.fishControlView.ruiMeiBack.customModel substringWithRange:NSMakeRange(2, 2)]; if ([stateString isEqualToString:@"01"]) { _ruimeiSet.customModeOn=YES; }else{ _ruimeiSet.customModeOn=NO; } [_ruimeiSet.tableView reloadData]; }else if ([dmodel.type isEqualToString:DECICE_TYPE_JUNENGCC]){ }else if ([dmodel.type isEqualToString:DECICE_TYPE_SONGNEWBD]){ }else{ int controlAmount=[dmodel.controlAmount intValue]; switch (controlAmount) { case IFISH_DEVICE_CONTROLAMOUNT0: { _noncontrolnonetimerVC.timeArr = timerArr; [_noncontrolnonetimerVC.indicatorView stopAnimating]; [_noncontrolnonetimerVC.tableView reloadData]; } break; case IFISH_DEVICE_CONTROLAMOUNT2: { int timerAmount= [dmodel.timerAmount intValue]; if (bufferlenth == IFISH_BACKMASGTYAP57) { //57 字节 if (timerAmount == 0) { //两控零定时器 _twocontrolNonetimerVC.timeArr = timerArr; [_twocontrolNonetimerVC.indicatorView stopAnimating]; [_twocontrolNonetimerVC.tableView reloadData]; }else if (timerAmount == 4){ //两控四定时器 _twoControlSetTimeVC.timeArr = timerArr; [_twoControlSetTimeVC.indicatorView stopAnimating]; [_twoControlSetTimeVC.tableView reloadData]; } }else if (bufferlenth == IFISH_BACKMASGTYAP99){ //两控四定时器99 字节 _twoControlNinetyninebiteVC.timeArr = timerArr; [_twoControlNinetyninebiteVC.indicatorView stopAnimating]; [_twoControlNinetyninebiteVC.tableView reloadData]; } } break; case IFISH_DEVICE_CONTROLAMOUNT3: { _SetTimeVC.timeArr = timerArr; [_SetTimeVC.indicatorView stopAnimating]; [_SetTimeVC.tableView reloadData]; } break; case IFISH_DEVICE_CONTROLAMOUNT4: { int timerAmount= [dmodel.timerAmount intValue]; if (timerAmount ==8) { _forControlSetVC.timeArr = timerArr; [_forControlSetVC.indicatorView stopAnimating]; [_forControlSetVC.tableView reloadData]; }else if (timerAmount ==6){ _keLiAiSetVc.timeArr = timerArr; [_keLiAiSetVc.indicatorView stopAnimating]; [_keLiAiSetVc.tableView reloadData]; } } break; case IFISH_DEVICE_CONTROLAMOUNT5: { if (bufferlenth == IFISH_BACKMASGTYAP73){ _xuToSetVC.timeArr = timerArr; [_xuToSetVC.indicatorView stopAnimating]; [_xuToSetVC.tableView reloadData]; } } break; case IFISH_DEVICE_CONTROLAMOUNT6: { } break; case IFISH_DEVICE_CONTROLAMOUNT8: { if (bufferlenth == IFISH_BACKMASGTYAP128){ _songNuoSetVC.timeArr = timerArr; [_songNuoSetVC.indicatorView stopAnimating]; [_songNuoSetVC.tableView reloadData]; } } break; default: break; } } } -(void)cameraBindDeviceSuccess{} -(void)noCanuserDevicePush{ if (_isOkRenderVideoFrame) { [self stopGLViewVideo]; } formLogIn = NO; isfromCameraView = YES; [AppDelegate sharedDefault].canFullScreen = NO; //再次sleep 防止音频内存泄漏问题; usleep(50*1000); IfishBindDeviceSelectViewController *connectVC=[[IfishBindDeviceSelectViewController alloc]init]; [self.navigationController pushViewController:connectVC animated:YES]; } //炫多 -(void)selectXuToAtIndex:(NSIndexPath*)index withbackModel:(XutoBackMsgModel *)backmodel{ //XUANDUO_GUANSHUIBENG_ALERT manulswitchMSModel*manulModel=[[manulswitchMSModel alloc]init]; [[Socketsingleton sharedInstance] setSoketLightDataWith:manulModel]; NSString*switchString=manulModel.description; if (index.row ==7 ) { NSString*stateString=[backmodel.waterpump substringWithRange:NSMakeRange(2, 2)]; if ([stateString isEqualToString:@"01"]) { UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"确认关闭水泵?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; alert.tag = XUANDUO_GUANSHUIBENG_ALERT; [alert show]; }else{ //开 manulModel.lightNumber = @"05"; manulModel.switchBtn = @"01"; manulModel.crc16Str = @"0000"; NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString,manulModel.lightNumber,manulModel.switchBtn,manulModel.crc16Str]; NSData*manulData=[dataContorl stringToHexData:switchString2]; [[Socketsingleton sharedInstance] soketWriteData:manulData]; } }else if (index.row == 8){ [self showWenDuPic]; [self jiaReMianQue]; } } //关闭水泵 -(void)guanbiShuiBeng{ //manulswitchMSModel 和摄像头sdk 中的类重名报错 //[self.bottomFishHView makeToastActivity]; XuToLightModel*manulModel=[[XuToLightModel alloc]init]; [[Socketsingleton sharedInstance] setXuToSoketLightDataWith:manulModel]; NSString*switchString=manulModel.description; //开 manulModel.lightNumber = @"05"; manulModel.switchBtn = @"00"; manulModel.crc16Str = @"0000"; NSString*switchString2=[NSString stringWithFormat:@"%@%@%@%@",switchString,manulModel.lightNumber,manulModel.switchBtn,manulModel.crc16Str]; NSData*manulData=[dataContorl stringToHexData:switchString2]; [[Socketsingleton sharedInstance] soketWriteData:manulData]; } -(void)jiaReMianQue{ XutoBackMsgModel*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"xutoBackInfo"]; UInt64 mac=[dataContorl hexToTen:backmodel.heatTemperature]; NSLog(@"%llu",mac); //float TPlabel=mac/10+(mac%10)*0.1; [self setMianQueueWithUint64:mac]; } #pragma mark - 确定加热棒温度 -(void)sureBtnClick:(UIButton *)btn{ NSLog(@"%@******** _wenduPicview.picViewResultString",_wenduPicview.picViewResultString); if (_wenduPicview.picViewResultString ==nil) { [_wenduPicview removeFromSuperview]; }else{ JiaReWenDuModel *model=[[JiaReWenDuModel alloc] init]; [[Socketsingleton sharedInstance] setXuToJiaReBangDataWith:model]; int intlowString = [_wenduPicview.picViewResultString intValue]; int newIntlowString=intlowString*10; NSLog(@"%d******** newIntlowString",newIntlowString); // 转四位16进制 model.JiaReWenDu=[dataContorl tpIntStringToFourHex:newIntlowString]; model.crc16Code =@"0000"; NSString * hexstring=[NSString stringWithFormat:@"%@%@%@",model.description,model.JiaReWenDu,model.crc16Code]; NSData*data=[dataContorl stringToHexData:hexstring]; [ [Socketsingleton sharedInstance] soketWriteData:data]; } [_wenduPicview removeFromSuperview]; } -(void)hotCoolBtnClick:(UIButton *)btn { NSLog(@"%@******** _wenduPicview.picViewResultString",_wenduPicview.picViewResultString); if (_ruSunPicview.picViewResultString ==nil) { [_ruSunPicview removeFromSuperview]; }else{ JiaReWenDuModel *model=[[JiaReWenDuModel alloc] init]; [[Socketsingleton sharedInstance] setXuToJiaReBangDataWith:model]; int intlowString = [_ruSunPicview.picViewResultString intValue]; int newIntlowString=intlowString*10; NSLog(@"%d******** newIntlowString",newIntlowString); // 转四位16进制 model.JiaReWenDu=[dataContorl tpIntStringToFourHex:newIntlowString]; model.crc16Code =@"0000"; NSString * hexstring=[NSString stringWithFormat:@"%@%@%@",model.description,model.JiaReWenDu,model.crc16Code]; NSData*data=[dataContorl stringToHexData:hexstring]; [ [Socketsingleton sharedInstance] soketWriteData:data]; } [_ruSunPicview removeFromSuperview]; } #pragma mark - 点击松诺加热棒事件 -(void)slectSongNuoInde:(NSIndexPath *)index withBackModel:(SongNuoBackMassage *)backModel{ //和炫多 温度选择器一样 这里用炫多选择器展示 [self showWenDuPic]; [self songNuojiaReMianQue]; } -(void)songNuojiaReMianQue{ SongNuoBackMassage *backmodel=[[DataCenter defaultDtacenter]valueForKey:@"SongNuoBackMassage"]; UInt64 mac=[dataContorl hexToTen:backmodel.heatTemperature]; [self setMianQueueWithUint64:mac]; } //摄像头已不存在 -(void)cameraIsNotExit{ if(!_isReject){ _isReject = YES; while (_isPlaying) { // usleep() 与sleep()类似,用于延迟挂起进程。进程被挂起放到ready queue usleep(50*1000); } [[P2PClient sharedClient] p2pHungUp]; } [self stopGLViewVideo]; [Socketsingleton sharedInstance].communiteDelegate=nil; [[Socketsingleton sharedInstance] cutOffSocket]; [self.remoteView getLastImgGoback]; [AppDelegate sharedDefault].canFullScreen = NO; [self.remoteView releseromotViewSet]; //改 tab 栏后新增 [self setAppTabRoot]; } #pragma mark - 可丽爱加热棒 -(void)selctKeLiAiIndex:(NSIndexPath *)index withBackModel:(KeLiAiBackMassage *)backModel { [self showWenDuPic]; // [self keLiAijiaReMianQueWith]; } -(void)keLiAijiaReMianQueWith { KeLiAiBackMassage*backmodel=[[DataCenter defaultDtacenter]valueForKey:@"KeLiAiBackInfo"]; UInt64 mac=[dataContorl hexToTen:backmodel.heatTemperature]; [self setMianQueueWithUint64:mac]; } #pragma mark - 显示温度选择器初始数据 -(void)setMianQueueWithUint64:(UInt64)mac { float TPlabel=mac/10; int temp= (int)(TPlabel+0.5); NSString *stringFloat = [NSString stringWithFormat:@"%d",temp]; NSLog(@"%@",stringFloat); NSArray*wenDuArr=[_wenduPicview.picArr objectAtIndex:0]; //主线程名字和炫多通用 _xutoMainQueue 无影响 dispatch_async(_xutoMainQueue, ^{ for (NSInteger i=0; i