ClassroomMainContainer.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // ClassroomMainContainer.m
  3. // StudentDaya
  4. //
  5. // Created by Kyle on 2020/6/12.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "ClassroomMainContainer.h"
  9. #import "RTCService.h"
  10. #import "LocalRenderManager.h"
  11. @interface ClassroomMainContainer ()
  12. @property (nonatomic, strong) UIView *tapGestureView;
  13. @property (nonatomic) CGRect currentVideoFrame;
  14. @property (nonatomic) CGRect originVideoFrame;
  15. @property (nonatomic, strong) UIImageView *tipsImage;
  16. @end
  17. @implementation ClassroomMainContainer
  18. - (instancetype)initWithFrame:(CGRect)frame {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. self.backgroundColor = [UIColor colorWithHexString:@"141414" alpha:1];
  22. [self addSubview:self.emptyView];
  23. [self addSubview:self.videoBackView];
  24. [self.videoBackView addSubview:self.videoView];
  25. self.originVideoFrame = self.videoBackView.frame;
  26. self.currentVideoFrame = self.originVideoFrame;
  27. [self.videoView addSubview:self.tipsImage];
  28. }
  29. return self;
  30. }
  31. - (void)didChangeRole:(Role)role {
  32. [self.emptyView changeRole:role];
  33. }
  34. - (void)containerViewRenderView:(RoomMember *)member {
  35. self.videoBackView.hidden = NO;
  36. self.videoView.hidden = NO;
  37. if([[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
  38. RoomMember *curMemeber =[ClassroomService sharedService].currentRoom.currentMember;
  39. [[RTCService sharedInstance] renderLocalVideoOnView:self.videoView cameraEnable:curMemeber.cameraEnable];
  40. [LocalRenderManager shareInstance].hadRenderMainView = YES;
  41. }else {
  42. [LocalRenderManager shareInstance].hadRenderMainView = NO;
  43. [[RTCService sharedInstance] exchangeRemoteUserAVStreamToNomalSteam:member.userId callback:^{
  44. [[RTCService sharedInstance] renderRemoteVideoOnView:self.videoView forUser:member.userId];
  45. }];
  46. }
  47. self.member = member;
  48. }
  49. - (void)cancelRenderView {
  50. [LocalRenderManager shareInstance].hadRenderMainView = NO;
  51. // 如何关闭了摄像头,可能导致videoView 遮挡控制事件
  52. [self updateVideoViewFrame:NO];
  53. self.videoBackView.hidden = YES;
  54. }
  55. - (void)setSubjectName:(NSString *)subjectName {
  56. _subjectName = subjectName;
  57. NSString *imgName = [self getGuideImage:subjectName];
  58. if (![NSString isEmptyString:imgName]) {
  59. self.tipsImage.hidden = NO;
  60. [self.tipsImage setImage:[UIImage imageNamed:imgName]];
  61. }
  62. else {
  63. self.tipsImage.hidden = YES;
  64. }
  65. }
  66. #pragma mark - private method
  67. - (void)updateVideoViewFrame:(BOOL)isFull {
  68. self.currentVideoFrame = self.frame;
  69. if(isFull) {
  70. [self.superview addSubview:self.videoBackView];
  71. [self.superview bringSubviewToFront:self.videoBackView];
  72. CGFloat width = 0.0f;
  73. CGFloat height = 0.0f;
  74. height = kScreen_Width / 4.0f * 3;
  75. if (height > kScreenHeight) {
  76. height = kScreenHeight;
  77. }
  78. width = height / 3.0f * 4;
  79. self.videoView.frame = CGRectMake((kScreenWidth - width) / 2.0f, 0, width, height);
  80. }else {
  81. [self.videoBackView removeFromSuperview];
  82. [self addSubview:self.videoBackView];
  83. self.currentVideoFrame = self.originVideoFrame;
  84. self.videoView.frame = CGRectMake(0, 0, CGRectGetWidth(self.currentVideoFrame), CGRectGetHeight(self.currentVideoFrame));
  85. }
  86. self.videoBackView.frame = self.currentVideoFrame;
  87. }
  88. #pragma mark - getter
  89. - (UIView *)videoBackView {
  90. if (!_videoBackView) {
  91. CGFloat width = 0.0f;
  92. CGFloat height = 0.0f;
  93. height = kScreenHeight - 20;
  94. width = height / 3.0f * 4;
  95. if (width > kScreenWidth - 180) {
  96. width = kScreenWidth - 180;
  97. height = width / 4.0f * 3;
  98. }
  99. _videoBackView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, width, height)];
  100. _videoBackView.backgroundColor = [UIColor colorWithHexString:@"141414" alpha:1];
  101. }
  102. return _videoBackView;
  103. }
  104. - (UIView *)videoView {
  105. if(!_videoView) {
  106. CGFloat width = 0.0f;
  107. CGFloat height = 0.0f;
  108. height = kScreenHeight - 20;
  109. width = height / 3.0f * 4;
  110. if (width > kScreenWidth - 180) {
  111. width = kScreenWidth - 180;
  112. height = width / 4.0f * 3;
  113. }
  114. _videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
  115. }
  116. return _videoView;
  117. }
  118. - (EmptyView *)emptyView {
  119. if (!_emptyView) {
  120. CGFloat width = 0.0f;
  121. CGFloat height = 0.0f;
  122. height = kScreenHeight - 20;
  123. width = height / 3.0f * 4;
  124. if (width > kScreenWidth - 180) {
  125. width = kScreenWidth - 180;
  126. height = width / 4.0f * 3;
  127. }
  128. _emptyView = [[EmptyView alloc] initWithFrame:CGRectMake(10, 10, width, height) role:[ClassroomService sharedService].currentRoom.currentMember.role];
  129. }
  130. return _emptyView;
  131. }
  132. - (UIImageView *)tipsImage {
  133. if (!_tipsImage) {
  134. CGFloat width = 0.0f;
  135. CGFloat height = 0.0f;
  136. height = kScreenHeight - 20;
  137. width = height / 3.0f * 4;
  138. if (width > kScreenWidth - 180) {
  139. width = kScreenWidth - 180;
  140. height = width / 4.0f * 3;
  141. }
  142. _tipsImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
  143. }
  144. return _tipsImage;
  145. }
  146. #pragma mark ----- 获取引导图
  147. - (NSString *)getGuideImage:(NSString *)subjectName {
  148. if ([subjectName isEqualToString:@"钢琴"]) {
  149. return @"image_piano";
  150. }
  151. else if ([subjectName isEqualToString:@"萨克斯"]) {
  152. return @"image_sax";
  153. }
  154. else if ([subjectName isEqualToString:@"长号"]) {
  155. return @"image_trombone";
  156. }
  157. else if ([subjectName isEqualToString:@"古筝"]) {
  158. return @"image_Zheng";
  159. }
  160. else if ([subjectName isEqualToString:@"低音提琴"]) {
  161. return @"image_contrabass";
  162. }
  163. else if ([subjectName isEqualToString:@"小鼓"]) {
  164. return @"image_sideDrum";
  165. }
  166. else if ([subjectName isEqualToString:@"架子鼓"]) {
  167. return @"image_Drum";
  168. }
  169. else if ([subjectName isEqualToString:@"扬琴"]) {
  170. return @"image_dulcimer";
  171. }
  172. else if ([subjectName isEqualToString:@"大提琴"]) {
  173. return @"image_violoncello";
  174. }
  175. else if ([subjectName isEqualToString:@"单簧管"] || [subjectName isEqualToString:@"双簧管"]) {
  176. return @"image_clarinet";
  177. }
  178. else if ([subjectName isEqualToString:@"小提琴"] || [subjectName isEqualToString:@"中提琴"]) {
  179. return @"image_violin";
  180. }
  181. else if ([subjectName isEqualToString:@"长笛"] || [subjectName isEqualToString:@"大管"] || [subjectName isEqualToString:@"小号"] || [subjectName isEqualToString:@"笙"] || [subjectName isEqualToString:@"笛子"]) {
  182. return @"image_flute";
  183. }
  184. else if ([subjectName isEqualToString:@"圆号"] || [subjectName isEqualToString:@"大号"] || [subjectName isEqualToString:@"上低音号"] || [subjectName isEqualToString:@"手风琴"] || [subjectName isEqualToString:@"古典吉他"] || [subjectName isEqualToString:@"中阮"] || [subjectName isEqualToString:@"琵琶"] || [subjectName isEqualToString:@"二胡"]) {
  185. return @"image_tuba";
  186. }
  187. else {
  188. return @"";
  189. }
  190. }
  191. /*
  192. // Only override drawRect: if you perform custom drawing.
  193. // An empty implementation adversely affects performance during animation.
  194. - (void)drawRect:(CGRect)rect {
  195. // Drawing code
  196. }
  197. */
  198. @end