Davin
2023-06-25 dd29df2e08ac87c878e26513f1b5ae06eae7a6d9
EZSDK/EZSDK/EZ/UIViewControllers/EZLivePlayViewController.m
@@ -25,6 +25,7 @@
#import <EZOpenSDKFramework/EZPMPlayPrivateTokenInfo.h>
#import "HDLEZAlertInputView.h"
#import "HDLEZOPButton.h"
#import "HDLEZVideoDoorToolView.h"
#define MinimumZoomScale 1.0
#define MaximumZoomScale 4.0
@@ -49,6 +50,9 @@
@property (nonatomic, strong) HIKLoadView *loadingView;
@property (nonatomic, weak) IBOutlet UIButton *playerPlayButton;
@property (nonatomic, weak) IBOutlet UIView *playerView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *playerViewWHRatio;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *playerViewBottomMargin;
@property (nonatomic, weak) IBOutlet UIView *toolBar;
@property (nonatomic, weak) IBOutlet UIView *bottomView;
@property (nonatomic, weak) IBOutlet UIButton *controlButton;
@@ -98,6 +102,7 @@
@property (nonatomic, copy) NSString *streamToken;
@property (nonatomic, strong) UIView *doorPlayerView;//门锁播放view
@property (nonatomic, assign) CGFloat doorPlayerAspectRatio;   // 门锁播放视图宽高比
// 呼叫视图相关控件
@property (weak, nonatomic) IBOutlet UIView *videoCallOutView;      // 呼叫弹框
@@ -105,6 +110,8 @@
@property (weak, nonatomic) IBOutlet HDLEZOPButton *hangUpButton;        // 挂断按钮
@property (weak, nonatomic) IBOutlet HDLEZOPButton *ignoreButton;        // 忽略按钮
@property (weak, nonatomic) IBOutlet HDLEZOPButton *answerButton;        // 接听按钮
@property (strong, nonatomic) HDLEZVideoDoorToolView *fullSceneToolView; // 全屏工具视图
@end
@@ -125,6 +132,8 @@
    self.isStartingTalk = NO;
    self.ptzView.hidden = YES;
    self.talkView.hidden = YES;
    self.videoCallOutView.hidden = YES;
    self.doorPlayerAspectRatio = HDLEZ_APP_SCREEN_WIDTH / HDLEZ_APP_SCREEN_HEIGHT;
    _landscape = NO;
    
    if (!self.deviceInfo) {//如果没有传deviceInfo,需主动获取
@@ -374,6 +383,7 @@
            [self.qualityButton setTitle:NSLocalizedString(@"device_quality_low",@"流畅") forState:UIControlStateNormal];
        }
    }
#warning 不支持切换清晰度,全屏时也需要主持
    if (_cameraInfo.cameraNo == 0 || [self.deviceInfo.deviceType containsString:@"CAS"]) { //不支持清晰度切换
        self.qualityButton.hidden = YES;
    }
@@ -486,6 +496,13 @@
    [self.answerButton setTitle:HDLEZLocallizedString(@"device_callout_answer") forState:UIControlStateNormal];
    self.answerButton.imagePosition = HDLEZOPButtonImagePositionTop;
    self.answerButton.spacingBetweenImageAndTitle = 12.;
    // 门锁全屏状态下工具栏
    [self.view addSubview:self.fullSceneToolView];
    __weak EZLivePlayViewController *weakSelf = self;
    [self.fullSceneToolView configPlayStatus:YES soundOn:YES videoLevel:1 toolOperation:^(HDLEZVideoFullSceneOperation operationType) {
        [weakSelf doorLockFullSceneOperation:operationType];
    }];
}
/*开锁
@@ -677,12 +694,13 @@
 *  @param width  宽度
 */
