| | |
| | | #import "EZStreamPlayer.h" |
| | | #import "MBProgressHUD.h" |
| | | #import "EZPMPlayPrivateTokenInfo.h" |
| | | |
| | | #import "HDLEZAlertInputView.h" |
| | | #define MinimumZoomScale 1.0 |
| | | #define MaximumZoomScale 4.0 |
| | | |
| | |
| | | @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; |
| | | @property (weak, nonatomic) IBOutlet UILabel *zoomSizeLabel; |
| | | |
| | | @property (nonatomic, strong) HDLEZButton *unlockButton;//开锁按钮 |
| | | |
| | | @property (nonatomic, copy) NSString *streamToken; |
| | | |
| | | @end |
| | |
| | | self.ptzView.hidden = YES; |
| | | self.talkView.hidden = YES; |
| | | |
| | | if (!self.deviceInfo) {//如果没有传deviceInfo,需主动获取 |
| | | [self getDeviceInfo]; |
| | | return; |
| | | } |
| | | |
| | | //初始化相关数据 |
| | | [self initialData]; |
| | | |
| | | // self.talkButton.enabled = self.deviceInfo.isSupportTalk; |
| | | // self.controlButton.enabled = self.deviceInfo.isSupportPTZ; |
| | | // self.captureButton.enabled = NO; |
| | | // self.localRecordButton.enabled = NO; |
| | | // self.streamPlayBtn.hidden = YES; |
| | | // |
| | | // if (_url) |
| | | // { |
| | | // _player = [EZOPENSDK createPlayerWithUrl:_url]; |
| | | // } |
| | | // else if([self.deviceInfo.deviceType containsString:@"CAS"]) //hub |
| | | // { |
| | | // _cameraInfo = [[EZCameraInfo alloc]init]; //兼容demo之前的业务逻辑,手动填充了cameraInfo,实际开发直接传入序列号和通道号生成EZPlayer即可 |
| | | // _cameraInfo.deviceSerial = _hubCoDevSerial; |
| | | // _cameraInfo.cameraNo = _cameraIndex; |
| | | // _player = [EZOPENSDK createPlayerWithDeviceSerial:_cameraInfo.deviceSerial cameraNo:_cameraInfo.cameraNo]; |
| | | // } |
| | | // else |
| | | // { |
| | | // _cameraInfo = [self.deviceInfo.cameraInfo dd_objectAtIndex:_cameraIndex]; |
| | | // _player = [EZOPENSDK createPlayerWithDeviceSerial:_cameraInfo.deviceSerial cameraNo:_cameraInfo.cameraNo]; |
| | | // _talkPlayer = [EZOPENSDK createPlayerWithDeviceSerial:_cameraInfo.deviceSerial cameraNo:_cameraInfo.cameraNo]; |
| | | // if (_cameraInfo.videoLevel == 2) |
| | | // { |
| | | // [self.qualityButton setTitle:NSLocalizedString(@"device_quality_high", @"高清") forState:UIControlStateNormal]; |
| | | // } |
| | | // else if (_cameraInfo.videoLevel == 1) |
| | | // { |
| | | // [self.qualityButton setTitle:NSLocalizedString(@"device_quality_median", @"均衡") forState:UIControlStateNormal]; |
| | | // } |
| | | // else |
| | | // { |
| | | // [self.qualityButton setTitle:NSLocalizedString(@"device_quality_low",@"流畅") forState:UIControlStateNormal]; |
| | | // } |
| | | // } |
| | | // if (_cameraInfo.cameraNo == 0 || [self.deviceInfo.deviceType containsString:@"CAS"]) { //不支持清晰度切换 |
| | | // self.qualityButton.hidden = YES; |
| | | // } |
| | | // |
| | | // if (self.deviceInfo.cameraInfo.count > 1) { |
| | | // self.title = [NSString stringWithFormat:@"Camera %ld", (long)_cameraInfo.cameraNo]; |
| | | // } |
| | | // else { |
| | | // self.title = _deviceInfo.deviceName; |
| | | // } |
| | | // self.largeTitleLabel.text = self.title; |
| | | // [self hidenWatchFunc]; |
| | | // |
| | | //#if DEBUG |
| | | // if (!_url) |
| | | // { |
| | | // //抓图接口演示代码 |
| | | // [EZOPENSDK captureCamera:_cameraInfo.deviceSerial cameraNo:_cameraInfo.cameraNo completion:^(NSString *url, NSError *error) { |
| | | // NSLog(@"[%@] capture cameraNo is [%d] url is %@, error is %@", _cameraInfo.deviceSerial, (int)_cameraInfo.cameraNo, url, error); |
| | | // }]; |
| | | // } |
| | | //#endif |
| | | // |
| | | // _player.delegate = self; |
| | | // _talkPlayer.delegate = self; |
| | | // //判断设备是否加密,加密就从demo的内存中获取设备验证码填入到播放器的验证码接口里,本demo只处理内存存储,本地持久化存储用户自行完成 |
| | | // if (self.deviceInfo.isEncrypt) |
| | | // { |
| | | // NSString *verifyCode = [[GlobalKit shareKit].deviceVerifyCodeBySerial objectForKey:self.deviceInfo.deviceSerial]; |
| | | // [_player setPlayVerifyCode:verifyCode]; |
| | | // [_talkPlayer setPlayVerifyCode:verifyCode]; |
| | | // } |
| | | // [_player setPlayerView:_playerView]; |
| | | // BOOL hdStatus = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"EZVideoPlayHardDecodingStatus_%@", self.deviceInfo.deviceSerial]]; |
| | | // [_player setHDPriority:hdStatus]; |
| | | // [_player startRealPlay]; |
| | | // |
| | | // if(!_loadingView) |
| | | // _loadingView = [[HIKLoadView alloc] initWithHIKLoadViewStyle:HIKLoadViewStyleSqureClockWise]; |
| | | // [self.view insertSubview:_loadingView aboveSubview:self.playerView]; |
| | | // [_loadingView mas_makeConstraints:^(MASConstraintMaker *make) { |
| | | // make.width.height.mas_equalTo(@14); |
| | | // make.centerX.mas_equalTo(self.playerView.mas_centerX); |
| | | // make.centerY.mas_equalTo(self.playerView.mas_centerY); |
| | | // }]; |
| | | // [self.loadingView startSquareClcokwiseAnimation]; |
| | | // |
| | | // self.largeBackButton.hidden = YES; |
| | | // _isOpenSound = YES; |
| | | // |
| | | // [self.controlButton dd_centerImageAndTitle]; |
| | | // [self.talkButton dd_centerImageAndTitle]; |
| | | // [self.captureButton dd_centerImageAndTitle]; |
| | | // [self.localRecordButton dd_centerImageAndTitle]; |
| | | // |
| | | // [self.voiceButton setImage:[UIImage imageNamed:@"preview_unvoice_btn_sel"] forState:UIControlStateHighlighted]; |
| | | // [self addLine]; |
| | | // |
| | | // self.localRecordLabel.layer.borderColor = [UIColor whiteColor].CGColor; |
| | | // self.localRecordLabel.layer.cornerRadius = 12.0f; |
| | | // self.localRecordLabel.layer.borderWidth = 1.0f; |
| | | // self.localRecordLabel.clipsToBounds = YES; |
| | | // self.playButton.enabled = NO; |
| | | // |
| | | // |
| | | // self.scrollView.minimumZoomScale = MinimumZoomScale; |
| | | // self.scrollView.maximumZoomScale = MaximumZoomScale; |
| | | // self.scrollView.backgroundColor = [UIColor clearColor]; |
| | | // self.scrollView.delegate = self; |
| | | // self.scrollView.showsHorizontalScrollIndicator = NO; |
| | | // self.scrollView.showsVerticalScrollIndicator = NO; |
| | | // self.scrollView.userInteractionEnabled = YES; |
| | | // self.scrollView.multipleTouchEnabled = YES; |
| | | // self.scrollView.pagingEnabled = NO; |
| | | // |
| | | // if ([GlobalKit shareKit].deviceType==HDLEZDeviceType_Door) {//为门锁时,只显示麦克风和开门按钮 |
| | | // self.captureButton.hidden=YES; |
| | | // self.localRecordButton.hidden=YES; |
| | | // |
| | | // [self.controlButton setTitle:NSLocalizedString(@"device_open", @"开门") forState:UIControlStateNormal]; |
| | | // } |
| | | } |
| | | |
| | | - (void)viewDidAppear:(BOOL)animated { |
| | | [super viewDidAppear:animated]; |
| | | self.navigationController.navigationBar.hidden = NO;//2021-02-01 |
| | | self.ptzViewContraint.constant = self.bottomView.frame.size.height; |
| | | self.talkViewContraint.constant = self.ptzViewContraint.constant; |
| | | } |
| | | |
| | | - (void)viewWillDisappear:(BOOL)animated { |
| | | // self.navigationController.navigationBarHidden = YES;//2021-02-01 添加隐藏navigationBarHidden |
| | | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideQualityView) object:nil]; |
| | | //结束本地录像 |
| | | if(self.localRecordButton.selected) |
| | | { |
| | | [_player stopLocalRecordExt:^(BOOL ret) { |
| | | |
| | | NSLog(@"%d", ret); |
| | | |
| | | [_recordTimer invalidate]; |
| | | _recordTimer = nil; |
| | | self.localRecordLabel.hidden = YES; |
| | | [self saveRecordToPhotosAlbum:_filePath]; |
| | | _filePath = nil; |
| | | }]; |
| | | } |
| | | |
| | | NSLog(@"viewWillDisappear"); |
| | | [super viewWillDisappear:animated]; |
| | | } |
| | | |
| | | - (void)viewDidDisappear:(BOOL)animated |
| | | { |
| | | NSLog(@"viewDidDisappear"); |
| | | [super viewDidDisappear:animated]; |
| | | [_player stopRealPlay]; |
| | | if (_talkPlayer) |
| | | { |
| | | [_talkPlayer stopVoiceTalk]; |
| | | } |
| | | } |
| | | |
| | | - (void)didReceiveMemoryWarning { |
| | | [super didReceiveMemoryWarning]; |
| | | // Dispose of any resources that can be recreated. |
| | | } |
| | | |
| | | /*获取设备信息 |
| | | */ |
| | | -(void)getDeviceInfo{ |
| | | //获取设备信息 |
| | | [EZOpenSDK getDeviceInfo:self.deviceSerial completion:^(EZDeviceInfo *deviceInfo, NSError *error) { |
| | | if(error) |
| | | { |
| | | NSLog(@"EZ 查询设备信息失败"); |
| | | return; |
| | | } |
| | | if (deviceInfo) { |
| | | self.deviceInfo=deviceInfo; |
| | | [self initialData]; |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /*初始化相关数据 |
| | | */ |
| | | -(void)initialData{ |
| | | self.talkButton.enabled = self.deviceInfo.isSupportTalk; |
| | | self.controlButton.enabled = self.deviceInfo.isSupportPTZ; |
| | | self.captureButton.enabled = NO; |
| | |
| | | if ([GlobalKit shareKit].deviceType==HDLEZDeviceType_Door) {//为门锁时,只显示麦克风和开门按钮 |
| | | self.captureButton.hidden=YES; |
| | | self.localRecordButton.hidden=YES; |
| | | self.controlButton.hidden=YES; |
| | | |
| | | [self.controlButton setTitle:NSLocalizedString(@"device_open", @"开门") forState:UIControlStateNormal]; |
| | | } |
| | | } |
| | | |
| | | - (void)viewDidAppear:(BOOL)animated { |
| | | [super viewDidAppear:animated]; |
| | | self.navigationController.navigationBar.hidden = NO;//2021-02-01 |
| | | self.ptzViewContraint.constant = self.bottomView.frame.size.height; |
| | | self.talkViewContraint.constant = self.ptzViewContraint.constant; |
| | | } |
| | | |
| | | - (void)viewWillDisappear:(BOOL)animated { |
| | | // self.navigationController.navigationBarHidden = YES;//2021-02-01 添加隐藏navigationBarHidden |
| | | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideQualityView) object:nil]; |
| | | //结束本地录像 |
| | | if(self.localRecordButton.selected) |
| | | { |
| | | [_player stopLocalRecordExt:^(BOOL ret) { |
| | | |
| | | NSLog(@"%d", ret); |
| | | |
| | | [_recordTimer invalidate]; |
| | | _recordTimer = nil; |
| | | self.localRecordLabel.hidden = YES; |
| | | [self saveRecordToPhotosAlbum:_filePath]; |
| | | _filePath = nil; |
| | | //重设控制台按钮 |
| | | _unlockButton=[[HDLEZButton alloc] init]; |
| | | [self.bottomView addSubview:_unlockButton]; |
| | | [_unlockButton mas_makeConstraints:^(MASConstraintMaker *make) { |
| | | make.top.left.right.bottom.equalTo( self.controlButton); |
| | | }]; |
| | | [_unlockButton setImage:[UIImage imageNamed:@"hdl_ez_ic_unlock_disable"] forState:UIControlStateNormal]; |
| | | [_unlockButton setTitle:NSLocalizedString(@"device_open", @"开门") forState:UIControlStateNormal]; |
| | | [_unlockButton dd_centerImageAndTitle]; |
| | | [_unlockButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal]; |
| | | _unlockButton.titleLabel.font=[UIFont systemFontOfSize:14]; |
| | | [_unlockButton addTarget:self action:@selector(unlockDoor) forControlEvents:UIControlEventTouchUpInside]; |
| | | _unlockButton.enabled=NO; |
| | | // self.controlButton.enabled=YES; |
| | | // [self.controlButton setImage:[UIImage imageNamed:@"hdl_ez_ic_unlock"] forState:UIControlStateNormal]; |
| | | // [self.controlButton setTitle:NSLocalizedString(@"device_open", @"开门") forState:UIControlStateNormal]; |
| | | } |
| | | } |
| | | |
| | | /*开锁 |
| | | */ |
| | | -(void)unlockDoor{ |
| | | [HDLEZAlertInputView showInputAlertWithtitle:HDLEZLocallizedString(@"device_please_input_door_password") cancleTitle:HDLEZLocallizedString(@"device_temp_cancle") sureTitle:HDLEZLocallizedString(@"device_temp_sure") keyboardType:UIKeyboardTypeASCIICapableNumberPad cancleBlock:^{ |
| | | |
| | | } sureBlock:^(NSString * _Nonnull content) { |
| | | HDLEZLog(@"点击了确认:%@",content); |
| | | [MBProgressHUD showHUDAddedTo:self.view animated:YES]; |
| | | __weak __typeof(self)weakSelf = self; |
| | | [[EZHttpUtil sharedManager] authLockByHDL:content deviceId:self.deviceId completion:^(ResponseData * _Nonnull responseData) { |
| | | if (responseData.success) { |
| | | [[EZHttpUtil sharedManager] remoteOpenByHDL:self.streamToken deviceId:self.deviceId completion:^(ResponseData * _Nonnull responseData) { |
| | | [MBProgressHUD hideHUDForView:weakSelf.view animated:YES]; |
| | | if (responseData.success) { |
| | | [weakSelf.view makeToast:HDLEZLocallizedString(@"device_open_success") |
| | | duration:1.5 |
| | | position:@"center"]; |
| | | |
| | | }else{ |
| | | [weakSelf.view makeToast:responseData.message |
| | | duration:1.5 |
| | | position:@"center"]; |
| | | } |
| | | }]; |
| | | }else{ |
| | | [MBProgressHUD hideHUDForView:weakSelf.view animated:YES]; |
| | | [weakSelf.view makeToast:responseData.message |
| | | duration:1.5 |
| | | position:@"center"]; |
| | | } |
| | | }]; |
| | | |
| | | }]; |
| | | |
| | | NSLog(@"viewWillDisappear"); |
| | | [super viewWillDisappear:animated]; |
| | | } |
| | | |
| | | - (void)viewDidDisappear:(BOOL)animated |
| | | { |
| | | NSLog(@"viewDidDisappear"); |
| | | [super viewDidDisappear:animated]; |
| | | [_player stopRealPlay]; |
| | | if (_talkPlayer) |
| | | { |
| | | [_talkPlayer stopVoiceTalk]; |
| | | } |
| | | } |
| | | |
| | | - (void)didReceiveMemoryWarning { |
| | | [super didReceiveMemoryWarning]; |
| | | // Dispose of any resources that can be recreated. |
| | | } |
| | | |
| | | /* |
| | | #pragma mark - Navigation |
| | | |
| | |
| | | - (void)player:(EZPlayer *)player playPrivateTokenInfo:(EZPMPlayPrivateTokenInfo *)tokenInfo { |
| | | NSLog(@"开门token--->%@", tokenInfo.token); |
| | | self.streamToken=tokenInfo.token; |
| | | |
| | | if (!_unlockButton.isEnabled) { |
| | | [_unlockButton setImage:[UIImage imageNamed:@"hdl_ez_ic_unlock"] forState:UIControlStateNormal]; |
| | | _unlockButton.enabled=YES; |
| | | } |
| | | } |
| | | #pragma mark - ValidateCode Methods |
| | | |
| | |
| | | } |
| | | [weakSelf.player stopRealPlay]; |
| | | |
| | | _cameraInfo.videoLevel = type; |
| | | weakSelf.cameraInfo.videoLevel = type; |
| | | if (sender == weakSelf.highButton) |
| | | { |
| | | [weakSelf.qualityButton setTitle:NSLocalizedString(@"device_quality_high", @"高清") forState:UIControlStateNormal]; |
| | |
| | | |
| | | - (IBAction)ptzViewShow:(id)sender |
| | | { |
| | | if ([GlobalKit shareKit].deviceType==HDLEZDeviceType_Door) {//为门锁设备时,执行开门 |
| | | NSString *verifyCode = [[GlobalKit shareKit].deviceVerifyCodeBySerial objectForKey:self.deviceInfo.deviceSerial]; |
| | | |
| | | [[EZHttpUtil sharedManager] authLockByHDL:@"123456" deviceId:self.deviceInfo.deviceSerial verifyCode:verifyCode completion:^(ResponseData * _Nonnull responseData) { |
| | | NSLog(@"终端授权结果:%@",responseData.data); |
| | | [[EZHttpUtil sharedManager] remoteOpenByHDL:self.streamToken deviceId:self.deviceInfo.deviceSerial completion:^(ResponseData * _Nonnull responseData) { |
| | | NSLog(@"开门结果:%@",responseData.data); |
| | | }]; |
| | | }]; |
| | | return; |
| | | } |
| | | |
| | | self.ptzView.hidden = NO; |
| | | [self.bottomView bringSubviewToFront:self.ptzView]; |
| | | self.ptzControlButton.alpha = 0; |