| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // ClassroomMainContainer.m
- // StudentDaya
- //
- // Created by Kyle on 2020/6/12.
- // Copyright © 2020 DayaMusic. All rights reserved.
- //
- #import "ClassroomMainContainer.h"
- #import "RTCService.h"
- #import "LocalRenderManager.h"
- @interface ClassroomMainContainer ()
- @property (nonatomic, strong) UIView *tapGestureView;
- @property (nonatomic) CGRect currentVideoFrame;
- @property (nonatomic) CGRect originVideoFrame;
- @property (nonatomic, strong) UIImageView *tipsImage;
- @end
- @implementation ClassroomMainContainer
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor colorWithHexString:@"141414" alpha:1];
- [self addSubview:self.emptyView];
- [self addSubview:self.videoBackView];
- [self.videoBackView addSubview:self.videoView];
- self.originVideoFrame = self.videoBackView.frame;
- self.currentVideoFrame = self.originVideoFrame;
- [self.videoView addSubview:self.tipsImage];
- }
- return self;
- }
- - (void)didChangeRole:(Role)role {
- [self.emptyView changeRole:role];
- }
- - (void)containerViewRenderView:(RoomMember *)member {
- self.videoBackView.hidden = NO;
- self.videoView.hidden = NO;
- if([[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
- RoomMember *curMemeber =[ClassroomService sharedService].currentRoom.currentMember;
- [[RTCService sharedInstance] renderLocalVideoOnView:self.videoView cameraEnable:curMemeber.cameraEnable];
- [LocalRenderManager shareInstance].hadRenderMainView = YES;
- }else {
- [LocalRenderManager shareInstance].hadRenderMainView = NO;
- [[RTCService sharedInstance] exchangeRemoteUserAVStreamToNomalSteam:member.userId callback:^{
- [[RTCService sharedInstance] renderRemoteVideoOnView:self.videoView forUser:member.userId];
- }];
- }
- self.member = member;
- }
- - (void)cancelRenderView {
- [LocalRenderManager shareInstance].hadRenderMainView = NO;
- // 如何关闭了摄像头,可能导致videoView 遮挡控制事件
- [self updateVideoViewFrame:NO];
- self.videoBackView.hidden = YES;
- }
- - (void)setSubjectName:(NSString *)subjectName {
- _subjectName = subjectName;
- NSString *imgName = [self getGuideImage:subjectName];
- if (![NSString isEmptyString:imgName]) {
- self.tipsImage.hidden = NO;
- [self.tipsImage setImage:[UIImage imageNamed:imgName]];
- }
- else {
- self.tipsImage.hidden = YES;
- }
- }
- #pragma mark - private method
- - (void)updateVideoViewFrame:(BOOL)isFull {
- self.currentVideoFrame = self.frame;
- if(isFull) {
- [self.superview addSubview:self.videoBackView];
- [self.superview bringSubviewToFront:self.videoBackView];
- CGFloat width = 0.0f;
- CGFloat height = 0.0f;
-
- height = kScreen_Width / 4.0f * 3;
- if (height > kScreenHeight) {
- height = kScreenHeight;
- }
- width = height / 3.0f * 4;
- self.videoView.frame = CGRectMake((kScreenWidth - width) / 2.0f, 0, width, height);
- }else {
- [self.videoBackView removeFromSuperview];
- [self addSubview:self.videoBackView];
- self.currentVideoFrame = self.originVideoFrame;
- self.videoView.frame = CGRectMake(0, 0, CGRectGetWidth(self.currentVideoFrame), CGRectGetHeight(self.currentVideoFrame));
- }
- self.videoBackView.frame = self.currentVideoFrame;
- }
- #pragma mark - getter
- - (UIView *)videoBackView {
- if (!_videoBackView) {
- CGFloat width = 0.0f;
- CGFloat height = 0.0f;
- height = kScreenHeight - 20;
- width = height / 3.0f * 4;
- if (width > kScreenWidth - 180) {
- width = kScreenWidth - 180;
- height = width / 4.0f * 3;
- }
- _videoBackView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, width, height)];
- _videoBackView.backgroundColor = [UIColor colorWithHexString:@"141414" alpha:1];
- }
- return _videoBackView;
- }
- - (UIView *)videoView {
- if(!_videoView) {
- CGFloat width = 0.0f;
- CGFloat height = 0.0f;
- height = kScreenHeight - 20;
- width = height / 3.0f * 4;
- if (width > kScreenWidth - 180) {
- width = kScreenWidth - 180;
- height = width / 4.0f * 3;
- }
- _videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
- }
- return _videoView;
- }
- - (EmptyView *)emptyView {
- if (!_emptyView) {
- CGFloat width = 0.0f;
- CGFloat height = 0.0f;
- height = kScreenHeight - 20;
- width = height / 3.0f * 4;
- if (width > kScreenWidth - 180) {
- width = kScreenWidth - 180;
- height = width / 4.0f * 3;
- }
- _emptyView = [[EmptyView alloc] initWithFrame:CGRectMake(10, 10, width, height) role:[ClassroomService sharedService].currentRoom.currentMember.role];
- }
- return _emptyView;
- }
- - (UIImageView *)tipsImage {
- if (!_tipsImage) {
- CGFloat width = 0.0f;
- CGFloat height = 0.0f;
- height = kScreenHeight - 20;
- width = height / 3.0f * 4;
- if (width > kScreenWidth - 180) {
- width = kScreenWidth - 180;
- height = width / 4.0f * 3;
- }
- _tipsImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
- }
- return _tipsImage;
- }
- #pragma mark ----- 获取引导图
- - (NSString *)getGuideImage:(NSString *)subjectName {
- if ([subjectName isEqualToString:@"钢琴"]) {
- return @"image_piano";
- }
- else if ([subjectName isEqualToString:@"萨克斯"]) {
- return @"image_sax";
- }
- else if ([subjectName isEqualToString:@"长号"]) {
- return @"image_trombone";
- }
- else if ([subjectName isEqualToString:@"古筝"]) {
- return @"image_Zheng";
- }
- else if ([subjectName isEqualToString:@"低音提琴"]) {
- return @"image_contrabass";
- }
- else if ([subjectName isEqualToString:@"小鼓"]) {
- return @"image_sideDrum";
- }
- else if ([subjectName isEqualToString:@"架子鼓"]) {
- return @"image_Drum";
- }
- else if ([subjectName isEqualToString:@"扬琴"]) {
- return @"image_dulcimer";
- }
- else if ([subjectName isEqualToString:@"大提琴"]) {
- return @"image_violoncello";
- }
- else if ([subjectName isEqualToString:@"单簧管"] || [subjectName isEqualToString:@"双簧管"]) {
- return @"image_clarinet";
- }
- else if ([subjectName isEqualToString:@"小提琴"] || [subjectName isEqualToString:@"中提琴"]) {
- return @"image_violin";
- }
- else if ([subjectName isEqualToString:@"长笛"] || [subjectName isEqualToString:@"大管"] || [subjectName isEqualToString:@"小号"] || [subjectName isEqualToString:@"笙"] || [subjectName isEqualToString:@"笛子"]) {
- return @"image_flute";
- }
- else if ([subjectName isEqualToString:@"圆号"] || [subjectName isEqualToString:@"大号"] || [subjectName isEqualToString:@"上低音号"] || [subjectName isEqualToString:@"手风琴"] || [subjectName isEqualToString:@"古典吉他"] || [subjectName isEqualToString:@"中阮"] || [subjectName isEqualToString:@"琵琶"] || [subjectName isEqualToString:@"二胡"]) {
- return @"image_tuba";
- }
- else {
- return @"";
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|