LivePrepareViewController.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // LivePrepareViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/30.
  6. //
  7. #import "LivePrepareViewController.h"
  8. #import "LivePreviewBodyView.h"
  9. #import <RongRTCLib/RongRTCLib.h>
  10. #import "KSEnterLiveroomManager.h"
  11. #import <RongFaceBeautifier/RongFaceBeautifier.h>
  12. @interface LivePrepareViewController ()
  13. @property (nonatomic, strong) LivePreviewBodyView *bodyView;
  14. // 音频配置
  15. @property(strong, nonatomic) RCRTCEngine *engine;
  16. @end
  17. @implementation LivePrepareViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. self.ks_prefersNavigationBarHidden = YES;
  22. [self configUI];
  23. [self configEngine];
  24. }
  25. - (void)configUI {
  26. self.bodyView = [LivePreviewBodyView shareInstance];
  27. [self.view addSubview:self.bodyView];
  28. [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.right.bottom.top.mas_equalTo(self.view);
  30. }];
  31. MJWeakSelf;
  32. [self.bodyView previewOperationCallback:^(PREVIEWLIVEACTION action) {
  33. [weakSelf previewOperationAction:action];
  34. }];
  35. }
  36. - (void)configEngine {
  37. self.engine = [RCRTCEngine sharedInstance];
  38. RCRTCVideoView *videoView = [[RCRTCVideoView alloc] init];
  39. videoView.fillMode = RCRTCVideoFillModeAspectFill;
  40. videoView.frameAnimated = NO;
  41. [self.bodyView.videoView addSubview:videoView];
  42. [videoView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.top.bottom.right.mas_equalTo(self.bodyView.videoView);
  44. }];
  45. [self.engine.defaultVideoStream setVideoView:videoView];
  46. [self.engine.defaultVideoStream startCapture];
  47. }
  48. - (void)previewOperationAction:(PREVIEWLIVEACTION)action {
  49. switch (action) {
  50. case PREVIEWLIVEACTION_BACK: // 返回
  51. {
  52. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  53. }
  54. break;
  55. case PREVIEWLIVEACTION_SWITCH: // 切换
  56. {
  57. [[RCRTCEngine sharedInstance].defaultVideoStream switchCamera];
  58. }
  59. break;
  60. case PREVIEWLIVEACTION_BEAUTY: // 美颜
  61. {
  62. [self displayBeautyView];
  63. }
  64. break;
  65. case PREVIEWLIVEACTION_SHARE: // 分享
  66. {
  67. }
  68. break;
  69. case PREVIEWLIVEACTION_OPEN: // 进入直播间
  70. {
  71. [self joinLiveRoom];
  72. }
  73. break;
  74. default:
  75. break;
  76. }
  77. }
  78. - (void)displayBeautyView {
  79. [self configSettingBeauty:YES white:8 smoothLevel:5 ruddyLevel:8 brightLevel:7 filter:RCRTCBeautyFilterEsthetic filterLevel:80];
  80. }
  81. - (void)configSettingBeauty:(BOOL)isOn white:(NSInteger)whitenessLevel smoothLevel:(NSInteger)smoothLevel ruddyLevel:(NSInteger)ruddyLevel brightLevel:(NSInteger)brightLevel filter:(RCRTCBeautyFilter)filter filterLevel:(int)filterLevel {
  82. if (isOn) {
  83. // 获取当前美颜参数
  84. RCRTCBeautyOption *option = [[RCRTCBeautyEngine sharedInstance] getCurrentBeautyOption];
  85. // 修改参数
  86. option.whitenessLevel = whitenessLevel;
  87. option.smoothLevel = smoothLevel;
  88. option.ruddyLevel = ruddyLevel;
  89. option.brightLevel = brightLevel;
  90. // 设置美颜
  91. [[RCRTCBeautyEngine sharedInstance] setBeautyOption:YES option:option];
  92. // 设置滤镜
  93. [[RCRTCBeautyEngine sharedInstance] setBeautyFilter:filter];
  94. // 设置滤镜强度
  95. [[RCRTCBeautyEngine sharedInstance] setFilterIntensity:filterLevel];
  96. }
  97. else {
  98. [[RCRTCBeautyEngine sharedInstance] reset];
  99. }
  100. }
  101. - (void)joinLiveRoom {
  102. [self showhud];
  103. MJWeakSelf;
  104. [KSEnterLiveroomManager joinLiveWithRoomId:self.roomId inController:(CustomNavViewController *)self.navigationController callback:^{
  105. [weakSelf removehub];
  106. }];
  107. }
  108. /*
  109. #pragma mark - Navigation
  110. // In a storyboard-based application, you will often want to do a little preparation before navigation
  111. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  112. // Get the new view controller using [segue destinationViewController].
  113. // Pass the selected object to the new view controller.
  114. }
  115. */
  116. @end