YOUPAIBBBaseVideoCallVC.m 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. //
  2. // YOUPAIBBBaseVideoCallVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2021/10/28.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIBBBaseVideoCallVC.h"
  9. #import "FUOpenGLView.h"
  10. #import "FUCamera.h"
  11. #import "PFAPIDemoBar.h"
  12. #import "PFDateHandle.h"
  13. #import <PixelFree/SMPixelFree.h>
  14. //#import "YOUPAIAGVideoProcessing.h"
  15. #import "AppDelegate.h"
  16. #import "YOUPAIBBCustomSystomNotification.h"
  17. @interface YOUPAIBBBaseVideoCallVC ()<FUCameraDelegate,PFAPIDemoBarDelegate>
  18. @property (assign,nonatomic) CGPoint youpaipstartPoint; //用来做清屏
  19. @property (nonatomic, strong) FUCamera *youpaipmCamera; //Faceunity Camera
  20. @property(nonatomic,assign)BOOL youpaipisRecordScreen;
  21. @property(nonatomic,strong)UIView *youpaiprecoderHideView;
  22. @property (nonatomic, assign) BOOL youpaipisHangupCallVideo; /// 是否手动挂断
  23. @property(nonatomic,strong)UIImageView *timeLogo;
  24. @property(nonatomic,strong)UIButton *closeBtn;
  25. @property(nonatomic, strong) PFAPIDemoBar *beautyEditView;
  26. @property (nonatomic, strong) NSUserDefaults *def;
  27. @property (nonatomic,strong) SMPixelFree *mPixelFree;
  28. @property (nonatomic,assign)BOOL clickCompare;
  29. @end
  30. @implementation YOUPAIBBBaseVideoCallVC
  31. //@synthesize consumer;
  32. -(BOOL)prefersStatusBarHidden
  33. {
  34. return YES;
  35. }
  36. - (FUCamera *)youpaipmCamera {
  37. if (!_youpaipmCamera) {
  38. _youpaipmCamera = [[FUCamera alloc] init];
  39. _youpaipmCamera.delegate = self;
  40. }
  41. return _youpaipmCamera;
  42. }
  43. - (void)dealloc{
  44. NSLog(@"dealloc basevideo");
  45. [[NSNotificationCenter defaultCenter] removeObserver:self];
  46. [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
  47. }
  48. - (void)viewWillAppear:(BOOL)animated{
  49. [super viewWillAppear:animated];
  50. self.navigationController.navigationBarHidden = YES;
  51. [LCSaveData saveIsVideo:YES];
  52. [self.youpaipmCamera startCapture];
  53. // [IQKeyboardManager sharedManager].enable = NO;
  54. }
  55. - (void)viewDidAppear:(BOOL)animated{
  56. [super viewDidAppear:animated];
  57. }
  58. - (void)viewWillDisappear:(BOOL)animated{
  59. [super viewWillDisappear:animated];
  60. [self.youpaipplayer stop];
  61. //add by leo 此处会导致vc无法释放
  62. self.youpaipplayer =nil;
  63. //add by leo 异常退出/被踢 显示处于视频中
  64. [LCSaveData saveIsVideo:NO];
  65. self.navigationController.navigationBarHidden = NO;
  66. // [IQKeyboardManager sharedManager].enable = YES;
  67. }
  68. - (void)viewDidLoad{
  69. [super viewDidLoad];
  70. self.sx_disableInteractivePop = YES;
  71. self.def = [NSUserDefaults standardUserDefaults];
  72. [self initPixelFree];
  73. [self setDefaultParam];
  74. NSString* path = [[NSBundle mainBundle] pathForResource:@"sound"ofType:@"bundle"];
  75. NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/call_bg.mp3",path]];
  76. self.youpaipplayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
  77. [self.youpaipplayer prepareToPlay];
  78. self.youpaipplayer.numberOfLoops = -1;
  79. [self.youpaipplayer play];
  80. [self youpaifinitView];
  81. [self youpaifinitAgora];
  82. NSString* str=[AgoraRtcEngineKit getSdkVersion];
  83. //设置默认曝光度
  84. [self.youpaipmCamera setExposureValue:0];
  85. [self.youpaipmCamera startCapture];
  86. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifwillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
  87. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifwillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
  88. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifdidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
  89. //挂断视频,接听通知
  90. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifhangupCallVideoNotification) name:@"HangupCallVideo" object:nil];
  91. }
  92. #pragma mark 澜极美颜--start
  93. -(PFAPIDemoBar *)beautyEditView {
  94. if (!_beautyEditView) {
  95. _beautyEditView = [[PFAPIDemoBar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 280, self.view.frame.size.width, 280)];
  96. _beautyEditView.mDelegate = self;
  97. }
  98. return _beautyEditView ;
  99. }
  100. -(void)comparisonButtonDidClick:(BOOL)state{
  101. self.clickCompare = state;
  102. }
  103. -(void)writeData:(NSData *)data fileName:(NSString *)fileName{
  104. NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  105. NSString *documentDirectory = [documentDirectories objectAtIndex:0];
  106. // 获取目标文件的完整路径
  107. NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
  108. // [[NSFileManager defaultManager] fileExistsAtPath:filePath];
  109. // 创建文件并覆盖写入数据
  110. BOOL success = [[NSFileManager defaultManager] createFileAtPath:filePath
  111. contents:data
  112. attributes:nil];
  113. if (success) {
  114. NSLog(@"数据写入成功");
  115. } else {
  116. NSLog(@"数据写入失败");
  117. }
  118. }
  119. -(NSData *)readDatafileName:(NSString *)fileName{
  120. NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  121. NSString *documentDirectory = [documentDirectories objectAtIndex:0];
  122. // 获取目标文件的完整路径
  123. NSString *filePath = [documentDirectory stringByAppendingPathComponent:fileName];
  124. NSData *data = [NSData dataWithContentsOfFile:filePath];
  125. return data;
  126. }
  127. -(void)initPixelFree{
  128. NSString *face_FiltePath = [[NSBundle mainBundle] pathForResource:@"filter_model.bundle" ofType:nil];
  129. NSString *authFile = [[NSBundle mainBundle] pathForResource:@"pixelfreeAuth.lic" ofType:nil];
  130. self.mPixelFree = [[SMPixelFree alloc] initWithProcessContext:nil srcFilterPath:face_FiltePath authFile:authFile];
  131. [self.view addSubview:self.beautyEditView];
  132. self.beautyEditView.hidden = YES;
  133. }
  134. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  135. self.beautyEditView.hidden = YES;
  136. [self.view endEditing:YES];
  137. }
  138. -(void)setDefaultParam{
  139. NSArray<PFBeautyParam *>* defaultData = [PFDateHandle setupShapData];
  140. NSArray<PFBeautyParam *>* defaultSkinData = [PFDateHandle setupSkinData];
  141. NSArray<PFBeautyParam *>* defaultfiltersData = [PFDateHandle setupFilterData];
  142. NSArray<PFBeautyParam *>* defaultfaceData = [PFDateHandle setupFaceType];
  143. // 读本地缓存
  144. NSData *data = [self readDatafileName:@"shapeParamsData"];
  145. if (data) {
  146. defaultData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  147. }
  148. data = [self readDatafileName:@"skinParamsData"];
  149. if (data) {
  150. defaultSkinData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  151. }
  152. data = [self readDatafileName:@"filtersParamsData"];
  153. if (data) {
  154. defaultfiltersData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  155. }
  156. data = [self readDatafileName:@"oneKeyParamsData"];
  157. if (data) {
  158. defaultfaceData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  159. }
  160. // 更新 UI
  161. self.beautyEditView.shapeParams = defaultData;
  162. self.beautyEditView.skinParams = defaultSkinData;
  163. self.beautyEditView.filtersParams = defaultfiltersData;
  164. self.beautyEditView.faceTypeParams = defaultfaceData;
  165. NSUserDefaults*userDefaults = [NSUserDefaults standardUserDefaults];
  166. int oneKeyType = (int)[userDefaults integerForKey:@"oneKeyType"];
  167. int filtersIndex = (int)[userDefaults integerForKey:@"filtersUseIndex"];
  168. self.beautyEditView.oneKeyType = oneKeyType;
  169. self.beautyEditView.filterIndex = filtersIndex;
  170. [self.beautyEditView updateDemoBar];
  171. // 更新 SDK 设置
  172. for (PFBeautyParam *param in defaultData) {
  173. [self filterValueChange:param];
  174. }
  175. for (PFBeautyParam *param in defaultSkinData) {
  176. [self filterValueChange:param];
  177. }
  178. PFBeautyParam *param = defaultfaceData[oneKeyType];
  179. [self filterValueChange:param];
  180. param = defaultfiltersData[filtersIndex];
  181. [self filterValueChange:param];
  182. }
  183. -(void)filterValueChange:(PFBeautyParam *)param{
  184. CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
  185. float value = param.mValue;
  186. if(param.type == FUDataTypeBeautify){
  187. if ([param.mParam isEqualToString:@"face_EyeStrength"]) {
  188. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_EyeStrength value:&value];
  189. }
  190. if ([param.mParam isEqualToString:@"face_thinning"]) {
  191. float aa = param.mValue;
  192. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_thinning value:&value];
  193. }
  194. if ([param.mParam isEqualToString:@"face_narrow"]) {
  195. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_narrow value:&value];
  196. }
  197. if ([param.mParam isEqualToString:@"face_chin"]) {
  198. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_chin value:&value];
  199. }
  200. if ([param.mParam isEqualToString:@"face_V"]) {
  201. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_V value:&value];
  202. }
  203. if ([param.mParam isEqualToString:@"face_small"]) {
  204. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_small value:&value];
  205. }
  206. if ([param.mParam isEqualToString:@"face_nose"]) {
  207. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_nose value:&value];
  208. }
  209. if ([param.mParam isEqualToString:@"face_forehead"]) {
  210. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_forehead value:&value];
  211. }
  212. if ([param.mParam isEqualToString:@"face_mouth"]) {
  213. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_mouth value:&value];
  214. }
  215. if ([param.mParam isEqualToString:@"face_philtrum"]) {
  216. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_philtrum value:&value];
  217. }
  218. if ([param.mParam isEqualToString:@"face_long_nose"]) {
  219. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_long_nose value:&value];
  220. }
  221. if ([param.mParam isEqualToString:@"face_eye_space"]) {
  222. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_space value:&value];
  223. }
  224. if ([param.mParam isEqualToString:@"face_smile"]) {
  225. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_smile value:&value];
  226. }
  227. if ([param.mParam isEqualToString:@"face_eye_rotate"]) {
  228. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_eye_rotate value:&value];
  229. }
  230. if ([param.mParam isEqualToString:@"face_canthus"]) {
  231. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFace_canthus value:&value];
  232. }
  233. if ([param.mParam isEqualToString:@"runddy"]) {
  234. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceRuddyStrength value:&value];
  235. }
  236. if ([param.mParam isEqualToString:@"writen"]) {
  237. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceWhitenStrength value:&value];
  238. }
  239. if ([param.mParam isEqualToString:@"blur"]) {
  240. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceBlurStrength value:&value];
  241. }
  242. if ([param.mParam isEqualToString:@"sharpen"]) {
  243. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceSharpenStrength value:&value];
  244. }
  245. if ([param.mParam isEqualToString:@"newWhitenStrength"]) {
  246. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceM_newWhitenStrength value:&value];
  247. }
  248. if ([param.mParam isEqualToString:@"qualityStrength"]) {
  249. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeFaceH_qualityStrength value:&value];
  250. }
  251. }
  252. if (param.type == FUDataTypeFilter) {
  253. const char *aaa = [param.mParam UTF8String];
  254. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterName value:(void *)aaa];
  255. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterStrength value:&value];
  256. }
  257. if (param.type == FUDataTypeStickers) {
  258. if([param.mParam isEqualToString:@"origin"]){
  259. [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:NULL];
  260. } else{
  261. // NSString *path = [[NSBundle mainBundle] pathForResource:@"Stickers" ofType:nil];
  262. // NSString *currentFolder = [path stringByAppendingPathComponent:param.mParam];
  263. // const char *aaa = [currentFolder UTF8String];
  264. // [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)aaa];
  265. NSString *name = [NSString stringWithFormat:@"%@.bundle",param.mParam];
  266. NSString *paths = [[NSBundle mainBundle] pathForResource:name ofType:nil];
  267. [self.mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterSticker2DFilter value:(void *)[paths UTF8String]];
  268. }
  269. }
  270. if (param.type == FUDataTypeOneKey) {
  271. if ([param.mTitle isEqualToString:@"origin"]) {
  272. int value = PFBeautyTypeOneKeyNormal;
  273. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  274. }
  275. if ([param.mTitle isEqualToString:@"自然"]) {
  276. int value = PFBeautyTypeOneKeyNatural;
  277. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  278. }
  279. if ([param.mTitle isEqualToString:@"可爱"]) {
  280. int value = PFBeautyTypeOneKeyCute;
  281. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  282. }
  283. if ([param.mTitle isEqualToString:@"女神"]) {
  284. int value = PFBeautyTypeOneKeyGoddess;
  285. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  286. }
  287. if ([param.mTitle isEqualToString:@"白净"]) {
  288. int value = PFBeautyTypeOneKeyFair;
  289. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  290. }
  291. }
  292. }
  293. -(void)bottomDidChange:(int)index{
  294. if (index != 0 && _beautyEditView.oneKeyType != PFBeautyTypeOneKeyNormal) {
  295. int value = PFBeautyTypeOneKeyNormal;
  296. [_mPixelFree pixelFreeSetBeautyFiterParam:PFBeautyFiterTypeOneKey value:&value];
  297. [self showDelayedAlert];
  298. _beautyEditView.oneKeyType = PFBeautyTypeOneKeyNormal;
  299. }
  300. }
  301. - (void)showDelayedAlert {
  302. // 创建 UIAlertController
  303. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"一键美颜已关闭" preferredStyle:UIAlertControllerStyleAlert];
  304. dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
  305. dispatch_after(delay, dispatch_get_main_queue(), ^{
  306. [alertController dismissViewControllerAnimated:YES completion:nil];
  307. });
  308. [self presentViewController:alertController animated:YES completion:nil];
  309. }
  310. #pragma mark 澜极美颜--end
  311. - (void)youpaifhangupCallVideoNotification{
  312. [self youpaifvideoEnd:BBCustomSystomNotificationTypeWithHangupCallVideo];
  313. [ZCHUDHelper showTitle:@"对方已挂断"];
  314. }
  315. - (void)youpaifinitView{
  316. self.youpaipremoteVideo = [[UIView alloc]initWithFrame:CGRectMake(0,0,KScreenWidth,KScreenHeight)];
  317. self.youpaipremoteVideo.backgroundColor = [UIColor blackColor];
  318. [self.view addSubview:self.youpaipremoteVideo];
  319. self.youpaiprecoderHideView = [[UIView alloc]init];
  320. [self.youpaiprecoderHideView setBackgroundColor:[UIColor whiteColor]];
  321. [self.youpaiprecoderHideView setHidden:YES];
  322. [self.view addSubview:self.youpaiprecoderHideView];
  323. UIView* msgCoverView = [[UIView alloc]initWithFrame:CGRectMake(-KScreenWidth, 0, KScreenWidth*2, KScreenHeight)];
  324. msgCoverView.backgroundColor = [UIColor clearColor];
  325. UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifmsgViewPanHandel:)];
  326. [msgCoverView addGestureRecognizer:pan];
  327. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifdoubleTapHandel:)];
  328. doubleTap.numberOfTapsRequired = 2;
  329. [msgCoverView addGestureRecognizer:doubleTap];
  330. self.youpaipmsgCoverView = msgCoverView;
  331. [self.view addSubview:msgCoverView];
  332. UIView* interView = [[UIView alloc]initWithFrame:CGRectMake(KScreenWidth, 0, KScreenWidth, KScreenHeight)];
  333. interView.backgroundColor = [UIColor clearColor];
  334. self.youpaipinterView = interView;
  335. UITapGestureRecognizer* interTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifinterHandel:)];
  336. [self.youpaipinterView addGestureRecognizer:interTap];
  337. [msgCoverView addSubview:interView];
  338. //设置顶部按钮
  339. UIButton* closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(16,StatusBarHeight+4, 30, 30)];
  340. [closeBtn setImage:[UIImage imageNamed:@"vqu_images_video_end"] forState:(UIControlStateNormal)];
  341. [closeBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  342. [closeBtn setEnlargeEdge:10];
  343. [self.view addSubview:closeBtn];
  344. self.closeBtn = closeBtn;
  345. self.closeBtn.hidden = YES;
  346. UIView *timeBgv = [[UIView alloc] init];
  347. timeBgv.layer.cornerRadius = 12.0f;
  348. timeBgv.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3f];
  349. [self.view addSubview:timeBgv];
  350. [timeBgv mas_makeConstraints:^(MASConstraintMaker *make) {
  351. make.left.offset(54.0f);
  352. make.top.offset(StatusBarHeight+7);
  353. make.height.offset(24.0f);
  354. }];
  355. UIImageView* timeLogo = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 30, 30)];
  356. timeLogo.contentMode = UIViewContentModeScaleAspectFill;
  357. timeLogo.image = [UIImage imageNamed:@"vqu_images_video_time"];
  358. [timeBgv addSubview:timeLogo];
  359. [timeLogo mas_makeConstraints:^(MASConstraintMaker *make) {
  360. make.left.offset(0);
  361. make.centerY.equalTo(timeBgv);
  362. make.size.mas_offset(CGSizeMake(30, 30));
  363. }];
  364. self.timeLogo = timeLogo;
  365. self.timeLogo.hidden = YES;
  366. UILabel* timeLabel = [self youpaifcreateLabelWithFrame:CGRectMake(44,0,100,30) text:@"00:00"];
  367. timeLabel.textColor = HexColorFromRGB(0xFFFFFF);
  368. self.youpaiptimeLabel = timeLabel;
  369. [timeBgv addSubview:timeLabel];
  370. [self youpaiftimeStart];
  371. [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  372. make.top.bottom.offset(0.0f);
  373. make.right.offset(-8.0f);
  374. make.left.equalTo(timeLogo.mas_right);
  375. }];
  376. self.youpaiptimeLabel.hidden = YES;
  377. self.youpaiplocalVideo = [[UIView alloc]initWithFrame:CGRectMake(KScreenWidth-106,StatusBarHeight+4, 90,120)];
  378. self.youpaiplocalVideo.backgroundColor = [UIColor blackColor];
  379. self.youpaiplocalVideo.layer.cornerRadius = 5.0;
  380. self.youpaiplocalVideo.layer.masksToBounds = YES;
  381. [self.view addSubview:self.youpaiplocalVideo];
  382. UITapGestureRecognizer* localTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(youpaifloaclVideoHandel:)];
  383. [self.youpaiplocalVideo addGestureRecognizer:localTap];
  384. //摄像
  385. UIButton* cameraBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.youpaiplocalVideo.center.x-16,StatusBarHeight+4+120+8.5,32,25)];
  386. [cameraBtn setImage:[UIImage imageNamed:@"vqu_images_video_off"] forState:(UIControlStateNormal)];
  387. [cameraBtn addTarget:self action:@selector(youpaifcameraBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
  388. [self.view addSubview:cameraBtn];
  389. cameraBtn.selected = YES;
  390. self.youpaipcameraBtn = cameraBtn;
  391. self.youpaipcameraBtn.hidden = YES;
  392. self.youpaipcameraBtn.centerX = self.youpaiplocalVideo.center.x;
  393. }
  394. - (UILabel*)youpaifcreateLabelWithFrame:(CGRect)frame text:(NSString*)contentText{
  395. UILabel* lab = [[UILabel alloc]initWithFrame:frame];
  396. lab.textColor = [UIColor whiteColor];
  397. lab.font = [UIFont systemFontOfSize:11];
  398. lab.textAlignment = NSTextAlignmentLeft;
  399. lab.text = contentText;
  400. return lab;
  401. }
  402. #pragma mark - Agora
  403. - (void)youpaifinitAgora{
  404. self.agoraKit = [AgoraRtcEngineKit sharedEngineWithAppId:AgoraID delegate:self];
  405. NSLog(@"version is %@",[AgoraRtcEngineKit getSdkVersion]);
  406. AgoraVideoEncoderConfiguration *configuration = [[AgoraVideoEncoderConfiguration alloc] initWithSize:AgoraVideoDimension1280x720 frameRate:AgoraVideoFrameRateFps24 bitrate:AgoraVideoBitrateCompatible orientationMode:AgoraVideoOutputOrientationModeAdaptative mirrorMode:AgoraVideoMirrorModeAuto];
  407. [self.agoraKit setVideoEncoderConfiguration:configuration];
  408. [self.agoraKit enableVideo];
  409. [self.agoraKit setExternalVideoSource:YES useTexture:YES sourceType:AgoraExternalVideoSourceTypeVideoFrame]; //只允许外部源
  410. [self.agoraKit setChannelProfile:AgoraChannelProfileLiveBroadcasting];
  411. [self.agoraKit setClientRole:AgoraClientRoleBroadcaster];
  412. //add by leo 修复视频镜像问题
  413. [self.agoraKit setLocalVideoMirrorMode:AgoraVideoMirrorModeDisabled];
  414. [self.agoraKit enableWebSdkInteroperability:YES];
  415. AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  416. videoCanvas.uid = 0;
  417. videoCanvas.view = self.youpaiplocalVideo;
  418. videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  419. self.localCanvas = videoCanvas;
  420. [self.agoraKit setupLocalVideo:videoCanvas];
  421. }
  422. #pragma mark - AgoraRtcEngineDelegate
  423. //收到对方的视频
  424. - (void)rtcEngine:(AgoraRtcEngineKit *)engine firstRemoteVideoDecodedOfUid:(NSUInteger)uid size: (CGSize)size elapsed:(NSInteger)elapsed {
  425. self.youpaipremoteVideo.hidden = NO;
  426. self.youpaipcameraBtn.hidden = NO;
  427. self.youpaiptimeLabel.hidden = NO;
  428. self.closeBtn.hidden = NO;
  429. self.timeLogo.hidden = NO;
  430. AgoraRtcVideoCanvas *videoCanvas = [[AgoraRtcVideoCanvas alloc] init];
  431. videoCanvas.renderMode = AgoraVideoRenderModeHidden;
  432. self.remoteCanvas= videoCanvas;
  433. self.remoteCanvas.uid = uid;
  434. self.remoteCanvas.view = self.youpaipremoteVideo;
  435. int value =[self.agoraKit setupRemoteVideo:self.remoteCanvas];
  436. NSLog(@"%d",value);
  437. }
  438. - (void)rtcEngine:(AgoraRtcEngineKit *)engine
  439. didVideoMuted:(BOOL)muted byUid:(NSUInteger)uid{
  440. if (muted) {//对端关闭了视频
  441. self.localCanvas.view = self.youpaipremoteVideo;
  442. self.remoteCanvas.view = self.youpaiplocalVideo;
  443. [self.agoraKit setupLocalVideo:self.localCanvas];
  444. [self.agoraKit setupRemoteVideo:self.remoteCanvas];
  445. self.youpaiplocalVideo.hidden = YES;
  446. }else{
  447. self.localCanvas.view = self.youpaiplocalVideo;
  448. self.remoteCanvas.view = self.youpaipremoteVideo;
  449. [self.agoraKit setupLocalVideo:self.localCanvas];
  450. [self.agoraKit setupRemoteVideo:self.remoteCanvas];
  451. self.youpaiplocalVideo.hidden = NO;
  452. }
  453. }
  454. - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOfflineOfUid:(NSUInteger)uid reason:(AgoraUserOfflineReason)reason{
  455. if (!self.youpaipisHangupCallVideo) {
  456. [self youpaifvideoEnd:BBCustomSystomNotificationTypeWithWasInterruptedCallVideo];
  457. [ZCHUDHelper showTitle:[YOUPAIBBCustomSystomNotification youpaifnotificationTitleWithType:BBCustomSystomNotificationTypeWithWasInterruptedCallVideo]];
  458. }
  459. }
  460. - (void)rtcEngine:(AgoraRtcEngineKit *)engine didAudioRouteChanged:(AgoraAudioOutputRouting)routing{
  461. // [ZCHUDHelper showTitle:[NSString stringWithFormat:@"音频路由已切换%d",routing]];
  462. }
  463. //踢人 v1.1.1
  464. //- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine connectionChangedToState:(AgoraConnectionStateType)state reason:(AgoraConnectionChangedReason)reason
  465. //{
  466. // if(reason ==3)
  467. // {
  468. // NSLog(@"收到踢人消息");
  469. // // [self youpaifvideoEnd:5];
  470. // }
  471. //}
  472. #pragma mark - Agora Video Source Protocol
  473. - (BOOL)shouldInitialize {
  474. return YES;
  475. }
  476. - (void)shouldStart {
  477. [self.youpaipmCamera startCapture];
  478. }
  479. - (void)shouldStop {
  480. [self.youpaipmCamera stopCapture];
  481. }
  482. - (void)shouldDispose {
  483. }
  484. //
  485. //
  486. //- (AgoraVideoBufferType)bufferType {
  487. // return AgoraVideoBufferTypePixelBuffer;
  488. //}
  489. //- (AgoraVideoCaptureType)captureType{
  490. // return AgoraVideoCaptureTypeCamera;
  491. //}
  492. #pragma mark - FUCameraDelegate
  493. bool lzIsNeeded = YES;
  494. -(void)didOutputVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer {
  495. if (lzIsNeeded) {
  496. lzIsNeeded = !lzIsNeeded;
  497. return;
  498. }
  499. lzIsNeeded = !lzIsNeeded;
  500. // CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
  501. CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer) ;
  502. CVPixelBufferLockBaseAddress(pixelBuffer, 0);
  503. // CFAbsoluteTime startRenderTime = CFAbsoluteTimeGetCurrent();
  504. //render the items to pixelbuffer
  505. [_mPixelFree processWithBuffer:pixelBuffer rotationMode:PFRotationMode0];
  506. // CFAbsoluteTime renderTime = (CFAbsoluteTimeGetCurrent() - startRenderTime);
  507. //
  508. //
  509. // CFAbsoluteTime frameTime = (CFAbsoluteTimeGetCurrent() - startTime);
  510. //
  511. // int frameWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
  512. // int frameHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
  513. CGSize frameSize;
  514. if (CVPixelBufferGetPixelFormatType(pixelBuffer) == kCVPixelFormatType_32BGRA) {
  515. frameSize = CGSizeMake(CVPixelBufferGetBytesPerRow(pixelBuffer) / 4, CVPixelBufferGetHeight(pixelBuffer));
  516. }else{
  517. frameSize = CGSizeMake(CVPixelBufferGetWidth(pixelBuffer), CVPixelBufferGetHeight(pixelBuffer));
  518. }
  519. // push video frame to agora
  520. // [self.consumer consumePixelBuffer:pixelBuffer withTimestamp:CMSampleBufferGetPresentationTimeStamp(sampleBuffer) rotation:AgoraVideoRotationNone];
  521. CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
  522. }
  523. #pragma mark - WebSocketDelegate
  524. - (void)youpaifrequestSuccess{
  525. }
  526. - (void)youpaifresponseConnent{
  527. }
  528. - (void)youpaifresponseChoosing:(NSString*)tip{
  529. }
  530. //add by leo 剩余可通话时间
  531. - (void)youpaifcanCallTime:(NSString*)tip
  532. {
  533. }
  534. //v1.1.1断连重连
  535. - (void)youpaifvideoStart{
  536. [self.youpaipplayer stop];
  537. // self.videoModel.duration = [dict[@"duration"] integerValue];
  538. //是否主叫
  539. BOOL callfrom = [[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:self.youpaipvideoModel.youpaipfrom_uid];
  540. if (self.youpaipvideoModel.youpaipporn_check_v2.youpaipis_open&&(self.youpaipvideoModel.youpaipporn_check_v2.youpaipcheck_from_user||callfrom)) {
  541. NSLog(@"鉴黄已打开");
  542. [YOUPAIXLVideoShotTool sharedPusher].shotCycle = self.youpaipvideoModel.youpaipporn_check_v2.youpaipinterval_time;
  543. [YOUPAIXLVideoShotTool sharedPusher].periodArray = self.youpaipvideoModel.youpaipporn_check_v2.youpaipperiod_array;
  544. // [YOUPAIAGVideoProcessing registerVideoPreprocessing:self.agoraKit];
  545. //老版本
  546. /*
  547. [YOUPAIXLVideoShotTool sharedPusher].shotCycle = self.videoModel.porn_check.interval_time;
  548. [YOUPAIXLVideoShotTool sharedPusher].period = self.videoModel.porn_check.period;
  549. */
  550. [YOUPAIXLVideoShotTool sharedPusher].room_id = self.youpaipvideoModel.youpaiproom_id;
  551. [YOUPAIXLVideoShotTool sharedPusher].localVideo = self.youpaiplocalVideo;
  552. [YOUPAIXLVideoShotTool sharedPusher].remoteVideo = self.youpaipremoteVideo;
  553. [YOUPAIXLVideoShotTool sharedPusher].isPornCheckOpen = YES;
  554. if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:self.youpaipvideoModel.youpaipfrom_uid]) {//自己是被叫端
  555. [YOUPAIXLVideoShotTool sharedPusher].isFrom = YES;
  556. [YOUPAIXLVideoShotTool sharedPusher].uid = self.youpaipvideoModel.youpaipto_uid;
  557. }else{
  558. [YOUPAIXLVideoShotTool sharedPusher].isFrom = NO;
  559. [YOUPAIXLVideoShotTool sharedPusher].uid = self.youpaipvideoModel.youpaipfrom_uid;
  560. }
  561. [YOUPAIXLVideoShotTool start];
  562. }
  563. //加入声网频道
  564. //modify by leo fix bug object unrelease
  565. WeakSelf;
  566. [self.agoraKit joinChannelByToken:nil channelId:self.youpaipvideoModel.youpaiproom_id info:nil uid:[[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] joinSuccess:^(NSString *channel, NSUInteger uid, NSInteger elapsed) {
  567. if([weakSelf.agoraKit isSpeakerphoneEnabled]){
  568. [weakSelf.agoraKit setEnableSpeakerphone:YES];
  569. }
  570. // self.localVideo.hidden = YES;
  571. [UIApplication sharedApplication].idleTimerDisabled = YES;
  572. }];
  573. }
  574. //1主动取消 2。拒绝 3.超时 4.被叫者挂断 5.主叫者挂断 6.费用不足
  575. - (void)youpaifvideoEnd:(NSInteger)type{
  576. kAppDelegate.ksocketManager = nil;
  577. [LCSaveData saveIsVideo:NO];
  578. [[NSNotificationCenter defaultCenter] removeObserver:self];
  579. if (self.timer) {
  580. dispatch_source_cancel(self.timer);//删除GCD定时器
  581. self.timer = nil;
  582. }
  583. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  584. [self.youpaipmCamera stopCapture];
  585. dispatch_async(self.youpaipmCamera.videoCaptureQueue, ^{
  586. });
  587. [self.agoraKit setExternalVideoSource:YES useTexture:YES sourceType:AgoraExternalVideoSourceTypeVideoFrame]; //只允许外部源
  588. [self.agoraKit leaveChannel:nil];
  589. [AgoraRtcEngineKit destroy];
  590. if (type==11) {
  591. if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id isEqualToString:self.youpaipvideoModel.youpaipto_uid]){//自己是被叫端
  592. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  593. }];
  594. }else{//自己是主叫端
  595. [YOUPAIXLVideoShotTool stop];
  596. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  597. NSLog(@"1111111");
  598. }];
  599. }
  600. }
  601. if (type==4|| type==5 || type==6 || type==10) {//去往评价结束界面
  602. //add by leo 关闭上传截图 定时器
  603. [YOUPAIXLVideoShotTool stop];
  604. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  605. NSLog(@"12121212");
  606. }];
  607. }else{
  608. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  609. NSLog(@"2222222");
  610. }];
  611. }
  612. });
  613. }
  614. - (void)youpaifcloseBtnClick{
  615. //确定退出视频咨询
  616. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确定挂断视频通话?" preferredStyle:UIAlertControllerStyleAlert];
  617. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  618. }];
  619. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  620. self.youpaipisHangupCallVideo = YES;
  621. [self youpaifvideoEnd:4];
  622. [YOUPAIBBCustomSystomNotification youpaifcustomSystomNotificationWithModel:self.youpaipvideoModel type:BBCustomSystomNotificationTypeWithHangupCallVideo block:^(NSError * _Nonnull error) {
  623. }];
  624. [ZCHUDHelper showTitle:@"已挂断"];
  625. }];
  626. [alertController addAction:cancelAction];
  627. [alertController addAction:okAction];
  628. [self presentViewController:alertController animated:YES completion:nil];
  629. }
  630. #pragma mark - interActive
  631. - (void)youpaiftimeStart{
  632. //v1.1.1断连重连
  633. __block int timeout = self.youpaipvideoModel.youpaipduration;
  634. WeakSelf;
  635. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  636. dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  637. self.timer = timer;
  638. dispatch_source_set_timer(timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
  639. dispatch_source_set_event_handler(timer, ^{
  640. timeout++;
  641. dispatch_async(dispatch_get_main_queue(), ^{
  642. weakSelf.youpaiptimeLabel.text =[ZCUtils getMMSSFromSS:timeout];
  643. kAppDelegate.logCallTime = weakSelf.youpaiptimeLabel.text;
  644. });
  645. });
  646. dispatch_resume(timer);
  647. }
  648. - (void)youpaifinterHandel:(UITapGestureRecognizer*)interTap{
  649. if (interTap.state == UIGestureRecognizerStateEnded) {
  650. if (interTap.view == self.youpaipinterView) {
  651. dispatch_async(dispatch_get_main_queue(), ^{
  652. [self.view endEditing:YES];
  653. });
  654. }else{}
  655. }
  656. }
  657. - (void)youpaifdoubleTapHandel:(UITapGestureRecognizer*)tap{
  658. if (tap.state == UIGestureRecognizerStateEnded) {
  659. if (self.youpaipinterView.frame.origin.x == KScreenWidth) {
  660. [self youpaifmsgViewAnimWithX:0];
  661. }else{
  662. [self youpaifmsgViewAnimWithX:KScreenWidth];
  663. }
  664. }
  665. }
  666. - (void)youpaifmsgViewPanHandel:(UIPanGestureRecognizer*)panGesture{
  667. //移动两点之间的绝对距离
  668. dispatch_async(dispatch_get_main_queue(), ^{
  669. [self.view endEditing:YES];
  670. });
  671. CGPoint translation = [panGesture translationInView:self.youpaipinterView];
  672. if (self.youpaipinterView.frame.origin.x==0 && translation.x<0) {
  673. }else if(self.youpaipinterView.frame.origin.x==KScreenWidth && translation.x>0){
  674. }else {
  675. CGPoint endPosition;
  676. if (panGesture.state == UIGestureRecognizerStateBegan){
  677. self.youpaipstartPoint = [panGesture locationInView:self.youpaipinterView];
  678. }else if (panGesture.state == UIGestureRecognizerStateChanged){
  679. CGPoint origin = self.youpaipinterView.frame.origin;
  680. origin.x+=translation.x;
  681. if (origin.x<=0) {
  682. origin.x = 0;
  683. self.youpaipinterView.frame= CGRectMake(origin.x, 0, KScreenWidth, KScreenHeight);
  684. }else if(origin.x>=KScreenWidth){
  685. origin.x = KScreenWidth;
  686. self.youpaipinterView.frame= CGRectMake(origin.x, 0, KScreenWidth, KScreenHeight);
  687. }
  688. }else if (panGesture.state == UIGestureRecognizerStateEnded) {
  689. endPosition = [panGesture locationInView:self.youpaipinterView];
  690. if (endPosition.x-self.youpaipstartPoint.x>80) {//右移 小动画
  691. [self youpaifmsgViewAnimWithX:KScreenWidth];
  692. }else if(endPosition.x-self.youpaipstartPoint.x<-80){ //移
  693. [self youpaifmsgViewAnimWithX:0];
  694. }
  695. }
  696. }
  697. }
  698. - (void)youpaifmsgViewAnimWithX:(CGFloat)x{
  699. NSTimeInterval durtionTime = fabs(self.youpaipinterView.x-x)*0.5/KScreenWidth;
  700. [UIView animateWithDuration:durtionTime animations:^{
  701. self.youpaipinterView.frame = CGRectMake(x, 0, KScreenWidth, KScreenHeight);
  702. } completion:^(BOOL finished) {
  703. self.youpaipinterView.frame = CGRectMake(x, 0, KScreenWidth, KScreenHeight);
  704. }];
  705. }
  706. - (void)youpaifloaclVideoHandel:(UITapGestureRecognizer*)localTap{
  707. if (localTap.state == UIGestureRecognizerStateEnded) {
  708. if([self.remoteCanvas.view isEqual:self.youpaipremoteVideo]){
  709. self.remoteCanvas.view = self.youpaiplocalVideo;
  710. self.localCanvas.view = self.youpaipremoteVideo;
  711. [self.agoraKit setupLocalVideo:self.localCanvas];
  712. [self.agoraKit setupRemoteVideo:self.remoteCanvas];
  713. }else{
  714. self.remoteCanvas.view = self.youpaipremoteVideo;
  715. self.localCanvas.view = self.youpaiplocalVideo;
  716. [self.agoraKit setupLocalVideo:self.localCanvas];
  717. [self.agoraKit setupRemoteVideo:self.remoteCanvas];
  718. }
  719. }
  720. }
  721. #pragma mark - ButtonClick
  722. - (void)youpaifbeautyBtnClick{
  723. [self.view bringSubviewToFront:self.beautyEditView];
  724. self.beautyEditView.hidden = NO;
  725. }
  726. - (void)youpaifswitchBtnClick:(UIButton*)btn{
  727. [_youpaipmCamera changeCameraInputDeviceisFront:!_youpaipmCamera.isFrontCamera];
  728. [self.agoraKit switchCamera];
  729. }
  730. - (void)youpaifvoiceBtnClick:(UIButton*)btn{
  731. if (btn.selected == YES) {
  732. btn.selected = NO;
  733. [btn setImage:[UIImage imageNamed:@"vqu_images_video_sound_off"] forState:(UIControlStateNormal)];
  734. [self.agoraKit disableAudio];
  735. }else{
  736. btn.selected = YES;
  737. [btn setImage:[UIImage imageNamed:@"vqu_images_video_sound_on"] forState:(UIControlStateNormal)];
  738. [self.agoraKit enableAudio];
  739. }
  740. }
  741. - (void)youpaifcameraBtnClick:(UIButton*)btn{
  742. if (btn.selected == YES) {
  743. btn.selected = NO;
  744. self.localCanvas.view = self.youpaiplocalVideo;
  745. self.remoteCanvas.view = self.youpaipremoteVideo;
  746. [self.agoraKit setupLocalVideo:self.localCanvas];
  747. [self.agoraKit setupRemoteVideo:self.remoteCanvas];
  748. [btn setImage:[UIImage imageNamed:@"vqu_images_video_on"] forState:(UIControlStateNormal)];
  749. [self.agoraKit muteLocalVideoStream:YES];
  750. self.youpaiplocalVideo.hidden = YES;
  751. }else{
  752. btn.selected = YES;
  753. [btn setImage:[UIImage imageNamed:@"vqu_images_video_off"] forState:(UIControlStateNormal)];
  754. [self.agoraKit muteLocalVideoStream:NO];
  755. self.youpaiplocalVideo.hidden = NO;
  756. }
  757. }
  758. #pragma mark - 键盘交互事件
  759. - (void)youpaifwillResignActive {
  760. [_youpaipmCamera stopCapture];
  761. }
  762. - (void)youpaifwillEnterForeground {
  763. [_youpaipmCamera startCapture];
  764. if (self.youpaipvoiceBtn.selected == NO) {
  765. [self.agoraKit enableAudio];
  766. [self.agoraKit disableAudio];
  767. }else{
  768. [self.agoraKit disableAudio];
  769. [self.agoraKit enableAudio];
  770. }
  771. }
  772. - (void)youpaifdidBecomeActive {
  773. [_youpaipmCamera startCapture];
  774. }
  775. @end