ifish/Ifish/controllers/IfishTabControllers/探索/lookafterWorkbech/ShopKanHuP2PViewController.m

2097 lines
79 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// ShopKanHuP2PViewController.m
// Ifish
//
// Created by imac on 16/8/26.
// Copyright © 2016年 lianxiang. All rights reserved.
//
#import "ShopKanHuP2PViewController.h"
#import "FListManager.h"
#import "LookAfterReportViewController.h"
#import "Utils.h"
#import "KanHuBaoGaoModel.h"
#import "P2pClient.h"
@interface ShopKanHuP2PViewController ()<GWP2PVideoPlayerProtocol>
{
CGFloat _horizontalScreenH;
CGFloat _monitorInterfaceW;//rtsp监控界面弹出修改
CGFloat _monitorInterfaceH;//rtsp监控界面弹出修改
UIButton* _btnDefence;
BOOL _isCanAutoOrientation;//限制屏幕什么时候可以旋转
BOOL _isStop;//是否暂停 用于区分是 暂停按钮 还是 连接失败按钮
BOOL _connectDevice; //是否连接到了P2P
BOOL _isConnectCamera;//是否连接到设备
BOOL _isconnecting;//是否正在连接摄像头
int _OnLine;
}
@end
@implementation ShopKanHuP2PViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.isShowControllerBar = YES;
self.isVideoModeHD = NO;
_isReject=YES;
_isStop = NO;
_isConnectCamera = NO;
_isconnecting = NO;
[self addTitleViewWithTitle:@"看护"];
[self connectDevice];
//监控竖屏时,各控件初始化(先)
[self initComponentForPortrait];
//监控横屏时,各控件初始化(后)
[self initComponentForHorizontalScreen];
_OnLine = 1;
}
#pragma mark -获取返回事件
-(void)goBackAction{
if ([self.player isPlaying]) {
[self.player p2pScreenshot:^(UIImage *screenshot, NSTimeInterval timeInterval) {
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *tempImage = [[UIImage alloc] initWithCGImage:screenshot.CGImage];
NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(tempImage)];
[Utils saveScreenshotFile:imgData];
});
}];
}
[self stopVideoPlayer];
[AppDelegate sharedDefault].canFullScreen = NO;
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 初始化设备 p2pConnect
-(void)connectDevice{
UserModel *model=[dataContorl getUserInfo];
NSString *userIDName=[NSString stringWithFormat:@"%d",(int)[model.gwellUserID integerValue]&0x7fffffff];
//初始化设备
if ([GWP2PClient sharedClient].linkStatus != P2PLinkStatusOK) {
NSLog(@"正在检查P2P连接状态");
_connectDevice = [[GWP2PClient sharedClient] connectWithAccount:userIDName codeStr1:model.P2PVerifyCode1 codeStr2:model.P2PVerifyCode2 sessionID1:model.sessionID sessionID2:model.sessionID2 customerIDs:nil];
if (_connectDevice) {
[self connectCamera];
}else{
NSLog(@"p2pConnect failure.失败,不能操作设备");
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.view makeToast:@"连接失败"];
[self hiddenMonitoringUI:NO callWithErrorType:GWP2PCallErrorNone isReCall:NO];
});
}
}
}
//连接到摄像头
-(void)connectCamera{
if (!_isconnecting) {
_isconnecting = YES;//正在连接中
NSString *newPassword = GIWEI_INITPASS;
NSString *cameraPass = [Utils GetTreatedPassword:newPassword];
[[GWP2PClient sharedClient] getMultipleDeviceStatusWithDeviceID:self.kanHuCamera.cameraId password:cameraPass completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
_isconnecting = NO;
//获取成功,打印设备信息,之后连接设备
if (success) {
_isConnectCamera = YES;
[self monitorP2PCall];
NSLog(@"当前连接设备信息:%@",dataDictionary);
}else{
_isConnectCamera = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.view makeToast:@"连接失败"];
[self hiddenMonitoringUI:NO callWithErrorType:100 isReCall:NO];
});
return;
}
}];
}else{
//设备连接中
}
}
#pragma mark --尝试连接摄像头
-(void)monitorP2PCall{
if ([self.player isPlaying]) {//如果已经连接,则不重复发出连接申请
return;
}
//p2p未连接
if ([GWP2PClient sharedClient].linkStatus != P2PLinkStatusOK) {
[self connectDevice];
return;
}
//未连接到设备
if (!_isConnectCamera) {
[self connectCamera];
return;
}
WEAK_SELF;
NSString *newPassword = GIWEI_INITPASS;
NSString *cameraPass = [Utils GetTreatedPassword:newPassword];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[weakSelf.player p2pCallDeviceWithDeviceId:self.kanHuCamera.cameraId password:cameraPass definition:GWP2PPTZDefinitionSD calling:^(NSDictionary *parameters) {
//呼叫设备
NSLog(@"[p2pCallDevice-Calling],paras=%@",parameters);
} accept:^(NSDictionary *parameters) {
NSLog(@"[p2pCallDevice-Accept],paras=%@",parameters);
} reject:^(GWP2PCallError error, NSString *errorCode) {
_isReject=YES;
NSLog(@"摄像头连接失败");
dispatch_async(dispatch_get_main_queue(), ^{
[self hiddenMonitoringUI:NO callWithErrorType:(NSInteger)error isReCall:NO];
});
} ready:^{
//呼叫成功操作
NSLog(@"连接摄像头成功 当前所在线程为%@",[NSThread currentThread]);
//隐藏呼叫中的UI
dispatch_async(dispatch_get_main_queue(), ^{
//隐藏旋转按钮
[weakSelf hiddenMonitoringUI:YES callWithErrorType:100 isReCall:NO];
//
[weakSelf didHiddenMonitorUIWith:YES];
});
} allowLAN:YES];
});
}
//摄像头播放回调
#pragma mark - GWP2PPlayer代理回调测试
- (void)p2pPlayer:(GWP2PPlayer *)player recieveGestureRecognizer:(UIGestureRecognizer *)gesture {
NSLog(@"-----delegate---recieveGestureRecognizer");
}
- (void)p2pVideoPlayer:(GWP2PVideoPlayer *)player numberOfAudiencesChange:(NSUInteger)currentNumber {
NSLog(@"-----delegate---numberOfAudiencesChange");
}
#pragma mark - OpenGLViewDelegate
//截图按钮点击
- (void)screenShot {
// WEAK_SELF;
//todo: 不停截图内存升高
[self.player p2pScreenshot:^(UIImage *screenshot, NSTimeInterval timeInterval) {
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *tempImage = [[UIImage alloc] initWithCGImage:screenshot.CGImage];
NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(tempImage)];
[Utils saveScreenshotFile:imgData];
[self.view makeToast:@"截图成功,请在图库中查看"];
});
}];
}
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
#pragma mark 生成看护报告
-(void)saveBaoGaoDataWith:(NSData *)imgData{
AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
//此接口不带请求头参数 带请求头参数的全在AFHttptool里
__weak typeof (self)weakself = self;
[manager POST:IfishGetLookReport parameters:self.baGaoDic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyyMMddHHmmss";
NSString *str = [formatter stringFromDate:[NSDate date]];
NSString *fileName = [NSString stringWithFormat:@"%@.png", str];
NSString *name = @"fileUpload";
// NSData*imgdata=UIImagePNGRepresentation(image);
[formData appendPartWithFileData:imgData name:name fileName:fileName mimeType:@"image/png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
NSLog(@"result:%@",resultDic[@"result"]);
[weakself.view hideToastActivity];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
NSDictionary *datadic=resultDic[@"data"];
KanHuBaoGaoModel *bgModel=[[KanHuBaoGaoModel alloc] init];
bgModel.baifenbi = datadic[@"baifenbi"];
bgModel.fileName = datadic[@"fileName"];
bgModel.timestamp = datadic[@"timestamp"];
bgModel.totalIndex = datadic[@"totalIndex"];
bgModel.reportId = datadic[@"reportId"];
bgModel.shareImg = datadic[@"shareImg"];
if ([self.player isPlaying]) {
[weakself stopVideoPlayer];
}
[self.view hideToastActivity];
LookAfterReportViewController *lookBaoGao = [[LookAfterReportViewController alloc] init];
lookBaoGao.baGaoMod = bgModel;
lookBaoGao.listModel = self.kanHuCamera;
lookBaoGao.pinFenArr = self.pinFenArray;
lookBaoGao.suggesttrue = self.suggetion;
usleep(50*1000);
[weakself.navigationController pushViewController:lookBaoGao animated:YES];
}else{
[self.view makeToast:@"生成失败"];
[self.view hideToastActivity];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self.view hideToastActivity];
[weakself.view makeToast:@"请检查网络"];
}];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//屏幕长亮
[[ UIApplication sharedApplication] setIdleTimerDisabled:YES];
self.navigationController.navigationBarHidden = NO;
_isCanAutoOrientation = YES;
//设置默认竖屏
[[AppDelegate sharedDefault] application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[AppDelegate sharedDefault].window];
[self cameraConnectSeting];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// 禁用 iOS7 返回手势
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//屏幕长亮关闭
[[ UIApplication sharedApplication] setIdleTimerDisabled:NO];
//离开此页面开启返回手势
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
[AppDelegate sharedDefault].canFullScreen = NO;
self.isReject = YES;
[[UIApplication sharedApplication] setStatusBarHidden:NO];
if (self.isFullScreen){
if (self.scrollView){
[self.scrollView setZoomScale:1.0];
}
}
}
#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
#pragma mark- 在线人数变化
-(void)receivePlayingMessage:(NSNotification *)notification
{
NSDictionary *parameter = [notification userInfo];
int key = [[parameter valueForKey:@"WathNumber"] intValue];
_OnLine ++ ;
if (key<=1) {
//_OnLine = key;
NSLog(@"当前在线人数%d",key);
//获取到在线人数后 关注人数1 子类中实现
[self popularityAdd:key];
}else{
if (_OnLine>2) {
return;
}
[self stopVideoPlayer];
[self alreadyHaveLookP];
}
}
#pragma mark - 已有人观看
-(void)alreadyHaveLookP{
}
#pragma mark - 人气加1 子类实现
-(void)popularityAdd:(int)onLineP
{
}
#pragma mark - 改变焦距
-(void)btnClickToChangeFocalLength:(id)sender{
}
#pragma mark - 焦距变倍
-(void)localLengthPinchToZoom:(id)sender {
if (!self.isFullScreen) {
return;
}
}
//加tab 栏后新增
-(void)cameraConnectSeting{
//rtsp监控界面弹出修改
[self monitorP2PCall];
[self hiddenMonitoringUI:NO callWithErrorType:100 isReCall:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#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:COLOR_MIAN];
//显示状态栏
[[UIApplication sharedApplication] setStatusBarHidden:NO];
//取得竖屏的rect
CGRect rect = [AppDelegate getScreenSize:YES isHorizontal:NO];
CGFloat width = rect.size.width;
//显示监控画面的载体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 clearColor];
[self.view addSubview:canvasView];
self.canvasView = canvasView;
self.canvasframe = canvasView.frame;
//视频监控连接中的背景图片
NSString *filePath = [Utils getHeaderFilePathWithId:self.kanHuCamera.cameraId];
UIImage *headImg = [UIImage imageWithContentsOfFile:filePath];
if(headImg==nil){
headImg = LXImageWithImageName(@"ic_header.png");
}
self.canvasView.layer.contents = (id)headImg.CGImage;
//添加播放器VC
self.player = [[GWP2PVideoPlayer alloc] init];
self.player.delegate = self;
self.player.mute = YES;
self.player.viewController.view.backgroundColor = [UIColor clearColor];
[self.canvasView addSubview:self.player.viewController.view];
[self addChildViewController:self.player.viewController];
self.player.viewController.view.frame = RECT(0, 0, self.canvasView.frame.size.width, self.canvasView.frame.size.height);
self.remoteView = self.player.viewController.view;
//视频监控连接中或者连接失败的文字提示,以及旋转或者重连图片
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
CGFloat progressView_wh = LOADINGPRESSVIEW_WIDTH_HEIGHT;
CGFloat progressView_y = (self.canvasView.frame.size.height-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;
//、横屏工具栏
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.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, midtH/2, midtH/2)];
self.stopImageViewH.contentMode = UIViewContentModeScaleToFill;
self.stopImageViewH.image = stopImageH;
self.stopImageViewH.tag = 10;
[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];
// 生成报告view
KanHuBaoGaoView *baoGaoToolHView=[[KanHuBaoGaoView alloc] initWithFrame:CGRectMake(0.0, CGRectGetMaxY(self.canvasView.frame) - 1, width, self.view.frame.size.height - CGRectGetHeight(self.canvasView.frame))];
baoGaoToolHView.baoGaoViewDelegate = self;
self.HbootmView =baoGaoToolHView;
[self.view addSubview:self.HbootmView];
}
#pragma mark - baoGaoViewDelegate
-(void)shengChengBaoGaoWith:(NSString *)index1 index2:(NSString *)index2 index3:(NSString *)index3 addSuggesture:(NSString *)suggestion addPingFenArr:(NSArray *)pinFenArr{
if (self.isReject) {
[self.view makeToast:@"监控未开启"];
return;
}
[self.view makeToastActivity:CSToastPositionCenter];
[self screenShot];
UserModel*umodel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
NSDictionary*para=@{
@"userId":umodel.userId,
@"index1":index1,
@"index2":index2,
@"index3":index3,
@"suggestion":suggestion,
@"fileUpload":@"png"
};
self.baGaoDic = para;
self.suggetion = suggestion;
self.pinFenArray = pinFenArr;
}
#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<rightItemCount;i++){
TouchButton *button = [self getBottomBarButton];
button.frame = CGRectMake(0, (CONTROLLER_RIGHT_ITEM_HEIGHT+1.0)*i, CONTROLLER_RIGHT_ITEM_WIDTH, CONTROLLER_RIGHT_ITEM_HEIGHT);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, button.frame.size.width, button.frame.size.height)];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = XWhite;
label.font = [UIFont boldSystemFontOfSize:16.0];
if(rightItemCount==2){//NPC
//无高清
if(i==0){
//label.text = NSLocalizedString(@"SD", nil);
label.text = NSLocalizedString(@"标清", nil);
label.tag = CONTROLLER_LABEL_TAG_SD;
button.tag = CONTROLLER_BTN_TAG_SD;
}else if(i==1){
label.text = NSLocalizedString(@"流畅", nil);
label.tag = CONTROLLER_LABEL_TAG_LD;
label.textColor = XBlue;
button.tag = CONTROLLER_BTN_TAG_LD;
}
}else if(rightItemCount==3){//IPC
//有高清
if(i==0){
label.text = NSLocalizedString(@"高清", nil);
label.tag = CONTROLLER_LABEL_TAG_HD;
button.tag = CONTROLLER_BTN_TAG_HD;
}else if(i==1){
label.text = NSLocalizedString(@"标清", nil);
label.tag = CONTROLLER_LABEL_TAG_SD;
label.textColor = XBlue;
button.tag = CONTROLLER_BTN_TAG_SD;
}else if(i==2){
label.text = NSLocalizedString(@"流畅", nil);
label.tag = CONTROLLER_LABEL_TAG_LD;
button.tag = CONTROLLER_BTN_TAG_LD;
//
}
}
[button addSubview:label];
[button addTarget:self action:@selector(onControllerBtnPress:) forControlEvents:UIControlEventTouchUpInside];
[controllerRight addSubview:button];
}
//进入横屏时,显示
//退出横屏时,隐藏
//底部半透明块
UIView *bottomBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, height-BOTTOM_BAR_HEIGHT, width, BOTTOM_BAR_HEIGHT)];
self.bottomBarView = bottomBarView;
[self.view addSubview:bottomBarView];
[self.bottomBarView setHidden:YES];
//左边的画质图标
//由于要隐藏掉此处改为暂停按钮
TouchButton *resolutionButton = [self getBottomBarButton];
[resolutionButton setFrame:CGRectMake(5.0, (BOTTOM_BAR_HEIGHT-RESOLUTION_BTN_H)/2.0, CONTROLLER_RIGHT_ITEM_WIDTH, RESOLUTION_BTN_H)];
resolutionButton.tag = CONTROLLER_BTN_TAG_RESOLUTION;
if (rightItemCount == 2) {
[resolutionButton setTitle:NSLocalizedString(@"LD", nil) forState:UIControlStateNormal];
}else{
[resolutionButton setTitle:NSLocalizedString(@"SD", nil) forState:UIControlStateNormal];
}
[resolutionButton setBackgroundImage:LXImageWithImageName(@"ic_ctl_resolution.png") forState:UIControlStateNormal];
[resolutionButton addTarget:self action:@selector(selectResolutionClick:) forControlEvents:UIControlEventTouchUpInside];
//暂时隐藏之选择高清
//[bottomBarView addSubview:resolutionButton];
//全屏暂停回来 openGlView 出现问题scale改变
// _HorizontalStopBtn=[UIButton buttonWithType:UIButtonTypeCustom];
//
// _HorizontalStopBtn.frame = CGRectMake(5.0, (BOTTOM_BAR_HEIGHT-RESOLUTION_BTN_H)/2.0, CONTROLLER_LEFT_ITEM_WIDTH, RESOLUTION_BTN_H);
// _HorizontalStopBtn.tag =VT_STOPBTN_TAG;
// [_HorizontalStopBtn setBackgroundImage:LXImageWithImageName(@"monitor_stop_h.png") forState:UIControlStateNormal];
// [_HorizontalStopBtn addTarget:self action:@selector(HorizontalStopBtnPress:) forControlEvents:UIControlEventTouchUpInside];
// [bottomBarView addSubview:_HorizontalStopBtn];
//
//右边的切换屏幕图标
TouchButton *switchScreenButton = [self getBottomBarButton];
[switchScreenButton setFrame:CGRectMake(width-CONTROLLER_BTN_H_W-5.0, (BOTTOM_BAR_HEIGHT-CONTROLLER_BTN_H_W)/2.0, CONTROLLER_BTN_H_W, CONTROLLER_BTN_H_W)];
switchScreenButton.tag = SWITCH_SCREEN_BUTTON_H_TAG;
[switchScreenButton setBackgroundImage:LXImageWithImageName(@"monitor_half_screen.png") forState:UIControlStateNormal];
[switchScreenButton addTarget:self action:@selector(onVerticalBtnPress:) forControlEvents:UIControlEventTouchUpInside];
[bottomBarView addSubview:switchScreenButton];
//右边的挂断图标
TouchButton *hungUpButton = [self getBottomBarButton];
[hungUpButton setFrame:CGRectMake(switchScreenButton.frame.origin.x-CONTROLLER_BTN_H_W-5.0, (BOTTOM_BAR_HEIGHT-CONTROLLER_BTN_H_W)/2.0, CONTROLLER_BTN_H_W, CONTROLLER_BTN_H_W)];
hungUpButton.tag = CONTROLLER_BTN_TAG_HUNGUP;
[hungUpButton setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_hungup.png") forState:UIControlStateNormal];
[hungUpButton addTarget:self action:@selector(onControllerBtnPress:) forControlEvents:UIControlEventTouchUpInside];
// [bottomBarView addSubview:hungUpButton];
//布防撤防、声音开关、截图开关、按住说话开关、开门按钮
UIView *controllBar = [[UIView alloc] initWithFrame:CGRectMake(CONTROLLER_RIGHT_ITEM_WIDTH+5.0, 0.0, width-CONTROLLER_RIGHT_ITEM_WIDTH-5.0-PUBLIC_WIDTH_OR_HEIGHT*2-5.0*2, PUBLIC_WIDTH_OR_HEIGHT)];
controllBar.backgroundColor = [UIColor clearColor];
self.controllBar = controllBar;
int btnCount = CONTROLLER_BTN_COUNT;
CGFloat firstControllerBtnX = (controllBar.frame.size.width-PUBLIC_WIDTH_OR_HEIGHT*btnCount)/2.0;
for(int i=0;i<btnCount;i++){
TouchButton *controllerBtn = [self getBottomBarButton];
controllerBtn.frame = CGRectMake(PUBLIC_WIDTH_OR_HEIGHT*i+firstControllerBtnX, (BOTTOM_BAR_HEIGHT-CONTROLLER_BTN_H_W)/2.0, CONTROLLER_BTN_H_W,CONTROLLER_BTN_H_W);
if(i==0){//布防撤防
_btnDefence = controllerBtn;
_btnDefence.hidden = YES;
//LXImageWithImageName(@"long_press_lock.png")
controllerBtn.tag = CONTROLLER_BTN_TAG_DEFENCE_LOCK;
// if ([AppDelegate sharedDefault].mainController.contact.defenceState == DEFENCE_STATE_ON || [AppDelegate sharedDefault].contact.defenceState == DEFENCE_STATE_ON) {
// [controllerBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_lock_on.png") forState:UIControlStateNormal];
// self.isDefenceOn = YES;
// }else if([AppDelegate sharedDefault].mainController.contact.defenceState == DEFENCE_STATE_OFF || [AppDelegate sharedDefault].contact.defenceState == DEFENCE_STATE_OFF){
// [controllerBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_lock_off.png") forState:UIControlStateNormal];
// self.isDefenceOn = NO;
// }
}else if(i==1){//声音开关
controllerBtn.tag = CONTROLLER_BTN_TAG_SOUND;
[controllerBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_sound_on.png") forState:UIControlStateNormal];
controllerBtn.hidden = YES;
}else if(i==2){//按住说话开关
controllerBtn.tag = CONTROLLER_BTN_TAG_PRESS_TALK;
[controllerBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_send_audio.png") forState:UIControlStateNormal];
[controllerBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_send_audio_p.png") forState:UIControlStateHighlighted];
controllerBtn.hidden = YES;
}else if(i==3){//截图开关
controllerBtn.tag = CONTROLLER_BTN_TAG_SCREENSHOT;
[controllerBtn setBackgroundImage:LXImageWithImageName(@"ic_ctl_new_screenshot.png") forState:UIControlStateNormal];
controllerBtn.hidden = YES;
}else if(i==4){//输出6秒高电平脉冲按钮
controllerBtn.tag = CONTROLLER_BTN_TAG_GPIO1_0;
[controllerBtn setBackgroundImage:LXImageWithImageName(@"long_press_lock.png") forState:UIControlStateNormal];
controllerBtn.hidden = YES;
}
if(i==2){
//对讲按钮
}else{
[controllerBtn addTarget:self action:@selector(onControllerBtnPress:) forControlEvents:UIControlEventTouchUpInside];
}
[controllBar addSubview:controllerBtn];
}
[bottomBarView addSubview:controllBar];
//button arrow
//进入横屏时,显示
//退出横屏时,隐藏
CGFloat customBorderButtonY = (height - CUSTOM_BORDER_BUTTON_HEIGHT)/2.0;
CustomBorderButton *customBorderButton=[CustomBorderButton buttonWithType:UIButtonTypeCustom];
customBorderButton.frame = CGRectMake(0, customBorderButtonY, CUSTOM_BORDER_BUTTON_WIDTH, CUSTOM_BORDER_BUTTON_HEIGHT);
[customBorderButton setNeedLineTop:true left:true bottom:true right:true];
[customBorderButton setLineColorTop:[UIColor blackColor] left:[UIColor clearColor] bottom:[UIColor blackColor] right:[UIColor blackColor]];//用同一色边线
[customBorderButton setLineWidthTop:2.0 left:2.0 bottom:2.0 right:2.0];//设置线的粗细,这里可以随意调整
[customBorderButton setRadiusTopLeft:0 topRight:8.0 bottomLeft:0 bottomRight:8.0];//边线加弧度
[customBorderButton setClipsToBoundsWithBorder:true];//裁剪掉边线外面的区域
[customBorderButton setFillColor:[UIColor darkGrayColor]];//增加内部填充颜色
[customBorderButton setAlpha:0.5];
[customBorderButton setOpaque:YES];
[customBorderButton setImage:[UIImage imageNamed:@"button_right"] forState:UIControlStateNormal];
[customBorderButton setImage:[UIImage imageNamed:@"button_right_selected"] forState:UIControlStateHighlighted];
[customBorderButton addTarget:self action:@selector(showLeftView:) forControlEvents:UIControlEventTouchUpInside];
self.customBorderButton = customBorderButton;
//左侧界面
//进入横屏时,显示
//退出横屏时,隐藏
CGFloat leftViewY = (height - LEFTVIEW_HEIGHT)/2.0;
CustomView *leftView = [[CustomView alloc] initWithFrame:CGRectMake(-LEFTVIEW_WIDTH, leftViewY, LEFTVIEW_WIDTH, LEFTVIEW_HEIGHT)];
[leftView setNeedLineTop:true left:true bottom:true right:true];
[leftView setLineColorTop:[UIColor blackColor] left:[UIColor blackColor] bottom:[UIColor blackColor] right:[UIColor blackColor]];//用同一色边线
[leftView setLineWidthTop:2.0 left:2.0 bottom:2.0 right:2.0];//设置线的粗细,这里可以随意调整
[leftView setRadiusTopLeft:8.0 topRight:8.0 bottomLeft:8.0 bottomRight:8.0];//边线加弧度
[leftView setClipsToBoundsWithBorder:true];//裁剪掉边线外面的区域
[leftView setFillColor:[UIColor darkGrayColor]];//增加内部填充颜色
[leftView setAlpha:0.5];
[leftView setOpaque:YES];
self.leftView = leftView;
[self.leftView setHidden:YES];
CGFloat xSpace = 4.0;
CGFloat ySpace = 4.0;
CGFloat numLabelW = 12.0;
CGFloat buttonW = (leftView.frame.size.width - numLabelW - xSpace*4)/2.0;
CGFloat buttonH = (leftView.frame.size.height - ySpace*4)/3.0;
int tag = 10;
for (int i = 0; i < 3; i++) {
UIButton *onButton = [UIButton buttonWithType:UIButtonTypeCustom];
onButton.frame = CGRectMake(xSpace, (buttonH+ySpace)*i+ySpace, buttonW, buttonH);
onButton.tag = tag++;
[onButton setTitle:@"ON" forState:UIControlStateNormal];
[onButton setTitleColor:XWhite forState:UIControlStateNormal];
onButton.titleLabel.font = XFontBold_12;
[onButton addTarget:self action:@selector(onOrOffButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.leftView addSubview:onButton];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(2*xSpace+buttonW, (buttonH+ySpace)*i+ySpace, numLabelW, buttonH)];
label.backgroundColor = [UIColor clearColor];
label.textColor = XWhite;
label.text = [NSString stringWithFormat:@"%d",i + 1];
label.font = XFontBold_12;
label.textAlignment = NSTextAlignmentCenter;
[self.leftView addSubview:label];
UIButton *offButton = [UIButton buttonWithType:UIButtonTypeCustom];
offButton.frame = CGRectMake(3*xSpace+buttonW +numLabelW, (buttonH+ySpace)*i+ySpace, buttonW, buttonH);
offButton.tag = tag++;
[offButton setTitle:@"OFF" forState:UIControlStateNormal];
[offButton setTitleColor:XWhite forState:UIControlStateNormal];
offButton.titleLabel.font = XFontBold_12;
[offButton addTarget:self action:@selector(onOrOffButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.leftView addSubview:offButton];
}
//右侧,灯控制按钮
//进入横屏时,显示,并调整frame
//退出横屏时,隐藏
//提示器
UIActivityIndicatorView *progressView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
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.remoteView addSubview:progressView];
self.progressView = progressView;
[self.progressView setHidden:YES];
//若设备支持灯设备时,则显示开关;若不支持,则隐藏
UIButton *lightButton = [UIButton buttonWithType:UIButtonTypeCustom];
lightButton.frame = CGRectMake(self.remoteView.frame.size.width-30.0-20.0, (self.remoteView.frame.size.height-30.0)/2, 30.0, 30.0);
lightButton.backgroundColor = [UIColor clearColor];
[lightButton setBackgroundImage:[UIImage imageNamed:@"lighton.png"] forState:UIControlStateNormal];
[lightButton addTarget:self action:@selector(btnClickToSetLightState:) forControlEvents:UIControlEventTouchUpInside];
[self.remoteView addSubview:lightButton];
[lightButton setHidden:YES];
self.lightButton = lightButton;
//进入横屏时,显示
//退出横屏时,隐藏
//焦距控件
//宽、高
CGFloat focalLengthView_w = 40.0;
CGFloat focalLengthView_h = 180.0;
//焦距控件与屏幕右边框的间距
CGFloat space_FocalLView_Screen = (width - self.remoteView.frame.size.width)/2+20+focalLengthView_w;
UIView *focalLengthView = [[UIView alloc] initWithFrame:CGRectMake(width-space_FocalLView_Screen, height-self.bottomBarView.frame.size.height-20.0-focalLengthView_h, focalLengthView_w, focalLengthView_h)];
if (!isSupportZoom) {//电子放大与焦距变焦不共存
[self.view addSubview:focalLengthView];
}
[focalLengthView setHidden:YES];
self.focalLengthView = focalLengthView;
//焦距伸长按钮
//宽、高
CGFloat elongationButton_w = 34.0;
CGFloat elongationButton_h = elongationButton_w*(46/43);
UIButton *elongationButton = [UIButton buttonWithType:UIButtonTypeCustom];
elongationButton.frame = CGRectMake((focalLengthView_w-elongationButton_w)/2, 0.0, elongationButton_w, elongationButton_h);
[elongationButton setBackgroundImage:[UIImage imageNamed:@"monitor_localLenght_zoom_normal.png"] forState:UIControlStateNormal];
[elongationButton setBackgroundImage:[UIImage imageNamed:@"monitor_localLenght_zoom_highlighted.png"] forState:UIControlStateHighlighted];
elongationButton.tag = FocalLength_Elongation_btnTag;
[elongationButton addTarget:self action:@selector(btnClickToChangeFocalLength:) forControlEvents:UIControlEventTouchUpInside];
[self.focalLengthView addSubview:elongationButton];
//拖动条
UISlider *focalLengthSlider = [[UISlider alloc] initWithFrame:CGRectMake(0.0, 0.0, focalLengthView_h-elongationButton_h*2, 30.0)];
focalLengthSlider.center = CGPointMake(self.focalLengthView.center.x-self.focalLengthView.frame.origin.x, self.focalLengthView.center.y-self.focalLengthView.frame.origin.y);
//设置旋转90度
focalLengthSlider.transform = CGAffineTransformMakeRotation(90*M_PI/180);
focalLengthSlider.minimumValue = 1.0;
focalLengthSlider.maximumValue = 15.0;
focalLengthSlider.value = 7.5;
focalLengthSlider.continuous = NO;//在手指离开的时候触发一次valueChange事件而不是在拖动的过程中不断触发valueChange事件
focalLengthSlider.tag = FocalLength_Change_sliderTag;
[focalLengthSlider addTarget:self action:@selector(btnClickToChangeFocalLength:) forControlEvents:UIControlEventValueChanged];
[self.focalLengthView addSubview:focalLengthSlider];
//焦距变短按钮
//宽、高
CGFloat shortenButton_w = elongationButton_w;
CGFloat shortenButton_h = elongationButton_h;
UIButton *shortenButton = [UIButton buttonWithType:UIButtonTypeCustom];
shortenButton.frame = CGRectMake((focalLengthView_w-shortenButton_w)/2, focalLengthView_h-shortenButton_h, shortenButton_w, shortenButton_h);
[shortenButton setBackgroundImage:[UIImage imageNamed:@"monitor_localLenght_narrow_normal.png"] forState:UIControlStateNormal];
[shortenButton setBackgroundImage:[UIImage imageNamed:@"monitor_localLenght_narrow_highlighted.png"] forState:UIControlStateHighlighted];
shortenButton.tag = FocalLength_Shorten_btnTag;
[shortenButton addTarget:self action:@selector(btnClickToChangeFocalLength:) forControlEvents:UIControlEventTouchUpInside];
[self.focalLengthView addSubview:shortenButton];
}
#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);
}
[self.player p2pStop];
}
}
break;
case CONTROLLER_BTN_TAG_SOUND:
{
}
break;
case CONTROLLER_BTN_TAG_SCREENSHOT:
{
[self screenShot];
}
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];
}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];
}
}
break;
case CONTROLLER_BTN_TAG_DEFENCE_LOCK://重新调整监控画面
{
NSString *contactId = [[P2PClient sharedClient] contactId];
NSString *contactPassword = [[P2PClient sharedClient] password];
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:
{
[self.player p2pSetDefinition:GWP2PPTZDefinitionHD];
[self updateRightButtonState:CONTROLLER_BTN_TAG_HD];
}
break;
case CONTROLLER_BTN_TAG_SD:
{
[self.player p2pSetDefinition:GWP2PPTZDefinitionSD];
[self updateRightButtonState:CONTROLLER_BTN_TAG_SD];
}
break;
case CONTROLLER_BTN_TAG_LD:
{
[self.player p2pSetDefinition:GWP2PPTZDefinitionLD];
[self updateRightButtonState:CONTROLLER_BTN_TAG_LD];
}
break;
}
}
- (TouchButton *)getBottomBarButton//重新调整监控画面
{
TouchButton *button = [TouchButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(0.0, 0.0, 50.0, 50.0)];
return button;
}
-(void)onOrOffButtonClick:(UIButton *)button{
//
int group = 0, pin = 0;
int value = 5;
int time[8] = {0};
time[0] = -1000;
time[1] = 1000;
time[2] = -1000;
time[3] = 1000;
time[4] = -1000;
switch (button.tag) {
case GPIO0_0:
{
group = 0;
pin = 0;
self.clickGPIO0_0Button = button;
self.clickGPIO0_0Button.backgroundColor = XBlue;
}
break;
case GPIO0_1:
{
group = 0;
pin = 1;
self.clickGPIO0_1Button = button;
self.clickGPIO0_1Button.backgroundColor = XBlue;
}
break;
case GPIO0_2:
{
group = 0;
pin = 2;
self.clickGPIO0_2Button = button;
self.clickGPIO0_2Button.backgroundColor = XBlue;
}
break;
case GPIO0_3:
{
group = 0;
pin = 3;
self.clickGPIO0_3Button = button;
self.clickGPIO0_3Button.backgroundColor = XBlue;
}
break;
case GPIO0_4:
{
group = 0;
pin = 4;
self.clickGPIO0_4Button = button;
self.clickGPIO0_4Button.backgroundColor = XBlue;
}
break;
case GPIO2_6:
{
group = 2;
pin = 6;
self.clickGPIO2_6Button = button;
self.clickGPIO2_6Button.backgroundColor = XBlue;
}
break;
}
//记录当前的GPIO设置参数
self.lastGroup = group;
self.lastPin = pin;
self.lastValue = value;
self.lastTime = time;
NSString *contactId = [[P2PClient sharedClient] callId];
NSString *contactPassword = [[P2PClient sharedClient] callPassword];
[[P2PClient sharedClient] setGpioCtrlWithId:contactId password:contactPassword group:group pin:pin value:value time:time];
}
#pragma mark 点击竖屏上的按钮时,响应
-(void)onVerticalBtnPress:(UIButton *)button{
switch(button.tag){
case SOUND_BUTTON_H_TAG://声音
{
if (![self.player isPlaying]) {
//图像渲染出来前,不可以控制声音
return;
}
}
break;
case SWITCH_SCREEN_BUTTON_H_TAG://切换至横屏或者竖屏
{
if (![self.player isPlaying]) {
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];
//设置默认全屏
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 screenShot];
}
break;
case PROMPT_BUTTON_TAG://重新连接监控
{
[self hiddenMonitoringUI:NO callWithErrorType:100 isReCall:YES];
[self monitorP2PCall];
}
break;
//暂停按钮
case STOPBTN_TAG:
{
//获取暂停按钮图
UIImageView *stopImageViewH = (UIImageView *)[button viewWithTag:10];
//暂停结束,继续播放视频
if(![self.player isPlaying]){
_isStop = NO;
[self hiddenMonitoringUI:NO callWithErrorType:100 isReCall:YES];
[self monitorP2PCall];
stopImageViewH.image = LXImageWithImageName(@"monitor_stop_h.png");
//横屏,声音打开
}else{
_isStop = YES;//点击暂停
[self stopVideoPlayer];
[self hiddenMonitoringUI:YES callWithErrorType:GWP2PCallErrorNone isReCall:NO];
stopImageViewH.image = LXImageWithImageName(@"monitor_on_h.png");
//横屏,声音关闭
}
}
break;
}
}
-(void)onSingleTap{
if (!self.isFullScreen) {
//竖屏时点击屏幕 弹出工具栏打开下面方法 3s 自动消失
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.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.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)hideBootommViewAfterSecondes{
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(dismissHbtoomToolView) userInfo:nil repeats:NO];
}
-(void)dismissHbtoomToolView{
if (self.isShowControllerBar) {
[self hidHbottomView];
}
}
-(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];
}];
//return;
}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)didHiddenResolutionInterface{
[UIView animateWithDuration:0.2 animations:^{
CGRect controllerRight = self.controllerRight.frame;
controllerRight.origin.y = _horizontalScreenH;
self.controllerRight.frame = controllerRight;
self.controllerRightBg.frame = controllerRight;
} completion:^(BOOL finished) {
self.isAlreadyShowResolution = NO;
}];
}
-(void)selectResolutionClick:(UIButton *)button{//重新调整监控画面
if (self.isAlreadyShowResolution) {
[self didHiddenResolutionInterface];
}else{
[self didShowResolutionInterface];
}
}
-(void)didShowResolutionInterface{
BOOL is16B9 = [[P2PClient sharedClient] is16B9];
BOOL is960P = [[P2PClient sharedClient] is960P];
//右边的画质图标
int rightItemCount = 0;
if(is16B9 || is960P){
rightItemCount = 3;
}else{
rightItemCount = 2;
}
[UIView animateWithDuration:0.2 animations:^{
CGRect controllerRight = self.controllerRight.frame;
controllerRight.origin.y = _horizontalScreenH-BOTTOM_BAR_HEIGHT-CONTROLLER_RIGHT_ITEM_HEIGHT*3-1.0;
self.controllerRight.frame = controllerRight;
CGRect controllerRightBgRect = self.controllerRightBg.frame;
controllerRightBgRect.origin.y = _horizontalScreenH-BOTTOM_BAR_HEIGHT-CONTROLLER_RIGHT_ITEM_HEIGHT*rightItemCount-1.0;
self.controllerRightBg.frame = controllerRightBgRect;
} completion:^(BOOL finished) {
self.isAlreadyShowResolution = YES;
}];
}
-(void)onDoubleTap{
if (!self.isFullScreen) {
// if (_isStop == NO) {
// [self hiddenMonitoringUI:NO callErrorInfo:nil isReCall:NO];
// _isStop = YES;
// }
//
// [self stopVideoPlayer];
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)stopVideoPlayer{
if ([self.player isPlaying]) {
[self.player p2pStop];
}
}
#pragma mark - 隐藏监控连接中的UI
-(void)hiddenMonitoringUI:(BOOL)isHidden callWithErrorType:(GWP2PCallError)errorType isReCall:(BOOL)isReCall{
if (isHidden) {
[self.yProgressView stop];
[self.yProgressView 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.promptButton setEnabled:NO];
self.stopImageViewH.image = LXImageWithImageName(@"monitor_stop_h.png");
// 禁用 底部栏暂停按钮
[self.stopBtnH setEnabled:NO];
}else{
self.yProgressView.angle = 0.0f;
self.yProgressView.backgroundView.image = LXImageWithImageName(@"ifishCamera_start");
self.stopImageViewH.image = LXImageWithImageName(@"monitor_on_h.png");
self.yProgressView.angle = 0.0f;
[self.yProgressView stop];
[self.promptButton setEnabled:YES];
[self.stopBtnH setEnabled:YES];
}
[self.yProgressView setHidden:NO];
[self.promptButton setHidden:NO];
[self.canvasView bringSubviewToFront:self.promptButton];
}
}
/*
GWP2PCallErrorNone = 0, //0无原因
GWP2PCallErrorDesidNotEnable, //1对方的ID 被禁用
GWP2PCallErrorDesidOverDate, //2对方的ID 过期了
GWP2PCallErrorDesidNotAcitve, //3对方的ID 尚未激活
GWP2PCallErrorDesidOffline, //4对方离线
GWP2PCallErrorDesidBusy, //5对方忙线中
GWP2PCallErrorDesidPowerDown, //6对方已关机
GWP2PCallErrorNoHelper, //7没有找到协助人
GWP2PCallErrorHangUp, //8对方已经挂断
GWP2PCallErrorTimeout, //9连接超时
GWP2PCallErrorInterError, //10内部错误
GWP2PCallErrorRingTimeout, //11无人接听
GWP2PCallErrorPwdWrong, //12密码错误(在远程监控时用到密码,在视频通话是不需要)
GWP2PCallErrorConnFail,
GWP2PCallErrorNotSupport,
*/
-(NSString *)getCallErrorStringWithErrorType:(GWP2PCallError)errorType{
switch((int)errorType)
{
case GWP2PCallErrorNone:
{
return NSLocalizedString(@"id_unknown_error", nil);
}
break;
case GWP2PCallErrorDesidNotEnable:
{
return NSLocalizedString(@"id_disabled", nil);
}
break;
case GWP2PCallErrorDesidOverDate:
{
return NSLocalizedString(@"id_overdate", nil);
}
break;
case GWP2PCallErrorDesidNotAcitve:
{
return NSLocalizedString(@"id_inactived", nil);
}
break;
case GWP2PCallErrorDesidOffline:
{
return NSLocalizedString(@"id_offline", nil);
}
break;
case GWP2PCallErrorDesidBusy:
{
return NSLocalizedString(@"id_busy", nil);
}
break;
case GWP2PCallErrorDesidPowerDown:
{
return NSLocalizedString(@"id_powerdown", nil);
}
break;
case GWP2PCallErrorNoHelper:
{
return NSLocalizedString(@"id_connect_failed", nil);
}
break;
case GWP2PCallErrorHangUp:
{
return NSLocalizedString(@"id_hangup", nil);
break;
}
case GWP2PCallErrorTimeout:
{
return NSLocalizedString(@"id_timeout", nil);
}
break;
case GWP2PCallErrorInterError:
{
return NSLocalizedString(@"id_internal_error", nil);
}
break;
case GWP2PCallErrorRingTimeout:
{
return NSLocalizedString(@"id_no_accept", nil);
}
break;
case GWP2PCallErrorPwdWrong:
{
return NSLocalizedString(@"id_password_error", nil);
}
break;
case GWP2PCallErrorConnFail:
{
return NSLocalizedString(@"id_connect_failed", nil);
}
break;
case GWP2PCallErrorNotSupport:
{
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.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.bottomBarView setAlpha:1.0];
[self.customBorderButton setAlpha:0.5];
[self.leftView setAlpha:0.5];
[self.focalLengthView setAlpha:1.0];
[self.pressView setAlpha:1.0];
}
}
#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];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(@"willRotateToInterfaceOrientation:(UIInterfaceOrientation)");
}
#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.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 disHideSubControlerBootomm];
[self.midToolHView setHidden:NO];
[self.bottomToolHView setHidden:NO];
//[self.baoGaoToolHView setHidden:NO];
[self.HbootmView setHidden:NO];
//视频监控连接中的背景图片
//进入竖屏时调整frame
self.canvasView.frame = self.canvasframe;
//视频监控连接中的背景图片
UserModel *model=[dataContorl getUserInfo];
NSString *filePath = [Utils getHeaderFilePathWithId:model.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);
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];
//旋转图片
CGFloat tipHeight = 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);
//左边的按住说话弹出的声音图标
//退出横屏时调整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;
self.navigationController.navigationBar.hidden = YES;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
//隐藏竖屏里的控件
[self hideSubControlerBootomm];
[self.midToolHView setHidden:YES];
//[self.baoGaoToolHView setHidden:YES];
[self.HbootmView setHidden:YES];
[self.bottomToolHView setHidden:YES];
//显示横屏里的控件
[self.controllerRightBg setHidden:NO];
[self.controllerRight 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;
//旋转图片
CGFloat tipHeight = LOADINGPRESSVIEW_WIDTH_HEIGHT;
self.yProgressView.frame = CGRectMake((width-LOADINGPRESSVIEW_WIDTH_HEIGHT)/2, (height)/2, LOADINGPRESSVIEW_WIDTH_HEIGHT, LOADINGPRESSVIEW_WIDTH_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);
//设置横屏底部工具栏3秒隐藏
[self hideBootommViewAfterSecondes];
}
-(void)hideSubControlerBootomm{
}
-(void)disHideSubControlerBootomm{
}
#pragma mark - 设置标清或高清
//由于要隐藏掉 画质选项卡 这里重写方法 设置视频默认高清 或标清
-(void)setGaoQingHuoBiaoQing{
BOOL is16B9 = [[P2PClient sharedClient] is16B9];
BOOL is960P = [[P2PClient sharedClient] is960P];
//右边的画质图标
int rightItemCount = 0;
if(is16B9 || is960P){
rightItemCount = 3;
}else{
rightItemCount = 2;
}
//设置高清
if (rightItemCount==3) {
[[P2PClient sharedClient] sendCommandType:USR_CMD_VIDEO_CTL andOption:7];
[self updateRightButtonState:CONTROLLER_BTN_TAG_HD];
}else if (rightItemCount == 2){
//设置标清
[[P2PClient sharedClient] sendCommandType:USR_CMD_VIDEO_CTL andOption:5];
[self updateRightButtonState:CONTROLLER_BTN_TAG_SD];
}
}
#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(@"标清", nil) forState:UIControlStateNormal];
//[rButton setTitle:NSLocalizedString(@"SD", 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(@"流畅", nil) forState:UIControlStateNormal];
//[rButton setTitle:NSLocalizedString(@"LD", nil) forState:UIControlStateNormal];
}
[self didHiddenResolutionInterface];
}
@end