- (void)player:(EZPlayer *)player didReceivedDisplayHeight:(NSInteger)height displayWidth:(NSInteger)width{
//    HDLEZLog(@"画面长:%ld,宽:%ld",(long)height,(long)width);
    NSLog(@"画面长:%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);
    NSLog(@"比例:%f",ratio);
    CGFloat playerVW=playerVH*ratio;
    self.doorPlayerAspectRatio = ratio;
//    HDLEZLog(@"宽:%ld",(long)playerVW);
    [self.doorPlayerView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(_doorPlayerView.mas_height).multipliedBy(ratio);
@@ -882,6 +900,7 @@
- (IBAction)large:(id)sender
{
    self.videoCallOutView.hidden = YES;
    if (_landscape == YES) {
        [self largeBack:self.largeBackButton];
        return;
@@ -890,22 +909,29 @@
    if (self.isVideoDoorLock) {
        self.navigationController.navigationBarHidden = YES;
        self.localRecrodContraint.constant = 50;
        self.toolBar.hidden = NO;
        self.largeTitleLabel.hidden = NO;
        self.toolBar.hidden = YES;
        self.largeTitleLabel.hidden = YES;
        self.largeBackButton.hidden = YES;
        self.bottomView.hidden = YES;
        self.videoCallOutView.hidden = YES;
        self.scrollView.backgroundColor = [UIColor blackColor];
                
        [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO];
        [NSLayoutConstraint deactivateConstraints:@[self.scrollViewTopMargin, self.scrollViewWHRatio]];
        [self.playerView setTranslatesAutoresizingMaskIntoConstraints:NO];
        [NSLayoutConstraint deactivateConstraints:@[self.scrollViewTopMargin, self.scrollViewWHRatio, self.playerViewWHRatio, self.playerViewBottomMargin]];
        self.scrollViewTopMargin = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-HDLEZ_APP_STATUS_BAR_HEIGHT];
        self.scrollViewWHRatio = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeHeight multiplier:HDLEZ_APP_SCREEN_WIDTH/(HDLEZ_APP_SCREEN_HEIGHT - 37.) constant:0];
        [NSLayoutConstraint activateConstraints:@[self.scrollViewTopMargin, self.scrollViewWHRatio]];
        self.scrollViewWHRatio = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeHeight multiplier:HDLEZ_APP_SCREEN_WIDTH/HDLEZ_APP_SCREEN_HEIGHT constant:0];
        self.playerViewWHRatio = [NSLayoutConstraint constraintWithItem:self.playerView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeHeight multiplier:self.doorPlayerAspectRatio constant:0];
        CGFloat playerBottomMargin = HDLEZ_APP_SCREEN_HEIGHT - (HDLEZ_APP_SCREEN_WIDTH / self.doorPlayerAspectRatio);
        NSLog(@"########播放间隙:%lf", playerBottomMargin);
        self.playerViewBottomMargin = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:playerBottomMargin];
        [NSLayoutConstraint activateConstraints:@[self.scrollViewTopMargin, self.scrollViewWHRatio, self.playerViewWHRatio, self.playerViewBottomMargin]];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.scrollView layoutIfNeeded];
            [self.toolBar layoutIfNeeded];
            [self.playerView layoutIfNeeded];
        });
        self.fullSceneToolView.hidden = NO;
        [self.view bringSubviewToFront:self.fullSceneToolView];
        return;
    }
    if (@available(iOS 16.0, *)) {
@@ -942,17 +968,22 @@
        self.largeTitleLabel.hidden = YES;
        self.localRecrodContraint.constant = 10;
        self.videoCallOutView.hidden = !self.isShowAlert;
        self.scrollView.backgroundColor = [UIColor clearColor];
        
        [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.toolBar setTranslatesAutoresizingMaskIntoConstraints:NO];
        [NSLayoutConstraint deactivateConstraints:@[self.scrollViewTopMargin,self.scrollViewWHRatio]];
        [self.playerView setTranslatesAutoresizingMaskIntoConstraints:NO];
        [NSLayoutConstraint deactivateConstraints:@[self.scrollViewTopMargin,self.scrollViewWHRatio, self.playerViewWHRatio, self.playerViewBottomMargin]];
        self.scrollViewTopMargin = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        self.scrollViewWHRatio = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeHeight multiplier:16/9. constant:0];
        [NSLayoutConstraint activateConstraints:@[self.scrollViewTopMargin,self.scrollViewWHRatio]];
        self.playerViewWHRatio = [NSLayoutConstraint constraintWithItem:self.playerView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeHeight multiplier:16/9. constant:0];
        self.playerViewBottomMargin = [NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
        [NSLayoutConstraint activateConstraints:@[self.scrollViewTopMargin,self.scrollViewWHRatio, self.playerViewWHRatio, self.playerViewBottomMargin]];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.scrollView layoutIfNeeded];
            [self.toolBar layoutIfNeeded];
            [self.playerView layoutIfNeeded];
        });
        self.fullSceneToolView.hidden = YES;
        return;
    }
    if (@available(iOS 16.0, *)) {
@@ -1041,6 +1072,7 @@
        [self.voiceButton setImage:[UIImage imageNamed:@"preview_voice_btn"] forState:UIControlStateNormal];
    }
    _isOpenSound = !_isOpenSound;
    [self.fullSceneToolView soundOn:_isOpenSound];
}
- (IBAction)playButtonClicked:(id)sender
@@ -1069,6 +1101,11 @@
        [self.loadingView startSquareClcokwiseAnimation];
    }
    _isPlaying = !_isPlaying;
    [self.fullSceneToolView playStatus:_isPlaying];
}
- (SEL)extracted {
    return @selector(hideQualityView);
}
- (IBAction)qualityButtonClicked:(id)sender
@@ -1081,7 +1118,7 @@
    {
        self.qualityView.hidden = NO;
        //停留5s以后隐藏视频质量View.
        [self performSelector:@selector(hideQualityView) withObject:nil afterDelay:5.0f];
        [self performSelector:[self extracted] withObject:nil afterDelay:5.0f];
    }
    self.qualityButton.selected = !self.qualityButton.selected;
}
@@ -1134,14 +1171,17 @@
                      if (sender == weakSelf.highButton)
                      {
                          [weakSelf.qualityButton setTitle:NSLocalizedString(@"device_quality_high", @"高清") forState:UIControlStateNormal];
                          [self.fullSceneToolView videoLevel:2];
                      }
                      else if (sender == weakSelf.middleButton)
                      {
                          [weakSelf.qualityButton setTitle:NSLocalizedString(@"device_quality_median", @"均衡") forState:UIControlStateNormal];
                          [self.fullSceneToolView videoLevel:1];
                      }
                      else
                      {
                          [weakSelf.qualityButton setTitle:NSLocalizedString(@"device_quality_low", @"流畅") forState:UIControlStateNormal];
                          [self.fullSceneToolView videoLevel:0];
                      }
                      if (result)
                      {
@@ -1642,6 +1682,52 @@
    }
}
#pragma mark - PrivateMethod (门锁全屏时的一系列操作)
- (void)doorLockFullSceneOperation:(HDLEZVideoFullSceneOperation)operation {
    switch (operation) {
        case HDLEZVideoFullSceneOperationOfHangUp: {    // 挂断
            [self hiddenCallOutAlertView];
        }
            break;
        case HDLEZVideoFullSceneOperationOfPlay: {  // 播放
            [self playButtonClicked:self.playButton];
        }
            break;
        case HDLEZVideoFullSceneOperationOfPause: { // 暂停
            [self playButtonClicked:self.playButton];
        }
            break;
        case HDLEZVideoFullSceneOperationOfSound: { // 开启音量
            [_player openSound];
            NSLog(@"#######开启音量");
        }
            break;
        case HDLEZVideoFullSceneOperationOfSoundOff: {  // 静音
            [_player closeSound];
            NSLog(@"#######静音");
        }
            break;
        case HDLEZVideoFullSceneOperationOfSmooth: {    // 流畅
            [self qualitySelectedClicked:self.lowButton];
        }
            break;
        case HDLEZVideoFullSceneOperationOfBalance: {   // 均衡
            [self qualitySelectedClicked:self.middleButton];
        }
            break;
        case HDLEZVideoFullSceneOperationOfHDFull: {    // 高清
            [self qualitySelectedClicked:self.highButton];
        }
            break;
        case HDLEZVideoFullSceneOperationOfExitFull: {  // 退出全屏
            [self largeBack:self.largeButton];
        }
            break;
        default:
            break;
    }
}
#pragma Setter
- (void)setIsShowAlert:(BOOL)isShowAlert {
    _isShowAlert = isShowAlert;
@@ -1654,6 +1740,15 @@
    }
}
#pragma mark - Getter
- (HDLEZVideoDoorToolView *)fullSceneToolView {
    if (!_fullSceneToolView) {
        _fullSceneToolView = [[HDLEZVideoDoorToolView alloc] initWithFrame:CGRectMake(0, HDLEZ_APP_SCREEN_HEIGHT - 280, HDLEZ_APP_SCREEN_WIDTH, 280)];
        _fullSceneToolView.hidden = YES;
    }
    return _fullSceneToolView;
}
- (BOOL)prefersHomeIndicatorAutoHidden {
    return YES;
}