萤石云 iOSSDK,移植跨平台相关工程
Davin
2023-06-15 011b0cc918bfa0e36a9ad4a0f45c18b801815920
EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m
@@ -32,6 +32,7 @@
{
    NSOperation *op;
    BOOL _isPressed;
    BOOL _landscape;    // 是否旋转
}
@property (nonatomic) BOOL isOpenSound;
@@ -89,10 +90,12 @@
@property (weak, nonatomic) IBOutlet UILabel *streamTypeLabel;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *zoomSizeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollViewWHRatio; // 滚动视图宽高比
@property (nonatomic, strong) HDLEZButton *unlockButton;//开锁按钮
@property (nonatomic, copy) NSString *streamToken;
@property (nonatomic, strong) UIView *doorPlayerView;//门锁播放view
@end
@@ -113,6 +116,7 @@
    self.isStartingTalk = NO;
    self.ptzView.hidden = YES;
    self.talkView.hidden = YES;
    _landscape = NO;
    
    if (!self.deviceInfo) {//如果没有传deviceInfo,需主动获取
        [self getDeviceInfo];
@@ -240,6 +244,21 @@
//    }
}
/*添加门锁播放view
 */
-(UIView*)doorPlayerView{
    if (!_doorPlayerView) {
        _doorPlayerView=[[UIView alloc] init];
        [_playerView addSubview:_doorPlayerView];
        [_doorPlayerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_playerView.mas_centerX);
            make.top.bottom.equalTo(_playerView);
            make.width.mas_equalTo(_doorPlayerView.mas_height).multipliedBy(1);
        }];
    }
    return _doorPlayerView;
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.hidden = NO;//2021-02-01
@@ -288,11 +307,15 @@
/*获取设备信息
 */
-(void)getDeviceInfo{
    __weak __typeof(self)weakSelf = self;
    //获取设备信息
    [EZOpenSDK getDeviceInfo:self.deviceSerial completion:^(EZDeviceInfo *deviceInfo, NSError *error) {
        if(error)
        {
            NSLog(@"EZ 查询设备信息失败");
            NSLog(@"EZ 查询设备信息失败:%@",error);
            [weakSelf.view makeToast:error.userInfo[@"NSLocalizedDescription"]
                            duration:1.5
                            position:@"center"];
            return;
        }
        if (deviceInfo) {
@@ -372,7 +395,11 @@
        [_player setPlayVerifyCode:verifyCode];
        [_talkPlayer setPlayVerifyCode:verifyCode];
    }
    [_player setPlayerView:_playerView];
//    if ([GlobalKit shareKit].deviceType==HDLEZDeviceType_Door) {//为门锁时
        [_player setPlayerView:self.doorPlayerView];
//    }else{
//        [_player setPlayerView:_playerView];
//    }
    BOOL hdStatus = [[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithFormat:@"EZVideoPlayHardDecodingStatus_%@", self.deviceInfo.deviceSerial]];
    [_player setHDPriority:hdStatus];
    [_player startRealPlay];
@@ -450,7 +477,7 @@
        __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) {
                [[EZHttpUtil sharedManager] remoteOpenByHDL:weakSelf.streamToken deviceId:weakSelf.deviceId completion:^(ResponseData * _Nonnull responseData) {
                    [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
                    if (responseData.success) {
                        [weakSelf.view makeToast:HDLEZLocallizedString(@"device_open_success")
@@ -503,9 +530,22 @@
    }
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
//- (UIInterfaceOrientationMask)supportedInterfaceOrientations
//{
//    return UIInterfaceOrientationMaskAllButUpsideDown;
//}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    if (@available(iOS 16.0, *)) {
        if (_landscape) {
            //横屏
            return UIInterfaceOrientationMaskLandscape;
        } else {
            //竖屏
            return UIInterfaceOrientationMaskPortrait;
        }
    } else {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
@@ -517,15 +557,40 @@
    self.bottomView.hidden = NO;
    self.largeTitleLabel.hidden = YES;
    self.localRecrodContraint.constant = 10;
    [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO];
    [NSLayoutConstraint deactivateConstraints:@[self.scrollViewWHRatio]];
    self.scrollViewWHRatio = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeHeight multiplier:16/9. constant:0];
    [NSLayoutConstraint activateConstraints:@[self.scrollViewWHRatio]];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.scrollView layoutIfNeeded];
        [self.toolBar layoutIfNeeded];
    });
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
       toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.navigationController.navigationBarHidden = YES;
        self.localRecrodContraint.constant = 50;
        self.toolBar.hidden = YES;
//        self.toolBar.hidden = YES;
        self.largeTitleLabel.hidden = NO;
        self.largeBackButton.hidden = NO;
        self.bottomView.hidden = YES;
        CGFloat tureScreenW = HDLEZ_APP_SCREEN_WIDTH > HDLEZ_APP_SCREEN_HEIGHT ? HDLEZ_APP_SCREEN_HEIGHT : HDLEZ_APP_SCREEN_WIDTH;
        CGFloat tureScreenH = HDLEZ_APP_SCREEN_WIDTH < HDLEZ_APP_SCREEN_HEIGHT ? HDLEZ_APP_SCREEN_HEIGHT : HDLEZ_APP_SCREEN_WIDTH;
        [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO];
        [NSLayoutConstraint deactivateConstraints:@[self.scrollViewWHRatio]];
        self.scrollViewWHRatio = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeHeight multiplier:tureScreenH/(tureScreenW - 37) constant:0];
        [NSLayoutConstraint activateConstraints:@[self.scrollViewWHRatio]];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.scrollView layoutIfNeeded];
            [self.toolBar layoutIfNeeded];
        });
    }
}
@@ -578,6 +643,27 @@
    }
    [_emptyButton setTitle:[NSString stringWithFormat:fromatStr,value] forState:UIControlStateNormal];
}
/**
 *  收到的画面长宽值
 *
 *  @param player 播放器对象
 *  @param height 高度
 *  @param width  宽度
 */
