You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
781 lines
27 KiB
781 lines
27 KiB
// |
|
// TihuVideoCallViewController.m |
|
// tongxin |
|
// |
|
// Created by ecell on 2021/7/29. |
|
// Copyright © 2021 xTT. All rights reserved. |
|
// |
|
|
|
#import "TihuVideoCallViewController.h" |
|
#import "Masonry.h" |
|
#import "QMUIKit.h" |
|
#import <AVFoundation/AVFoundation.h> |
|
#import <JLAuthorizationManager.h> |
|
#import "MZTimerLabel.h" |
|
#import "TihuManager.h" |
|
#import "UIView+XHRemoteImage.h" |
|
|
|
|
|
#define IPHONEXLater \ |
|
({BOOL isPhoneX = NO;\ |
|
if (@available(iOS 11.0, *)) {\ |
|
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\ |
|
}\ |
|
(isPhoneX);}) |
|
|
|
#define KKStatusBarHeight 88 |
|
#define KKSafeAreaBottomHeight (IPHONEXLater ? 34 : 0) |
|
//#define ScreenWidth [[UIScreen mainScreen] bounds].size.width |
|
//#define ScreenHeight [[UIScreen mainScreen] bounds].size.height |
|
|
|
|
|
#define kRTCRate ([UIScreen mainScreen].bounds.size.width / 320.0) |
|
// 视频聊天时,小窗口的宽 |
|
#define kMicVideoW (110 * kRTCRate) |
|
// 视频聊天时,小窗口的高 |
|
#define kMicVideoH (110 * kRTCRate) |
|
// 头像的大小 |
|
#define kAvatarWH (70 * kRTCRate) |
|
|
|
|
|
static CGFloat const kTitleSpace = 12; |
|
static CGFloat const kBtnHeitht = 106; |
|
|
|
@interface TihuVideoCallViewController (){ |
|
CGFloat _kBottomSide; |
|
} |
|
|
|
/// 拨打出去遮挡半透明View |
|
@property (nonatomic ,weak) UIView *shelterView; |
|
|
|
@property(nonatomic, strong) UIImageView *localImage; |
|
@property (nonatomic,strong)AVCaptureVideoPreviewLayer *previewLayer; //摄像头预览layer |
|
@property(nonatomic, strong) UIImageView *playImage; |
|
|
|
// view 相关 |
|
@property(nonatomic, strong) UIImageView *iconImage; |
|
@property(nonatomic, strong) UILabel *nameLabel; |
|
@property(nonatomic, strong) QMUIButton *acceptBtn; /// 接听 |
|
@property(nonatomic, strong) QMUIButton *cancelBtn; /// 取消 |
|
@property(nonatomic, strong) QMUIButton *closeBtn; /// 挂断 |
|
@property(nonatomic, strong) QMUIButton *refuseBtn; /// 拒绝 |
|
@property(nonatomic, strong) QMUIButton *swFBBtn; //切换摄像头 |
|
@property(nonatomic, strong) UILabel *tipsLabel; |
|
@property(nonatomic, strong) MZTimerLabel *timeLabel; |
|
@property(nonatomic, strong) QMUIButton *swSilenceBtn;//麦克风已开 |
|
@property(nonatomic, strong) QMUIButton *swSXTBtn;//麦克风已开 |
|
|
|
|
|
@property(nonatomic, strong) QMUIButton *exchangeBtn; |
|
@property(nonatomic, assign) BOOL isBigMine; |
|
|
|
|
|
/// 是否未打开麦克风 |
|
@property (nonatomic) BOOL isUNAuthorizationTypeAudio; |
|
|
|
/// 是否未打开相机 |
|
@property (nonatomic) BOOL isUNAuthorizationTypeCamera; |
|
|
|
@end |
|
|
|
@implementation TihuVideoCallViewController |
|
|
|
- (void)dealloc { |
|
[MoonChatPlatform getInstance].avChatingDelegate = nil; |
|
[TihuManager shared].callViewController = nil; |
|
} |
|
|
|
#pragma mark chatingEventDelegate |
|
//挂断事件 |
|
- (void)chatAVCloseEventCallBack:(int)type |
|
{ |
|
NSString *str = @"end"; |
|
if (type == 0) { |
|
str = @"通话结束"; |
|
} else if (type == 1) { |
|
str = @"通话忙"; |
|
} else if (type == 2) { |
|
str = @"对方拒绝"; |
|
} |
|
[self p_delayDismissWithTips:str]; |
|
[[TihuManager shared] stopRing]; |
|
[TihuManager shared].callViewController = nil; |
|
xLog(@"2.0 chatAVCloseEventCallBack===%d", type); |
|
} |
|
|
|
//拨打时,初始化预览自己的摄像头信息 |
|
- (void)chatVideoPreviewInit:(AVCaptureSession *)session |
|
{ |
|
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; |
|
[self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; |
|
self.previewLayer.frame = self.localImage.bounds; |
|
[self.localImage.layer addSublayer:self.previewLayer]; |
|
[MoonChatPlatform setVideoSurface:self.previewLayer isMine:YES]; |
|
|
|
[[TihuManager shared] dismissPopView]; |
|
self.shelterView.hidden = NO; |
|
} |
|
|
|
//拨打出去,对方接通了,初始化视频相关的信息 |
|
- (void)chatVideoSessionInit:(AVCaptureSession *)session |
|
{ |
|
self.shelterView.hidden = YES; |
|
self.playImage.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight); |
|
[MoonChatPlatform setVideoSurface:self.playImage isMine:NO]; |
|
|
|
CGFloat width = kMicVideoW; |
|
CGFloat height = kMicVideoH; |
|
CGRect preFrame = CGRectMake(ScreenWidth - width-15, KKStatusBarHeight,width,height); |
|
self.localImage.frame = preFrame; |
|
self.localImage.layer.borderWidth = 1.5; |
|
self.localImage.layer.borderColor = KKWhiteColorColor.CGColor; |
|
self.localImage.layer.cornerRadius = 3; |
|
self.localImage.layer.masksToBounds = YES; |
|
|
|
self.previewLayer.frame = self.localImage.bounds; |
|
|
|
[self.view addSubview:self.exchangeBtn]; |
|
[self comeToVideoChatUI]; |
|
|
|
|
|
[[TihuManager shared] stopRing]; |
|
NSLog(@"===chatVideoSessionInit==="); |
|
} |
|
|
|
//视频来电,接通了,初始化音频相关信息 |
|
- (void)chatAudioInit:(BOOL)isCalling { |
|
if (!isCalling) { |
|
// [self.swVAAcceptBtn removeFromSuperview]; |
|
return; |
|
} |
|
[self removeView]; |
|
[self initCenterView]; |
|
|
|
[[TihuManager shared] stopRing]; |
|
NSLog(@"===chatAudioInit==="); |
|
} |
|
|
|
//图像数据开始收到了 |
|
- (void)chatVideoDataReceived { |
|
NSLog(@"开始接收图像"); |
|
} |
|
|
|
- (void)viewWillAppear:(BOOL)animated { |
|
[super viewWillAppear:animated]; |
|
[self.navigationController setNavigationBarHidden:YES animated:NO]; |
|
//强制亮屏 |
|
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive){ |
|
[self judgeAuthorization]; |
|
} |
|
} |
|
|
|
- (void)judgeAuthorization |
|
{ |
|
if(self.isUNAuthorizationTypeCamera == YES) |
|
{ |
|
[self showAlertAuthorizationTypeCamera]; |
|
}else if(self.isUNAuthorizationTypeAudio == YES) |
|
{ |
|
[self showAlertAuthorizationTypeVideo]; |
|
} |
|
} |
|
|
|
-(void)showAlertAuthorizationTypeVideo{ |
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:[NSString stringWithFormat:@"请在iPhone的\"设置-隐私-麦克风\"选项中,允许%@访问你的麦克风",APPName] message:nil style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
|
|
} cancelHandler:^(LGAlertView *alertView) {} destructiveHandler:nil]; |
|
|
|
[alertView showAnimated:YES completionHandler:nil]; |
|
} |
|
|
|
-(void)showAlertAuthorizationTypeCamera{ |
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:[NSString stringWithFormat:@"请在iPhone的\"设置-隐私-相机\"选项中,允许%@访问你的相机",APPName] message:nil style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
|
|
} cancelHandler:^(LGAlertView *alertView) {} destructiveHandler:nil]; |
|
|
|
[alertView showAnimated:YES completionHandler:nil]; |
|
} |
|
|
|
- (void)viewWillDisappear:(BOOL)animated { |
|
[super viewWillDisappear:animated]; |
|
[self.navigationController setNavigationBarHidden:NO animated:NO]; |
|
[[TihuManager shared] stopRing]; |
|
} |
|
|
|
- (void)viewDidLoad { |
|
|
|
[super viewDidLoad]; |
|
//保持屏幕常亮 |
|
[[UIApplication sharedApplication] setIdleTimerDisabled:YES]; |
|
|
|
self.hidesBottomBarWhenPushed = YES; |
|
|
|
WEAKSELF |
|
JLAuthorizationManager *jlManager = [JLAuthorizationManager defaultManager]; |
|
[jlManager JL_requestAuthorizationWithAuthorizationType:JLAuthorizationTypeAudio |
|
authorizedHandler:nil |
|
unAuthorizedHandler:^{ |
|
weakSelf.isUNAuthorizationTypeAudio = YES; |
|
|
|
}]; |
|
[jlManager JL_requestAuthorizationWithAuthorizationType:JLAuthorizationTypeVideo |
|
authorizedHandler:nil |
|
unAuthorizedHandler:^{ |
|
weakSelf.isUNAuthorizationTypeCamera = YES; |
|
}]; |
|
|
|
//初始化UI和参数 |
|
_kBottomSide = -KKSafeAreaBottomHeight-20; //- 60; |
|
|
|
self.view.backgroundColor = UIColor.blackColor; |
|
|
|
[MoonChatPlatform getInstance].avChatingDelegate = self; |
|
|
|
[self initPreview]; |
|
|
|
[self initTipView]; |
|
[self initCenterView]; |
|
|
|
[self initUIAndRing]; |
|
|
|
if (_isFromBackground) { |
|
//[self chatVideoPreviewInit:[AVCaptureSession new]]; |
|
} |
|
} |
|
|
|
- (void)initUIAndRing { |
|
switch (self.vType) { |
|
case MoonChatViewTypeSendAudio: |
|
[[TihuManager shared] playRing:@"tones"]; |
|
// [self initSendAudioUI]; |
|
break; |
|
case MoonChatViewTypeSendVideo: |
|
[[TihuManager shared] playRing:@"tones"]; |
|
[self initSendVideoUI]; |
|
break; |
|
case MoonChatViewTypeReceiveAudio: |
|
[[TihuManager shared] playRing:@"ring"]; |
|
// [self initReceiceAudioUI]; |
|
break; |
|
case MoonChatViewTypeReceiveVideo: |
|
[[TihuManager shared] playRing:@"ring"]; |
|
[self initReceiceVideoUI]; |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
|
|
#pragma mark - EventHandle |
|
/// 主动接听 |
|
- (void)handleAcceptBtnEvent { |
|
[MoonChatPlatform answerChat]; |
|
} |
|
|
|
/// 切换摄像头 |
|
- (void)handleSWFBBtnEvent { |
|
[MoonChatPlatform switchCamera]; |
|
} |
|
|
|
/// 麦克风打开或关闭 |
|
- (void)handleSWSilenceBtnEvent:(QMUIButton *)sender { |
|
sender.selected = !sender.selected; |
|
[MoonChatPlatform setMute:sender.selected]; |
|
} |
|
|
|
//- (void)handleSWSpeakerBtnEvent:(QMUIButton *)sender { |
|
// sender.selected = !sender.selected; |
|
// [MoonChatPlatform changeSoundType:sender.selected]; |
|
//} |
|
|
|
- (void)handleCancelBtnEvent { |
|
[MoonChatPlatform cancelChat]; |
|
[TihuManager shared].callViewController = nil; |
|
[self p_delayDismissWithTips:@"通话已取消"]; |
|
} |
|
|
|
- (void)handleCloseBtnEvent { |
|
[MoonChatPlatform closeChat]; |
|
[TihuManager shared].callViewController = nil; |
|
[self p_delayDismissWithTips:@"通话结束"]; |
|
} |
|
|
|
- (void)handleRefuseBtnEvent { |
|
[MoonChatPlatform refuseChat]; |
|
[TihuManager shared].callViewController = nil; |
|
[self p_delayDismissWithTips:@"已拒绝,通话结束"]; |
|
|
|
} |
|
|
|
- (void)p_delayDismissWithTips:(NSString *)tips { |
|
[self p_showTips:tips]; |
|
[self performSelector:@selector(p_dismissVC) withObject:nil afterDelay:1.5]; |
|
} |
|
|
|
- (void)p_showTips:(NSString *)tipStr { |
|
[self.view bringSubviewToFront:self.tipsLabel]; |
|
self.tipsLabel.text = tipStr; |
|
self.tipsLabel.hidden = NO; |
|
} |
|
|
|
- (void)p_dismissVC { |
|
[self.navigationController popViewControllerAnimated:YES]; |
|
} |
|
|
|
#pragma mark - 界面相关 *** 可不看 *** |
|
- (void)initPreview |
|
{ |
|
self.playImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; |
|
[self.view addSubview:self.playImage]; |
|
|
|
CGRect rect = CGRectMake(0, 0, ScreenWidth, ScreenHeight); |
|
self.localImage = [[UIImageView alloc] initWithFrame:rect]; |
|
self.localImage.backgroundColor = [UIColor clearColor]; |
|
// [self.view bringSubviewToFront:self.localImage]; |
|
[self.view addSubview:self.localImage]; |
|
|
|
UIView *shelterView = [UIView new]; |
|
shelterView.backgroundColor = UIColor.blackColor; |
|
shelterView.alpha = .6; |
|
shelterView.hidden = YES; |
|
self.shelterView = shelterView; |
|
[self.view addSubview:shelterView]; |
|
} |
|
|
|
|
|
- (void)initCenterView |
|
{ |
|
if (self.vType == MoonChatViewTypeSendVideo) |
|
[self p_showTips:@"正在呼叫中..."]; |
|
else |
|
[self p_showTips:@"连接中"]; |
|
|
|
[self.iconImage setImageWithURL:[NSURL URLWithString:self.device.avator] placeholer:[UIImage imageNamed:@"icon_girl_head_portrait_1"]]; |
|
[self.view addSubview:self.iconImage]; |
|
[self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.size.mas_equalTo(124); |
|
make.centerX.mas_equalTo(self.view); |
|
make.top.equalTo(self.view).offset(154); |
|
}]; |
|
|
|
[self.view addSubview:self.nameLabel]; |
|
self.nameLabel.textAlignment = NSTextAlignmentCenter; |
|
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.top.equalTo(self.iconImage.mas_bottom).offset(12); |
|
make.centerX.equalTo(self.view); |
|
}]; |
|
|
|
[self.tipsLabel mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.top.equalTo(self.nameLabel.mas_bottom).offset(60); |
|
make.centerX.equalTo(self.view); |
|
}]; |
|
} |
|
|
|
/// 提示 |
|
- (void)initTipView |
|
{ |
|
[self.view addSubview:self.tipsLabel]; |
|
[self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.width.mas_equalTo(ScreenWidth - 50); |
|
make.height.mas_equalTo(30); |
|
make.centerY.mas_equalTo(self.view).offset(-50); |
|
make.centerX.mas_equalTo(self.view); |
|
}]; |
|
} |
|
|
|
- (void)removeView { |
|
[self.iconImage removeFromSuperview]; |
|
[self.nameLabel removeFromSuperview]; |
|
[self.acceptBtn removeFromSuperview]; |
|
[self.cancelBtn removeFromSuperview]; |
|
[self.closeBtn removeFromSuperview]; |
|
[self.refuseBtn removeFromSuperview]; |
|
//[self.swVABtn removeFromSuperview]; |
|
[self.swFBBtn removeFromSuperview]; |
|
//[self.swVAAcceptBtn removeFromSuperview]; |
|
[self.exchangeBtn removeFromSuperview]; |
|
} |
|
|
|
/**视频来电*/ |
|
- (void)initReceiceVideoUI |
|
{ |
|
[self.view addSubview:self.acceptBtn]; |
|
[self.acceptBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide); |
|
make.width.mas_equalTo(self.acceptBtn.mas_width); |
|
make.height.mas_equalTo(kBtnHeitht); |
|
make.right.equalTo(self.view.mas_right).inset(Adapted(43)); |
|
}]; |
|
|
|
|
|
[self.view addSubview:self.refuseBtn]; |
|
[self.refuseBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.mas_equalTo(self.acceptBtn); |
|
make.width.mas_equalTo(self.refuseBtn.mas_width); |
|
make.height.mas_equalTo(kBtnHeitht); |
|
make.left.equalTo(self.view).offset(Adapted(43)); |
|
}]; |
|
} |
|
|
|
///**语音来电*/ |
|
//- (void)initReceiceAudioUI |
|
//{ |
|
// [self p_initReceiveTalkUI]; |
|
//} |
|
|
|
//- (void)initSwitchAcceptBtn { |
|
// [self.view addSubview:self.swVAAcceptBtn]; |
|
// [self.swVAAcceptBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
// make.width.mas_equalTo(self.swVAAcceptBtn.mas_width); |
|
// make.height.mas_equalTo(kBtnHeitht); |
|
// make.bottom.mas_equalTo(self.acceptBtn.mas_top).offset(-20); |
|
// make.centerX.mas_equalTo(self.acceptBtn); |
|
// }]; |
|
//} |
|
|
|
|
|
|
|
/**发起视频聊天*/ |
|
- (void)initSendVideoUI |
|
{ |
|
[self.view addSubview:self.cancelBtn]; |
|
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide); |
|
make.centerX.equalTo(self.view); |
|
make.width.mas_equalTo(self.cancelBtn.mas_width); |
|
make.height.mas_equalTo(kBtnHeitht); |
|
}]; |
|
|
|
} |
|
|
|
///**发起语音聊天*/ |
|
//- (void)initSendAudioUI { |
|
// [self.view addSubview:self.cancelBtn]; |
|
// [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
// make.bottom.mas_equalTo(self.view).offset(_kBottomSide); |
|
// make.centerX.mas_equalTo(self.view); |
|
// make.width.mas_equalTo(self.cancelBtn.mas_width); |
|
// make.height.mas_equalTo(kBtnHeitht); |
|
// }]; |
|
// |
|
// [self.view addSubview:self.swSilenceBtn]; |
|
// [self.swSilenceBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
// make.bottom.mas_equalTo(self.cancelBtn); |
|
// make.centerX.mas_equalTo(self.view).offset(-120); |
|
// make.width.mas_equalTo(self.swSilenceBtn.mas_width); |
|
// make.height.mas_equalTo(kBtnHeitht); |
|
// }]; |
|
// |
|
//// [self.view addSubview:self.swSpeakerBtn]; |
|
//// [self.swSpeakerBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
//// make.bottom.mas_equalTo(self.cancelBtn); |
|
//// make.centerX.mas_equalTo(self.view).offset(120); |
|
//// make.width.mas_equalTo(self.swSpeakerBtn.mas_width); |
|
//// make.height.mas_equalTo(kBtnHeitht); |
|
//// }]; |
|
//} |
|
|
|
/**接听视频来电*/ |
|
- (void)comeToVideoChatUI |
|
{ |
|
self.tipsLabel.hidden = YES; |
|
self.acceptBtn.hidden = YES; |
|
self.refuseBtn.hidden = YES; |
|
self.iconImage.hidden = YES; |
|
|
|
self.nameLabel.font = FontBold_(18); |
|
if (self.iRemoteUserId) |
|
self.nameLabel.text = [NSString stringWithFormat:@"与%@进行对话", self.iRemoteUserId]; |
|
else |
|
self.nameLabel.text = [NSString stringWithFormat:@"与%@进行对话", self.device.name]; |
|
[self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.centerX.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(50); |
|
}]; |
|
|
|
|
|
/// 挂断 |
|
[self.view addSubview:self.closeBtn]; |
|
[self.closeBtn mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.mas_equalTo(self.view).offset(_kBottomSide); |
|
make.centerX.equalTo(self.view); |
|
make.width.mas_equalTo(self.closeBtn.mas_width); |
|
make.height.mas_equalTo(kBtnHeitht); |
|
}]; |
|
|
|
/// 麦克风 |
|
[self.view addSubview:self.swSilenceBtn]; |
|
[self.swSilenceBtn mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(self.closeBtn); |
|
make.left.equalTo(self.view).offset(Adapted(43)); |
|
make.width.mas_equalTo(self.swSilenceBtn.mas_width); |
|
make.height.mas_equalTo(kBtnHeitht); |
|
}]; |
|
|
|
/// 打开或关闭摄像头 |
|
[self.view addSubview:self.swSXTBtn]; |
|
[self.swSXTBtn mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(self.closeBtn); |
|
make.right.equalTo(self.view.mas_right).inset(Adapted(43)); |
|
make.width.mas_equalTo(self.swSilenceBtn.mas_width); |
|
make.height.mas_equalTo(kBtnHeitht); |
|
}]; |
|
|
|
/// 计时 |
|
[self.view addSubview:self.timeLabel]; |
|
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.equalTo(self.closeBtn.mas_top).inset(24); |
|
make.centerX.mas_equalTo(self.view); |
|
}]; |
|
[_timeLabel start]; |
|
|
|
|
|
/// 切换摄像头 |
|
[self.view addSubview:self.swFBBtn]; |
|
[self.swFBBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(self.view.mas_right).inset(16); |
|
make.centerY.equalTo(self.nameLabel); |
|
make.size.mas_equalTo(self.swFBBtn.currentImage.size); |
|
}]; |
|
} |
|
|
|
|
|
//交换两个视图 |
|
- (void)exchangeView |
|
{ |
|
self.isBigMine = !self.isBigMine; |
|
if (self.isBigMine) |
|
{ |
|
// CGFloat width = kMicVideoW; |
|
// CGFloat height = kMicVideoH; |
|
// self.localImage.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight); |
|
// self.previewLayer.frame = self.localImage.bounds; |
|
// self.playImage.frame = CGRectMake(ScreenWidth - width, KKStatusBarHeight,width,height); |
|
|
|
//[self.playImage.layer removeFromSuperlayer]; |
|
self.previewLayer.frame = self.playImage.bounds; |
|
[self.playImage.layer addSublayer:self.previewLayer]; |
|
[MoonChatPlatform setVideoSurface:self.previewLayer isMine:YES]; |
|
[MoonChatPlatform setVideoSurface:self.localImage isMine:NO]; |
|
} |
|
else |
|
{ |
|
// CGFloat width = kMicVideoW; |
|
// CGFloat height = kMicVideoH; |
|
// self.localImage.frame = CGRectMake(ScreenWidth - width, KKStatusBarHeight,width,height); |
|
// self.previewLayer.frame = self.localImage.bounds; |
|
// self.playImage.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight); |
|
|
|
//[self.localImage.layer removeFromSuperlayer]; |
|
self.previewLayer.frame = self.localImage.bounds; |
|
[self.localImage.layer addSublayer:self.previewLayer]; |
|
[MoonChatPlatform setVideoSurface:self.previewLayer isMine:YES]; |
|
[MoonChatPlatform setVideoSurface:self.playImage isMine:NO]; |
|
} |
|
} |
|
|
|
#pragma mark - Getters |
|
- (UIImageView *)iconImage { |
|
if (!_iconImage) { |
|
_iconImage = [[UIImageView alloc] init]; |
|
_iconImage.image = [UIImage imageNamed:@"DefaultHead"]; |
|
_iconImage.layer.cornerRadius = 12; |
|
_iconImage.layer.masksToBounds = YES; |
|
} |
|
return _iconImage; |
|
} |
|
|
|
- (UILabel *)nameLabel { |
|
if (!_nameLabel) { |
|
_nameLabel = [[UILabel alloc] init]; |
|
_nameLabel.font = FontBold_(24); |
|
_nameLabel.textAlignment = NSTextAlignmentCenter; |
|
_nameLabel.textColor = UIColor.whiteColor; |
|
if (self.iRemoteUserId) { |
|
//_nameLabel.text = [NSString stringWithFormat:@"与%@进行对话", self.iRemoteUserId]; |
|
_nameLabel.text = self.iRemoteUserId; |
|
} else{ |
|
//_nameLabel.text = [NSString stringWithFormat:@"与%@进行对话", self.device.name]; |
|
_nameLabel.text = self.device.name; |
|
} |
|
|
|
// MARK:不显示用户名称 |
|
//_nameLabel.text = @""; |
|
|
|
} |
|
return _nameLabel; |
|
} |
|
|
|
- (QMUIButton *)acceptBtn { |
|
if (!_acceptBtn) { |
|
_acceptBtn = [self generalBtn:@"接听" imageName:@"video_icon_pickup"]; |
|
_acceptBtn.spacingBetweenImageAndTitle = kTitleSpace; |
|
[_acceptBtn addTarget:self action:@selector(handleAcceptBtnEvent) forControlEvents:UIControlEventTouchUpInside]; |
|
//[_acceptBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; |
|
} |
|
return _acceptBtn; |
|
} |
|
|
|
- (QMUIButton *)cancelBtn { |
|
if (!_cancelBtn) { |
|
_cancelBtn = [self generalBtn:@"取消" imageName:@"video_icon_cancle"]; |
|
_cancelBtn.spacingBetweenImageAndTitle = kTitleSpace; |
|
[_cancelBtn addTarget:self action:@selector(handleCancelBtnEvent) forControlEvents:UIControlEventTouchUpInside]; |
|
} |
|
return _cancelBtn; |
|
} |
|
|
|
- (QMUIButton *)closeBtn { |
|
if (!_closeBtn) { |
|
_closeBtn = [self generalBtn:@"挂断" imageName:@"video_icon_cancle"]; |
|
_closeBtn.spacingBetweenImageAndTitle = kTitleSpace; |
|
[_closeBtn addTarget:self action:@selector(handleCloseBtnEvent) forControlEvents:UIControlEventTouchUpInside]; |
|
} |
|
return _closeBtn; |
|
} |
|
|
|
- (QMUIButton *)refuseBtn { |
|
if (!_refuseBtn) { |
|
_refuseBtn = [self generalBtn:@"拒绝" imageName:@"video_icon_cancle"]; |
|
_refuseBtn.spacingBetweenImageAndTitle = kTitleSpace; |
|
[_refuseBtn addTarget:self action:@selector(handleRefuseBtnEvent) forControlEvents:UIControlEventTouchUpInside]; |
|
} |
|
return _refuseBtn; |
|
} |
|
|
|
/// 切换摄像头 |
|
- (QMUIButton *)swFBBtn { |
|
if (!_swFBBtn) { |
|
_swFBBtn = [[QMUIButton alloc] init]; |
|
[_swFBBtn setImage:ImageName_(@"video_icon_camera") forState:0]; |
|
[_swFBBtn addTarget:self action:@selector(handleSWFBBtnEvent) forControlEvents:UIControlEventTouchUpInside]; |
|
} |
|
return _swFBBtn; |
|
} |
|
|
|
- (QMUIButton *)exchangeBtn { |
|
if (!_exchangeBtn) { |
|
CGFloat width = kMicVideoW; |
|
CGFloat height = kMicVideoH; |
|
_exchangeBtn = [[QMUIButton alloc] init]; |
|
_exchangeBtn.frame = CGRectMake(ScreenWidth - width, KKStatusBarHeight,width,height); |
|
//_exchangeBtn.spacingBetweenImageAndTitle = 10; |
|
[_exchangeBtn addTarget:self action:@selector(exchangeView) forControlEvents:UIControlEventTouchUpInside]; |
|
} |
|
return _exchangeBtn; |
|
} |
|
|
|
- (UILabel *)tipsLabel |
|
{ |
|
if (!_tipsLabel) { |
|
_tipsLabel = [[UILabel alloc] init]; |
|
_tipsLabel.font = [UIFont systemFontOfSize:14];//MSmallFont(14); |
|
_tipsLabel.textAlignment = NSTextAlignmentCenter; |
|
_tipsLabel.textColor = UIColorWhite; |
|
} |
|
return _tipsLabel; |
|
} |
|
|
|
- (MZTimerLabel *)timeLabel |
|
{ |
|
if (!_timeLabel) { |
|
_timeLabel = [[MZTimerLabel alloc] init]; |
|
_timeLabel.font = FontBold_(18);//MSmallFont(22); |
|
_timeLabel.textAlignment = NSTextAlignmentCenter; |
|
_timeLabel.textColor = UIColor.whiteColor; |
|
_timeLabel.timeFormat = @"mm:ss"; |
|
|
|
} |
|
return _timeLabel; |
|
} |
|
|
|
- (QMUIButton *)swSilenceBtn { |
|
if (!_swSilenceBtn) { |
|
_swSilenceBtn = [self generalBtn:@"麦克风已开" imageName:@"video_icon_muteon"]; |
|
_swSilenceBtn.spacingBetweenImageAndTitle = kTitleSpace; |
|
[_swSilenceBtn setImage:[UIImage imageNamed:@"video_icon_muteoff"] forState:UIControlStateSelected]; |
|
[_swSilenceBtn setTitle:@"麦克风已关" forState:UIControlStateSelected]; |
|
[_swSilenceBtn addTarget:self action:@selector(handleSWSilenceBtnEvent:) forControlEvents:UIControlEventTouchUpInside]; |
|
} |
|
return _swSilenceBtn; |
|
} |
|
|
|
- (QMUIButton *)swSXTBtn { |
|
if (!_swSXTBtn) { |
|
_swSXTBtn = [self generalBtn:@"摄像头已开" imageName:@"video_icon_ cameraono"]; |
|
_swSXTBtn.spacingBetweenImageAndTitle = kTitleSpace; |
|
[_swSXTBtn setImage:[UIImage imageNamed:@"video_icon_ cameraoff"] forState:UIControlStateSelected]; |
|
[_swSXTBtn setTitle:@"摄像头已关" forState:UIControlStateSelected]; |
|
//[_swSXTBtn addTarget:self action:@selector(handleSWSilenceBtnEvent:) forControlEvents:UIControlEventTouchUpInside]; |
|
} |
|
return _swSXTBtn; |
|
} |
|
|
|
//- (QMUIButton *)swSpeakerBtn { |
|
// if (!_swSpeakerBtn) { |
|
// _swSpeakerBtn = [self generalBtn:@"免提" imageName:@"video_icon_speakeron"]; |
|
// _swSilenceBtn.spacingBetweenImageAndTitle = kTitleSpace; |
|
// [_swSpeakerBtn setImage:[UIImage imageNamed:@"video_icon_speaker"] forState:UIControlStateSelected]; |
|
// [_swSpeakerBtn addTarget:self action:@selector(handleSWSpeakerBtnEvent:) forControlEvents:UIControlEventTouchUpInside]; |
|
// } |
|
// return _swSpeakerBtn; |
|
//} |
|
|
|
- (QMUIButton *)generalBtn:(NSString *)title imageName:(NSString *)imageName { |
|
QMUIButton *button = [[QMUIButton alloc] qmui_initWithImage:[UIImage imageNamed:imageName] title:title]; |
|
button.size = CGSizeMake(64, 64); |
|
button.titleLabel.font = Font_(14); |
|
button.imagePosition = QMUIButtonImagePositionTop; |
|
button.spacingBetweenImageAndTitle = kTitleSpace; |
|
[button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; |
|
[button sizeToFit]; |
|
return button; |
|
} |
|
|
|
|
|
//================================================================================================= |
|
|
|
-(void)uploadCallTime:(NSString *)callTime { |
|
|
|
if(callTime && callTime.length == 8){ |
|
|
|
NSLog(@"upload call time = %@", callTime); |
|
|
|
NSArray *hhmmss = [callTime componentsSeparatedByString:@":"]; |
|
|
|
if (hhmmss && hhmmss.count == 3) { |
|
|
|
int hh = [[NSString stringWithFormat:@"%@", hhmmss[0]] intValue]; |
|
int mm = [[NSString stringWithFormat:@"%@", hhmmss[1]] intValue]; |
|
int ss = [[NSString stringWithFormat:@"%@", hhmmss[2]] intValue]; |
|
|
|
int total = hh*60*60 + mm*60 + ss; |
|
|
|
//MARK:上传视频时间 |
|
|
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary]; |
|
|
|
[dic setValue:@(total) forKey:@"duration"]; |
|
[dic setValue:@(0) forKey:@"wait_duration"];//wait_duration |
|
[dic setValue:@(0) forKey:@"distinguishability_width"]; |
|
[dic setValue:@(0) forKey:@"distinguishability_heiger"]; |
|
[dic setValue:self.videoId forKey:@"video_id"]; |
|
|
|
[UserDefaults setValue:[NSString stringWithFormat:@"%@&%@&%@&%@&%@",@(total),self.videoId,@(0),@(0),@(0)] forKey:VideoTimeAndIDAndWHRecordKey]; |
|
|
|
[cUser postVideoCallTimeParame:[dic copy] deviceModel:self.device success:^(id responseObject) { |
|
xLog(@"上传视频时间成功"); |
|
//MARK: 上传完视频时间后删除存储的 Key |
|
[UserDefaults removeObjectForKey:VideoTimeAndIDAndWHRecordKey]; |
|
|
|
} failure:^{ |
|
xLog(@"上传视频时间失败,重试一次"); |
|
}]; |
|
} |
|
} |
|
} |
|
|
|
|
|
@end
|
|
|