- (void)player:(EZPlayer *)player didReceivedDisplayHeight:(NSInteger)height displayWidth:(NSInteger)width{
//    HDLEZLog(@"画面长:%ld,宽:%ld",(long)height,(long)width);
    CGFloat playerVH=self.playerView.frame.size.height;
//    HDLEZLog(@"高:%ld",(long)playerVH);
    CGFloat ratio=((CGFloat)width)/((CGFloat)height);
//    HDLEZLog(@"比例:%f",ratio);
    CGFloat playerVW=playerVH*ratio;
//    HDLEZLog(@"宽:%ld",(long)playerVW);
    [self.doorPlayerView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(_doorPlayerView.mas_height).multipliedBy(ratio);
    }];
}
@@ -773,14 +859,60 @@
- (IBAction)large:(id)sender
{
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    if (_landscape == YES) {
        [self largeBack:self.largeBackButton];
        return;
    }
    NSLog(@"######进入横屏!");
    _landscape = YES;
    if (@available(iOS 16.0, *)) {
        if (self.navigationController) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
            });
        } else {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self setNeedsUpdateOfSupportedInterfaceOrientations];
            });
        }
        NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
        UIWindowScene *ws = (UIWindowScene *)array.firstObject;
        UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
        geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskLandscape;
        [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
            NSLog(@"iOS 16 Error: %@",error);
        }];
    } else {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
}
- (IBAction)largeBack:(id)sender
{
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    NSLog(@"######收回横屏!");
    _landscape = NO;
    if (@available(iOS 16.0, *)) {
        if (self.navigationController) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
            });
        } else {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self setNeedsUpdateOfSupportedInterfaceOrientations];
            });
        }
        NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
        UIWindowScene *ws = (UIWindowScene *)array.firstObject;
        UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
        geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskPortrait;
        [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
            NSLog(@"iOS 16 Error: %@",error);
        }];
    } else {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
}
- (IBAction)capture:(id)sender
@@ -1280,17 +1412,41 @@
    }
    CGFloat averageWidth = [UIScreen mainScreen].bounds.size.width/5.0;
    UIImageView *lineImageView1 = [UIView dd_instanceVerticalLine:20 color:[UIColor grayColor]];
    lineImageView1.frame = CGRectMake(averageWidth, 7, lineImageView1.frame.size.width, lineImageView1.frame.size.height);
//    lineImageView1.frame = CGRectMake(averageWidth, 7, lineImageView1.frame.size.width, lineImageView1.frame.size.height);
    [self.toolBar addSubview:lineImageView1];
    [lineImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.playButton.mas_right);
        make.centerY.mas_equalTo(self.playButton.mas_centerY);
        make.width.mas_equalTo(lineImageView1.frame.size.width);
        make.height.mas_equalTo(lineImageView1.frame.size.height);
    }];
    UIImageView *lineImageView2 = [UIView dd_instanceVerticalLine:20 color:[UIColor grayColor]];
    lineImageView2.frame = CGRectMake(averageWidth * 2, 7, lineImageView2.frame.size.width, lineImageView2.frame.size.height);
//    lineImageView2.frame = CGRectMake(averageWidth * 2, 7, lineImageView2.frame.size.width, lineImageView2.frame.size.height);
    [self.toolBar addSubview:lineImageView2];
    [lineImageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.voiceButton.mas_right);
        make.centerY.mas_equalTo(self.voiceButton.mas_centerY);
        make.width.mas_equalTo(lineImageView2.frame.size.width);
        make.height.mas_equalTo(lineImageView2.frame.size.height);
    }];
    UIImageView *lineImageView3 = [UIView dd_instanceVerticalLine:20 color:[UIColor grayColor]];
    lineImageView3.frame = CGRectMake(averageWidth * 3, 7, lineImageView3.frame.size.width, lineImageView3.frame.size.height);
//    lineImageView3.frame = CGRectMake(averageWidth * 3, 7, lineImageView3.frame.size.width, lineImageView3.frame.size.height);
    [self.toolBar addSubview:lineImageView3];
    [lineImageView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.qualityButton.mas_right);
        make.centerY.mas_equalTo(self.qualityButton.mas_centerY);
        make.width.mas_equalTo(lineImageView3.frame.size.width);
        make.height.mas_equalTo(lineImageView3.frame.size.height);
    }];
    UIImageView *lineImageView4 = [UIView dd_instanceVerticalLine:20 color:[UIColor grayColor]];
    lineImageView4.frame = CGRectMake(averageWidth * 4, 7, lineImageView4.frame.size.width, lineImageView4.frame.size.height);
//    lineImageView4.frame = CGRectMake(averageWidth * 4, 7, lineImageView4.frame.size.width, lineImageView4.frame.size.height);
    [self.toolBar addSubview:lineImageView4];
    [lineImageView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.emptyButton.mas_right);
        make.centerY.mas_equalTo(self.emptyButton.mas_centerY);
        make.width.mas_equalTo(lineImageView4.frame.size.width);
        make.height.mas_equalTo(lineImageView4.frame.size.height);
    }];
}
@@ -1391,5 +1547,8 @@
    }
}
- (BOOL)prefersHomeIndicatorAutoHidden {
    return YES;
}
@end