12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105 |
- //
- // TXClassroomViewController.m
- // TeacherDaya
- //
- // Created by 王智 on 2023/4/14.
- // Copyright © 2023 DayaMusic. All rights reserved.
- //
- #import "TXClassroomViewController.h"
- #import "TXClassTitleView.h"
- #import "TXClassroomVideoListView.h"
- #import "TXClassroomMainContainer.h"
- #import "TXClassRoomAlertView.h"
- #import "LoginHelper.h"
- #import "TXRTCService.h"
- // 成员列表
- #import "ClassMemberListView.h"
- // 聊天列表
- #import "TXChatAreaView.h"
- #import "Classroom.h"
- #import "ClassroomService.h"
- #import <MBProgressHUD/MBProgressHUD.h>
- #import "AppDelegate.h"
- #import "KSWhiteboardControl.h"
- #import "UIDevice+TFDevice.h"
- #import "LocalRenderManager.h"
- #import "NSDate+Transform.h"
- #import "WhiteboardListView.h"
- #import "NewTXMetronomeAlertView.h"
- #import "UIViewController+zhStatusBarStyle.h"
- #import "KSTipsView.h"
- // 时间渲染
- #import "ClassroomTimerManager.h"
- //// 宫格视图
- #import "TXFullVideoView.h"
- #import "VideoMaskView.h"
- #import "TXTeachToolView.h"
- #import "AccompanyProgressView.h"
- #import "SongListViewController.h"
- #import "CustomNavViewController.h"
- #import "KSCloseCourseView.h"
- #import "KSImageDisplayView.h"
- #import "LLPhotoBrowser.h"
- #import "KSMediaManager.h"
- #import "UIImage+ResizeImage.h"
- #import "AccompanyView.h"
- #import "TXLiteAVSDK_Professional/TXLiteAVSDK.h"
- #import "KSRemoteUserManager.h"
- #import "TXQuitChooseView.h"
- #import "TXDanMuView.h"
- #import "TXTimeView.h"
- #import "CoursewareAlertView.h"
- #define MAXBIGPHOTONUMBER (3)
- #define MAXPHOTONUMBER (3)
- #define COLUMNNUMBER (3)
- #define KBUTTON_LEFTSPACE (16)
- #define TitleViewHeight (66)
- #define PersonListViewWidth (280)
- #define WhiteboardListWidth (140+33)
- #define TTimeLableWidth (180)
- #define TTimeLableHeight (20)
- // 需添加TRTC 回调
- @interface TXClassroomViewController ()<UIGestureRecognizerDelegate,TXClassTitleViewDelegate,KSWhiteboardControlDelegate,ClassroomDelegate,TXClassroomMainContainerDelegate,TXClassVideoListViewDelegate,ClassMemberListViewDelegate,WhiteboardListViewDelegate,ClassroomTimerManagerDelegate,TXFullVideoViewDelegate,TeachToolViewDelegate,LLPhotoBrowserDelegate,TRTCCloudDelegate, TXRTCServiceDelegate>
- @property (nonatomic, strong) KSMediaManager *mediaManager;
- @property (nonatomic, strong) NSMutableArray *imageArray; // 图片数组
- @property (nonatomic, strong) NSMutableArray *imageAsset; // 图片 asset
- @property (nonatomic, strong) TXClassTitleView *titleView;
- @property (nonatomic, strong) TXClassroomMainContainer *containerView;
- @property (nonatomic, strong) TXClassroomVideoListView *videoListView;
- @property (nonatomic, strong) ClassMemberListView *memberListView;
- @property (nonatomic, strong) KSWhiteboardControl *wBoardCtrl;
- // 聊天的area
- @property (nonatomic, strong) TXChatAreaView *chatAreaView;
- @property (nonatomic, strong) MBProgressHUD *hud;
- @property (nonatomic, strong) WhiteboardListView *whiteboardListView;
- @property (nonatomic, strong) UILabel *networkLabel;
- @property (nonatomic, assign) BOOL cancleAlert;
- @property (nonatomic, assign) BOOL isQuitRoom; // 是否正在退出房间
- @property (nonatomic, assign) BOOL hasShowAlert;
- @property (nonatomic, assign) BOOL isChat;
- @property (nonatomic, strong) NewTXMetronomeAlertView *controlView;
- @property (nonatomic, strong) KSTipsView *tipsView;
- @property (nonatomic, strong) ClassroomTimerManager *timeManager;
- @property (nonatomic, strong) TXFullVideoView *squareView; // 宫格视频
- @property (nonatomic, assign) BOOL squareOn; // 是否开启宫格模式
- @property (nonatomic, strong) VideoMaskView *maskView;
- @property (nonatomic, strong) NSString *fileUrl;
- @property (nonatomic, strong) TXTeachToolView *toolView;
- @property (nonatomic, strong) AccompanyProgressView *progressView;
- @property (nonatomic, strong) KSCloseCourseView *closeCourseAlert;
- @property (nonatomic, strong) TXClassRoomAlertView *alertView;
- @property (nonatomic, strong) AccompanyView *accompanyView;
- @property (nonatomic, strong) NSString *songName; // 当前选择的曲目名称
- @property (nonatomic, strong) NSString *songId; // 当前选择的曲目id
- @property (nonatomic, strong) NSString *songUrl; // 当前播放的url
- @property (nonatomic, assign) BOOL isAccompany; // 当前选择的是否为伴奏
- @property (nonatomic, assign) NSInteger soundVolume; // 伴奏音量
- @property (nonatomic, strong) CoursewareAlertView *coursewareView;
- @property (nonatomic, strong) TRTCCloud *engine;
- /** 节拍类型 */
- @property (nonatomic, assign) KSMetronomeType type;
- /** 播放速率,范围40~240 */
- @property (nonatomic, assign) int rate;
- // 播放节拍器音量
- @property (nonatomic, assign) NSInteger volome;
- // 是否隐藏了列表
- @property (nonatomic, assign) BOOL videoListHidden;
- @property (nonatomic, strong) TXDanMuView *danView;
- @property (nonatomic, strong) TXTimeView *timeView;
- @property (nonatomic, strong) UIButton *showButton;
- @end
- @implementation TXClassroomViewController
- -(BOOL)prefersHomeIndicatorAutoHidden {
- return YES;
- }
- - (void)changeOrientation:(BOOL)isLandScape {
- if (isLandScape) {
- // 切换到横屏
- if (IS_IPAD) {
- self.zh_statusBarHidden = YES;
- }
- AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
- delegate.allowAutoRotate = YES;
- [UIDevice switchNewOrientation:UIInterfaceOrientationLandscapeRight inController:self];
- }
- else {
- // 切换到横屏
- AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
- delegate.allowAutoRotate = NO;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if (IS_IPAD) {
- self.zh_statusBarHidden = NO;
- }
- [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait inController:self];
- });
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- // 切换到横屏
- [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
- _isPushChooseView = NO;
- if (_isPushChooseView) {
- NSLog(@"-----");
- }
- [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- // 竖屏
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
- if (_isPushChooseView == NO) {
- [self hideAlertView];
- [self judgeShowAlert];
- }
- [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
- }
- - (void)hideAlertView {
- if (self.alertView && self.alertView.isShow) {
- [self.alertView dismissAlertView];
- }
- [self.memberListView hiddenAlert];
- if (_accompanyView && _accompanyView.isShow) {
- [_accompanyView dismissAlertView];
- }
- if (self.controlView && self.controlView.isShow) {
- [self.controlView dismissAlertView];
- }
- }
- - (void)judgeShowAlert {
- if (self.cancleAlert || self.hasShowAlert) {
- return;
- }
- if (![NSString isEmptyString:self.classEndTime]) {
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSDate *endDate = [dateFormatter dateFromString:self.classEndTime];
- NSDate *currentDate = [NSDate date];
- NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:endDate];
- if (timeInterval >= 0) { // 课程结束弹出评价
- self.hasShowAlert = YES;
- [[NSNotificationCenter defaultCenter] postNotificationName:@"showEvaluateAlert" object:self.courseId];
- }
- }
- }
- - (void)configBeatConfig {
- self.type = KSMetronomeType4V4;
- self.volome = 100;
- self.rate = 90;
- }
- - (void)configDefaultSoundVolume {
- self.soundVolume = 100;
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- // 切换到横屏
- [self changeOrientation:YES];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
-
- self.view.backgroundColor = [UIColor whiteColor];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(leaveRoomAction) name:@"classroomLogout" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(quitRoomAction) name:@"classroomQuit" object:nil];
-
- [self configBeatConfig]; // 设置默认节拍器数据
- [self configDefaultSoundVolume]; // 设置默认伴奏音量
- [self configClassroomDefault];
- UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
- [self.view addGestureRecognizer:tapGes];
- tapGes.delegate = self;
-
- [self showRoleHud];
- [TRTC_MANAGER useSpeaker:YES];
- self.isQuitRoom = NO;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgroundQuitRoomAction) name:@"backgroundQuit" object:nil];
- }
- - (void)configClassroomDefault {
- [self addSubviews];
- [self bindDelegates];
- [self publishStream];
- [self renderMainContainerView];
- self.timeManager.isDisplay = YES;
- }
- - (void)backgroundQuitRoomAction {
- self.isQuitRoom = YES;
- [[LoginHelper sharedInstance] logout];
-
- self.cancleAlert = YES;
- }
- #pragma mark ----- 账号异地登陆
- - (void)leaveRoomAction {
- [self showMessage:@"该账号在其他设备上登录"];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- self.isQuitRoom = YES;
- [[LoginHelper sharedInstance] logout];
- self.cancleAlert = YES;
- [self hideAlertView];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"backLoginView" object:nil];
- });
- }
- - (void)quitRoomAction {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- self.isQuitRoom = YES;
- [[LoginHelper sharedInstance] logout];
- self.cancleAlert = YES;
- [self hideAlertView];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"showOtherLoginAlert" object:nil];
- });
- }
- // 提示信息
- - (void)showMessage:(NSString *)message {
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [self.view bringSubviewToFront:hud];
- hud.removeFromSuperViewOnHide =YES;
- hud.mode = MBProgressHUDModeText;
- hud.label.text = message;
- hud.minSize = CGSizeMake(132.f, 60.0f);
- hud.label.textColor = [UIColor whiteColor];
- hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
- hud.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
- [hud hideAnimated:YES afterDelay:2];
- }
- - (void)tapGesture: (UITapGestureRecognizer *)tapGesture {
- if (self.titleView.isDisplay) {
- self.titleView.isDisplay = NO;
- self.timeManager.isDisplay = NO;
- }
- else {
- self.titleView.isDisplay = YES;
- self.timeManager.isDisplay = YES;
- }
- [self hidePersonListView];
- [self hideChatAreaView];
- [self.danView resetInputStatus];
- }
- - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
-
- if ([touch.view isDescendantOfView:self.memberListView] || [touch.view isDescendantOfView:self.chatAreaView] || [touch.view isDescendantOfView:self.videoListView] || [touch.view isDescendantOfView:self.whiteboardListView]
- || [touch.view isDescendantOfView:self.squareView] || [touch.view isDescendantOfView:self.maskView] || [touch.view isDescendantOfView:self.toolView] || [touch.view isDescendantOfView:self.closeCourseAlert] || [touch.view isDescendantOfView:self.danView]) {
- return NO;
- }
- // if ([touch.view isDescendantOfView:self.containerView]) {
- // [self tapGesture:(UITapGestureRecognizer *)gestureRecognizer];
- // }
- return YES;
- }
- - (void)showRoleHud {
- Role role = [ClassroomService sharedService].currentRoom.currentMember.role;
- if(role == RoleAudience) {
- [self.tipsView showTipsMessage:@"你当前身份是旁听人,其他人看/听不见你" inView:self.view];
- [self performSelector:@selector(showOnlyYouHUD) withObject:nil afterDelay:5.0f];
- } else{
- [self showOnlyYouHUD];
- }
- }
- - (void)showOnlyYouHUD {
- if ([ClassroomService sharedService].currentRoom.memberList.count == 1) {
- [self.tipsView showTipsMessage:@"当前课堂只有你一人,你可以等待或离开" inView:self.view];
- }
- }
- #pragma mark ------ ClassTitleViewDelegate
- - (void)classTitleView:(UIButton *)button didTapAtTag:(ClassTitleViewActionTag)tag {
-
- [self.chatAreaView resetInputStatus];
- [self.danView resetInputStatus];
- ClassRoomTitleButton *tagButton = [self.titleView viewWithTag:tag+1000];
- switch (tag) {
- case ClassTitleViewActionTagSwitchCamera:
- {
- [TRTC_MANAGER switchCamera];
- }
- break;
- case ClassTitleViewActionTagMic:
- {
-
- if (tagButton.isSelected == NO) { // 关闭
- [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeMicrophone];
- }
- else { // 打开
- [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeMicrophone];
- }
- }
- break;
- case ClassTitleViewActionTagCamera:
- {
- if (tagButton.isSelected == NO) {
- [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeCamera];
- }
- else {
- [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeCamera];
- }
- }
- break;
- case ClassTitleViewActionTagMute:
- {
- tagButton.isSelected = !tagButton.isSelected;
- [TRTC_MANAGER useSpeaker:!tagButton.isSelected];
- }
- break;
- case ClassTitleViewActionTagSquare: // 宫格模式
- {
- if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
- // 当前
- [self.tipsView showTipsMessage:@"当前有学生演示中" inView:self.view];
- return;
- }
- self.squareOn = YES;
- [self.squareView showInView:self.view];
- [self.squareView showVideoList];
- }
- break;
- case ClassTitleViewActionTagDan: // 弹幕开关
- {
- tagButton.isSelected = !tagButton.isSelected;
- if (tagButton.isSelected) { // 关闭弹幕
- [self hideDanChatView];
- }
- else { // 开启弹幕
- [self showDanChatView];
- }
- }
- break;
- case ClassTitleViewActionTagChat:
- {
- tagButton.isSelected = !tagButton.isSelected;
- tagButton.isSelected ? [self showChatAreaView] : [self hideChatAreaView];
- self.isChat = tagButton.isSelected;
- }
- break;
- case ClassTitleViewActionTagMember:
- {
- tagButton.isSelected = !tagButton.isSelected;
- tagButton.isSelected ? [self showPersonListView] : [self hidePersonListView];
- }
- break;
- case ClassTitleViewActionTagHangup:
- {
- [self showQuitAlert];
- }
- default:
- break;
- }
- }
- - (void)quitViewAction:(QUITCLASSTYPE)type {
- if (type == QUITCLASSTYPE_CLOSE) {
- [self showCouseCloseAlert];
- }
- else {
- [self showQuitAlert];
- }
- }
- - (void)showQuitAlert {
- MJWeakSelf;
- self.alertView = [TXClassRoomAlertView shareInstance];
- [self.alertView configWithTitle:@"提示" desc:@"确认退出课堂吗?" leftTitle:@"取消" rightTitle:@"退出" cancel:^{
-
- } confirm:^{
- weakSelf.isQuitRoom = YES;
- weakSelf.hud = [weakSelf createProgressHUD];
- [[LoginHelper sharedInstance] logout];
- }];
- }
- #pragma mark ---- 节拍器控制
- - (void)showNodeControlView {
- [self hidePersonListView];
- self.controlView = [NewTXMetronomeAlertView shareInstance];
- [self.controlView configRate:self.rate volume:self.volome beatType:self.type];
- self.controlView.isPlayBeat = [ClassroomService sharedService].currentRoom.isPlayBeat;
- MJWeakSelf;
- [self.controlView showAlertSureCallback:^(int rate, KSMetronomeType type, NSInteger volume) {
- weakSelf.type = type;
- weakSelf.rate = rate;
- weakSelf.volome = volume;
- }];
- [self.controlView metronomeClickAction:^(BOOL enable) {
- [weakSelf metronomeAction:enable];
- }];
- }
- - (void)metronomeAction:(BOOL)enable {
-
- MJWeakSelf;
- // 播放节拍器
- if (enable == YES) {
- [ClassroomService sharedService].currentRoom.isPlayBeat = YES;
- if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
- NSString *userId = [ClassroomService sharedService].currentRoom.shareUserId;
- [weakSelf operationStudentPlayNode:userId];
- }
- else {
- [weakSelf operationStudentPlayNode:@""];
- }
-
- if ([ClassroomService sharedService].currentRoom.isPlaySong) {
- [ClassroomService sharedService].currentRoom.isPlaySong = NO;
- DeviceType type = self.isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
-
- [[ClassroomService sharedService] enableMutilMemberDevice:NO type:type songId:[weakSelf.songId intValue] soundVolume:weakSelf.soundVolume forUser:@""];
- weakSelf.accompanyView.isPlaying = NO;
- }
- }
- else {
-
- NSDictionary *parm = @{@"enable": @(NO),
- @"rate" : @(0),
- @"customType" : @(0),
- @"playVolume" : @(0),
- @"userId" : @"",
- };
-
- [[ClassroomService sharedService] enablePlayMessage:NO content:[parm mj_JSONString] userId:@""];
- [ClassroomService sharedService].currentRoom.isPlayBeat = NO;
- [weakSelf unplayBeatNodeRefreshStream]; // 刷新音频流播放
- }
- }
- - (void)operationStudentPlayNode:(NSString *)userId {
- NSDictionary *parm = @{@"enable": @(YES),
- @"rate" : @(self.rate),
- @"customType" : @(self.type),
- @"playVolume" : @(self.volome),
- @"userId" : userId,
- };
- [[ClassroomService sharedService] enablePlayMessage:YES content:[parm mj_JSONString] userId:userId];
- // 默认显示第一个学生的视频 单个操作不再次刷新主屏
- if (self.videoListView.videoDataSource.count >= 1 && [NSString isEmptyString:userId]) {
- for (RoomMember *member in self.videoListView.videoDataSource) {
- if (member.role == RoleStudent) {
- [self videoListView:nil didTap:member];
- break;
- }
- }
- }
- else if (![NSString isEmptyString:userId]) {
- [ClassroomService sharedService].currentRoom.currentPlayUserId = userId;
- [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:userId];
- }
- }
- - (void)playNodeAction:(BOOL)enable userId:(NSString *)userId rate:(int)rate beatType:(BeatType)type {
- NSLog(@"playNodeAction userId:%@ enable:%@ beatType:%@ rate:%@",userId,@(enable),@(type), @(rate));
- // 刷新当前学生的节拍器状态
- if ([NSString isEmptyString:userId]) { // 全员
- for (RoomMember *member in [ClassroomService sharedService].currentRoom.memberList) {
- member.enable = enable;
- }
- }
- else { // 部分操作
- NSArray *userIdArray = [userId componentsSeparatedByString:@","];
- for (NSString *subUserId in userIdArray) {
- for (RoomMember *member in [ClassroomService sharedService].currentRoom.memberList) {
- if ([member.userId isEqualToString:subUserId]) {
- member.enable = enable;
- }
- }
- }
- }
- [self.containerView refreshToolView];
- }
- #pragma mark - ClassroomDelegate
- - (void)roomDidLeave {
- NSLog(@"roomDidLeave");
-
- // 关闭白板连接
- [self.wBoardCtrl.wbView.sdk setCommonCallbackDelegate:nil];
- [self.wBoardCtrl.wbView.room disconnect:^{
- }];
- [TRTC_MANAGER leaveRoom:^(NSInteger code) {
-
- }];
-
- [self dismissClassroom];
- }
- - (void)dismissClassroom {
- [self.hud hideAnimated:YES];
- [ClassroomService sharedService].currentRoom = nil;
- [self changeOrientation:NO];
- [self.timeManager stopDurationTimer];
- [self.timeView.timeLabel.layer removeAllAnimations];
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)memberDidJoin:(RoomMember *)member {
- NSLog(@"memberDidJoin %@",member);
- if(member.role == RoleStudent) {
- [self.tipsView showTipsMessage:[NSString stringWithFormat:@"学生%@已经进入教室", member.name] inView:self.view];
- if (self.squareOn) {
- [self.squareView showVideoList];
- }
- else {
- [self.videoListView reloadVideoList];
- }
- // 如果在播放中
- if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
- if ([ClassroomService sharedService].currentRoom.memberList.count > 2) {
- [TRTC_MANAGER unPlayRemoteStudentWithId:member.userId];
- }
- }
- }
- [self.memberListView reloadPersonList];
- }
- - (void)memberDidLeave:(RoomMember *)member {
- NSLog(@"memberDidLeave %@",member);
- if(member.role != RoleAudience) {
- if (member.role == RoleStudent) {
- [self.tipsView showTipsMessage:[NSString stringWithFormat:@"学生%@已经离开教室", member.name] inView:self.view];
- if (self.squareOn && [member.userId isEqualToString:self.squareView.displayUserId]) {
- [self dismissMaskViewEvent];
- }
- // 如果主屏上台学生
- if ([ClassroomService sharedService].currentRoom.shareUserId == member.userId) {
- [self teachToolView:self.toolView.videoButton.actionButton didTapAtTag:TeachToolTagVideo];
- }
- else {
- if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayTypeStudent && [[ClassroomService sharedService].currentRoom.currentDisplayURI isEqualToString:member.userId]) {
- [self videoListView:self.videoListView didTap:[ClassroomService sharedService].currentRoom.currentMember];
- }
- }
- }
- if (self.squareOn) {
- [self.squareView showVideoList];
- }
- else {
- [self.videoListView reloadVideoList];
- }
- }
- [self.memberListView reloadPersonList:member tag:ClassPersonListTagRemove];
- if ([self.progressView isShow]) {
- [self.progressView requestData];
- }
- }
- - (void)memberDidKick:(RoomMember *)member {
- NSLog(@"memberDidKick %@",member);
- if ([ClassroomService sharedService].currentRoom.currentMember.role == RoleTeacher) {
- [self.tipsView showTipsMessage:[NSString stringWithFormat:@"你已将%@移出教室", member.name] inView:self.view];
- }
- if (self.squareOn) {
- [self.squareView showVideoList];
- }
- else {
- [self.videoListView reloadVideoList];
- }
- [self.memberListView reloadPersonList:member tag:ClassPersonListTagRemove];
- if (self.containerView.member.role == member.role) {
- [self.containerView cancelRenderView];
- }
- }
- - (void)errorDidOccur:(ErrorCode)code {
- NSLog(@"errorDidOccur %@",@(code));
- [self.hud hideAnimated:YES];
- if (code != ErrorCodeSuccess) {
- if (code == ErrorCodeOverMaxUserCount) {
- [self.tipsView showTipsMessage:@"超过人数限制" inView:self.view];
- }else {
- [self.tipsView showTipsMessage:@"操作失败,请稍后再试" inView:self.view];
- }
- }
- }
- - (void)deviceDidEnable:(BOOL)enable type:(DeviceType)type forUser:(RoomMember *)member operator:(nonnull NSString *)operatorId {
- NSLog(@"deviceDidEnable devicetype:%@ enable:%@ memeber:%@",@(type),@(enable),member);
- RoomMember *curMember = [ClassroomService sharedService].currentRoom.currentMember;
- NSString *hudMessage = @"";
- //只有老师和自己才有提示
- if (curMember.role == RoleTeacher && ![member.userId isEqualToString:curMember.userId]) {
- if (type == DeviceTypeCamera) {
- hudMessage = !enable ? [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetCameraClose", @"SealClass", nil),member.name] : [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetCameraOpen", @"SealClass", nil),member.name];
- [self refreshVideoView:member];
-
- } else if (type == DeviceTypeMicrophone) {
- hudMessage = !enable ? [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetMicorophoneClose", @"SealClass", nil),member.name] : [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetMicorophoneOpen", @"SealClass", nil),member.name];
- [self.containerView refreshToolView];
- [self.memberListView reloadPersonList:member tag:ClassPersonListTagRefresh];
- [self.videoListView updateMicStatus:member.userId volume:40];
- }
- else if (type == DeviceTypeMusicMode) {
- }
- else if (type == DeviceTypeHandup) {
- if (![curMember.userId isEqualToString:operatorId]) {
- hudMessage = !enable ? [NSString stringWithFormat:@"%@已取消举手",member.name] : [NSString stringWithFormat:@"%@已举手",member.name];
- }
-
- if (self.squareOn) {
- [self.squareView showVideoList];
- }
- else {
- [self.videoListView reloadVideoList];
- }
- [self.memberListView reloadPersonList:member tag:ClassPersonListTagRefresh];
- }
- else if (type == DeviceTypeExamSong) { // 伴奏播放
-
- }
- else if (type == DeviceTypeAccompany || type == DeviceTypeMusicScore) { // 新伴奏 或原声播放
-
- }
- if (![NSString isEmptyString:hudMessage]) {
- [self.tipsView showTipsMessage:hudMessage inView:self.view];
- }
-
- }else {
- if ([curMember.userId isEqualToString:member.userId]) {
- if (type == DeviceTypeCamera) { // 摄像头
- // 非自己操作才需要做提示
- if(![curMember.userId isEqualToString:operatorId]){
- hudMessage = !enable ? NSLocalizedStringFromTable(@"YourCameraClosed", @"SealClass", nil) : NSLocalizedStringFromTable(@"CameraOpend", @"SealClass", nil);
- [self.tipsView showTipsMessage:hudMessage inView:self.view];
- }
- [self refreshHardwareStatus];
- [TRTC_MANAGER setCameraDisable:!enable];
- [self refreshVideoView:member];
- return;
- } else if (type == DeviceTypeMicrophone) { // 麦克风
- // 非自己操作才需要做提示
- if(![curMember.userId isEqualToString:operatorId]){
- hudMessage = !enable ? NSLocalizedStringFromTable(@"YourMicorophoneClosed", @"SealClass", nil) : NSLocalizedStringFromTable(@"MicorophoneOpend", @"SealClass", nil);
- [self.tipsView showTipsMessage:hudMessage inView:self.view];
- }
-
- [self refreshHardwareStatus];
- [TRTC_MANAGER setMicrophoneDisable:!enable];
- [self.videoListView updateMicStatus:member.userId volume:40];
- }
- else if (type == DeviceTypeMusicMode) {
-
- }
-
- }
- }
-
- }
- - (void)refreshHardwareStatus {
- [self.titleView refreshTitleView];
- [self.containerView refreshToolView];
- }
- // 刷新单个视频显示
- - (void)refreshVideoView:(RoomMember *)member {
-
- if (self.squareOn) {
- [self.squareView showVideoList];
- }
- else {
- // 刷新单个数据
- RoomMember *curMember = [ClassroomService sharedService].currentRoom.currentMember;
- if ([member.userId isEqualToString:curMember.userId]) {
- if ([ClassroomService sharedService].currentRoom.currentDisplayType != DisplayWhiteboard && [[ClassroomService sharedService].currentRoom.currentDisplayURI isEqualToString:member.userId]) {
- [self.wBoardCtrl hideBoard];
- [self.containerView containerViewRenderView:member];
- }
- else {
- [self.videoListView updateUserVideo:member.userId];
- }
- [self.titleView refreshTitleView];
- }
- else {
- if ([ClassroomService sharedService].currentRoom.currentDisplayType != DisplayWhiteboard && [[ClassroomService sharedService].currentRoom.currentDisplayURI isEqualToString:member.userId]) {
- [self.wBoardCtrl hideBoard];
- [self.containerView containerViewRenderView:member];
- }
- else {
- [self.videoListView updateUserVideo:member.userId];
- }
- [self.memberListView reloadPersonList:member tag:ClassPersonListTagRefresh];
- }
- }
- [self.containerView refreshToolView];
- }
- - (void)whiteboardDidDisplay:(NSString *)boardId {
- NSLog(@"whiteboardDidDisplay %@ ",boardId);
- [self renderMainContainerView];
- }
- - (void)sharedScreenDidDisplay:(NSString *)userId {
- NSLog(@"sharedScreenDidDisplay %@ ",userId);
- [self renderMainContainerView];
- }
- - (void)teacherDidDisplay {
- NSLog(@"teacherDidDisplay %@ ",[ClassroomService sharedService].currentRoom.teacher);
- [self renderMainContainerView];
- }
- - (void)studentDidDisplay:(NSString *)studentId {
- NSLog(@"studentDidDisplay %@", studentId);
- [self renderMainContainerView];
- }
- - (void)noneDidDisplay {
- NSLog(@"noneDidDisplay");
- [self renderMainContainerView];
- }
- #pragma mark ---- whiteboardListDelegate
- - (void)whiteboardSharedViewCellTap:(id)recentShared {
- if ([recentShared isKindOfClass:[WhiteScene class]]) {
- [LocalRenderManager shareInstance].hadRenderMainView = NO;
- [TRTC_MANAGER cancleRenderUserVideo:[ClassroomService sharedService].currentRoom.currentDisplayURI];
- WhiteScene *whiteBoard = (WhiteScene *)recentShared;
- [self displayWhiteboard:whiteBoard.name];
- [ClassroomService sharedService].currentRoom.currentDisplayURI = whiteBoard.name;
- }
- }
- #pragma mark ---- TRTC delegate
- #pragma mark - private method
- - (void)bindDelegates {
- [ClassroomService sharedService].classroomDelegate = self;
- TRTC_MANAGER.delegate = self;
- }
- - (void)addSubviews {
- [self.view addSubview:self.containerView];
- [self.view addSubview:self.timeView];
- [self.timeView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.containerView.emptyView.mas_right).offset(-20);
- make.top.mas_equalTo(self.view.mas_top);
- make.height.mas_equalTo(44);
- }];
- [self.view bringSubviewToFront:self.timeView];
- [self.view addSubview:self.titleView];
- [self wBoardCtrl];
- [self chatAreaView];
- [self memberListView];
- [self.view addSubview:self.videoListView];
- [self.view addSubview:self.toolView];
- [self showDanChatView];
- CGFloat height = 275;
- [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.containerView.emptyView.mas_right);
- make.width.mas_equalTo(82);
- make.height.mas_equalTo(height);
- make.bottom.mas_equalTo(self.containerView.emptyView.mas_bottom);
- }];
- [self.toolView hiddenToolViewWithAnimation:NO];
- [self.view bringSubviewToFront:self.toolView];
- [self.view bringSubviewToFront:self.titleView];
- }
- - (void)showPersonListView {
- [self.view addSubview:self.memberListView];
- [self.memberListView reloadPersonList];
- }
- - (void)showChatAreaView{
- [self.view addSubview:self.chatAreaView];
- [self.chatAreaView scrollToBottom];
-
- }
- - (void)hidePersonListView {
- self.titleView.memberBtn.isSelected = NO;
- [self.memberListView removeFromSuperview];
- }
- - (void)hideChatAreaView{
- [UIView animateWithDuration:0.2 animations:^{
- self.titleView.chatBtn.isSelected = NO;
- [self.chatAreaView resetInputStatus];
- [self.chatAreaView removeFromSuperview];
- }];
- }
- - (void)showDanChatView {
- // 视频页面添加弹幕
- [self.containerView.videoView addSubview:self.danView];
- }
- - (void)hideDanChatView {
- //
- [self.danView removeFromSuperview];
- }
- - (CGRect)mainContainerViewFrame {
- CGFloat x = 0;
- CGFloat y = 0;
- CGFloat width = KLandscapeWidth - x;
- CGFloat height = KLandscapeHeight - y;
- return CGRectMake(x, y, width, height);
- }
- - (void)displayWhiteboard:(NSString *)boardId {
- CGRect boardFrame = [self getWBoardFrame];
- [self.wBoardCtrl loadWBoardWithFrame:boardFrame name:boardId];
- for (UIView * view in self.view.subviews) {
- if ([view isKindOfClass:[ClassMemberListView class]] || [view isKindOfClass:[TXChatAreaView class]] || [view isKindOfClass:[WhiteboardListView class]]) {
- [self.view bringSubviewToFront:view];
- }
- }
- if (self.videoListHidden) {
- [self.view bringSubviewToFront:self.showButton];
- [self.view bringSubviewToFront:self.toolView];
- }
- self.toolView.isVideoDisplay = NO;
- [self.view bringSubviewToFront:self.timeView];
- [self.view bringSubviewToFront:self.titleView];
-
- }
- - (void)refreshWhiteBoardFrame {
- [self.wBoardCtrl setWBoardFrame:[self getWBoardFrame]];
- }
- - (CGRect)getWBoardFrame {
-
- CGRect mainVideoFrame = CGRectZero;
- CGFloat width = 0;
- CGFloat height = 0;
- if (self.videoListHidden) {
- width = KLandscapeWidth;
- height = KLandscapeHeight;
-
- }
- else {
- width = KLandscapeWidth -(144 + 20 + 10);
- height = KLandscapeHeight;
- }
- mainVideoFrame.size.width = width;
- mainVideoFrame.size.height = height;
- mainVideoFrame.origin.x += 0;
- mainVideoFrame.origin.y = 0;
- return mainVideoFrame;
- }
- - (void)publishStream {
- if ([ClassroomService sharedService].currentRoom.currentMember.role != RoleAudience) {
- [TRTC_MANAGER publishStream];
- }
- }
- - (void)renderMainContainerView {
- if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayTypeStudent) {
- // 有打开的屏幕
- for (RoomMember *displayMember in [ClassroomService sharedService].currentRoom.memberList) {
- if ([displayMember.userId isEqualToString:[ClassroomService sharedService].currentRoom.currentDisplayURI]) {
- [self.containerView refreshToolView];
- [self.wBoardCtrl hideBoard];
- [self.containerView containerViewRenderView:displayMember];
- [self.videoListView showTeacherPrompt:NO];
- break;
- }
- }
-
- } else if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayTeacher) {
- NSLog(@"%@",[ClassroomService sharedService].currentRoom.currentDisplayURI);
- [self.wBoardCtrl hideBoard];
- [self.containerView containerViewRenderView:[ClassroomService sharedService].currentRoom.teacher];
- [self.videoListView showTeacherPrompt:YES];
- } else if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayWhiteboard) {
- [self.containerView cancelRenderView];
- [self displayWhiteboard:[ClassroomService sharedService].currentRoom.currentDisplayURI];
- [self.videoListView showTeacherPrompt:NO];
- } else if (([ClassroomService sharedService].currentRoom.currentDisplayType == DisplaySharedScreen)) {
- [self.wBoardCtrl hideBoard];
-
- [TRTC_MANAGER renderRemoteUser:[ClassroomService sharedService].currentRoom.currentDisplayURI inView:self.containerView.videoView];
- // 分享视频
- [self.videoListView showTeacherPrompt:NO];
- } else {
- [self.wBoardCtrl hideBoard];
- [self.containerView cancelRenderView];
- [self.videoListView showTeacherPrompt:NO];
- }
- }
- #pragma mark ----- ClassVideoListViewDelegate
- - (void)videoListView:(TXClassroomVideoListView *)view didTap:(RoomMember *)member {
-
- if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
- // 当前
- [self.tipsView showTipsMessage:@"当前有学生演示中" inView:self.view];
- return;
- }
-
- // 将视频投到主屏幕上
- NSString *currentDisplayUserId = member.userId;
- NSString *lastDisplayUserId = [ClassroomService sharedService].currentRoom.currentDisplayURI;
-
- if([currentDisplayUserId isEqualToString:lastDisplayUserId]) {
- [self.videoListView updateUserVideo:lastDisplayUserId];
- if(![[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
-
- // 记录当前演奏播放音频的学生
- if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
- [ClassroomService sharedService].currentRoom.currentPlayUserId = currentDisplayUserId;
- [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:member.userId];
- }
- }
- return;
- }
- DisplayType type = member.role == RoleTeacher ? DisplayTeacher : DisplayTypeStudent;
- [ClassroomService sharedService].currentRoom.currentDisplayURI = currentDisplayUserId;
- [ClassroomService sharedService].currentRoom.currentDisplayType = type;
- [self.videoListView updateUserVideo:member.userId];
-
- if(![[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
-
- // 记录当前演奏播放音频的学生
- if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
- [ClassroomService sharedService].currentRoom.currentPlayUserId = currentDisplayUserId;
- [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:member.userId];
- }
- }
- [self renderMainContainerView];
- }
- - (void)unplayBeatNodeRefreshStream {
-
- if ([ClassroomService sharedService].currentRoom.isPlayBeat == NO && [ClassroomService sharedService].currentRoom.isPlaySong == NO) { // 关闭节拍器后播放所有学生端声音
- [TRTC_MANAGER playAllRemoteStudentAudioStream];
- [ClassroomService sharedService].currentRoom.currentPlayUserId = nil;
- }
- }
- - (void)videoListView:(TXClassroomVideoListView *)view didHideView:(BOOL)isHideView {
- if (isHideView) { // 隐藏video list
- [self hideVideoList];
- }
- else { // 显示
- [self showVideoList];
- }
- }
- - (void)hideVideoList {
- self.videoListHidden = YES;
- CGRect frame = self.videoListView.frame;
- self.videoListView.frame = CGRectMake(KLandscapeWidth, frame.origin.y, frame.size.width, frame.size.height);
- [self.containerView changeVideoFrameFull:YES];
- [self refreshWhiteBoardFrame];
- [self.view addSubview:self.showButton];
- [self.view bringSubviewToFront:self.toolView];
- }
- - (void)showVideoList {
- self.videoListHidden = NO;
- CGRect frame = self.videoListView.frame;
- self.videoListView.frame = CGRectMake(KLandscapeWidth - frame.size.width, frame.origin.y, frame.size.width, frame.size.height);
- [self.containerView changeVideoFrameFull:NO];
- [self refreshWhiteBoardFrame];
- [self.showButton removeFromSuperview];
- }
- #pragma mark ---- ClassroomTimerManager delegate
- - (void)formatTime:(NSString *)timeString {
- self.timeView.timeLabel.text = timeString;
- }
- - (void)timeLabelAddAnimation:(CABasicAnimation *)animation {
- self.timeView.timeLabel.textColor = HexRGB(0x2DC7AA);
- [self.timeView.timeLabel.layer addAnimation:animation forKey:nil];
- }
- - (void)hiddenTitleView {
- self.titleView.isDisplay = NO;
- }
- - (void)quitClassroomNotifer {
- // 课程结束后15分钟自动退出房间 连堂课不退出(对内)
- if (self.isQuitRoom == NO) {
- self.isQuitRoom = YES;
- // 退出房间
- [self.tipsView showTipsMessage:@"课程已结束" inView:self.view];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- // 课程结束退出房间
- SealClassLog(@"ClassEnd!");
- self.hud = [self createProgressHUD];
- [[LoginHelper sharedInstance] logout];
- [self.titleView clearUnreadMessage];
-
- });
- }
- }
- #pragma mark --- whiteboard
- - (void)didTurnPage:(NSInteger)pageNum {
-
- }
- - (void)whiteboardViewDidChangeZoomScale:(float)scale {
-
- }
- - (void)needRefreshWhiteboardList {
- [self.whiteboardListView reloadDataSource];
- }
- - (void)needShowTopTitleView:(UIView *)touchView {
- if ([touchView isDescendantOfView:self.whiteboardListView]) {
- return;
- }
- self.titleView.isDisplay = YES;
- self.timeManager.isDisplay = YES;
- [self hidePersonListView];
- [self hideChatAreaView];
- [self.danView resetInputStatus];
- }
- // 白板连接状态回调
- - (void)connectionWhiteboardStatus:(JOINROOMSTATUS)status {
- if (status == JOINROOMSTATUS_FAILED) {
- [self.tipsView showTipsMessage:@"白板连接失败,请检查您的网络" inView:self.view];
- }
- else if (status == JOINROOMSTATUS_PARAMERROR) {
- [self.tipsView showTipsMessage:@"获取白板参数错误" inView:self.view];
- }
- }
- #pragma mark ---- mainContainer
- - (void)mainContainerOpertionMember:(RoomMember *)member tapButton:(UIButton *)button didTapAtTag:(MainToolButtonTag)tag {
- RoomMember *curMember = [ClassroomService sharedService].currentRoom.currentMember;
- // 操作自己
- MainToolButton *toolButton = [self.containerView.toolView viewWithTag:tag+1000];
- // 操作自己
- if ([member.userId isEqualToString:curMember.userId]) {
- switch (tag) {
- case MainToolButtonTagMic: // 麦克风
- {
- if (toolButton.isSelected) { // 打开
- [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeMicrophone];
- }
- else { // 关闭
- [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeMicrophone];
- }
- }
- break;
- case MainToolButtonTagCamero: // 摄像头
- {
- if (toolButton.isSelected) { // 打开
- [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeCamera];
- }
- else { // 关闭
-
- [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeCamera];
- }
- }
- break;
- case MainToolButtonTagShare: // 老师无此状态操作
- {
-
- }
- break;
- case MainToolButtonTagPercent:
- {
- // [self showProgressView];
- }
- break;
- default:
- break;
- }
- }
- else { // 操作学生
- switch (tag) {
- case MainToolButtonTagMic:
- {
- if (toolButton.isSelected) { // 打开
- self.alertView = [TXClassRoomAlertView shareInstance];
- [self.alertView configWithTitle:@"提示" desc:@"确认打开学生的麦克风吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
-
- } confirm:^{
- [[ClassroomService sharedService] enableDevice:YES type:DeviceTypeMicrophone songId:0 soundVolume:0 forUser:member.userId];
- }];
- }
- else { // 关闭
-
- self.alertView = [TXClassRoomAlertView shareInstance];
- [self.alertView configWithTitle:@"提示" desc:@"确认关闭学生的麦克风吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
-
- } confirm:^{
- [[ClassroomService sharedService] enableDevice:NO type:DeviceTypeMicrophone songId:0 soundVolume:0 forUser:member.userId];
- }];
- }
- }
- break;
- case MainToolButtonTagCamero:
- {
- if (toolButton.isSelected) { // 打开
-
- self.alertView = [TXClassRoomAlertView shareInstance];
- [self.alertView configWithTitle:@"提示" desc:@"邀请学生打开摄像头吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
-
- } confirm:^{
- [[ClassroomService sharedService] enableDevice:YES type:DeviceTypeCamera songId:0 soundVolume:0 forUser:member.userId];
- }];
- }
- else { // 关闭
-
- self.alertView = [TXClassRoomAlertView shareInstance];
- [self.alertView configWithTitle:@"提示" desc:@"确认关闭学生的摄像头吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
-
- } confirm:^{
- [[ClassroomService sharedService] enableDevice:NO type:DeviceTypeCamera songId:0 soundVolume:0 forUser:member.userId];
- }];
- }
- }
- break;
- case MainToolButtonTagShare:
- {
- if (toolButton.isSelected) { // 下台 显示老师
- // 停止伴奏和节拍器
- [self resetPlayBeatAndAccompany];
- // 之前共享的学生切换成小流
- [self exchangePreStudentToTinySteam];
- [self.containerView refreshToolView];
- [ClassroomService sharedService].currentRoom.currentDisplayType = DisplayTeacher;
- [ClassroomService sharedService].currentRoom.currentDisplayURI = [ClassroomService sharedService].currentRoom.currentMember.userId;
- [[ClassroomService sharedService] displayTeacher];
- [self.containerView containerViewRenderView:[ClassroomService sharedService].currentRoom.currentMember];
- [self.videoListView showTeacherPrompt:YES];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self renderMainContainerView];
- });
- }
- else { // 上台共享学生
- // 停止伴奏和节拍器
- [self resetPlayBeatAndAccompany];
- // 如果之前显示的白板 关闭掉
- self.toolView.isVideoDisplay = YES;
-
- [self.whiteboardListView removeFromSuperview];
- [ClassroomService sharedService].currentRoom.shareUserId = member.userId;
- [self.containerView refreshToolView];
- [[ClassroomService sharedService] displayStudent:member.userId];
- [self.containerView refreshShareStatus];
- [self.videoListView showTeacherPrompt:NO];
- if (member.handUpOn) {
- [[ClassroomService sharedService] enableDevice:NO type:DeviceTypeHandup songId:0 soundVolume:0 forUser:member.userId];
- }
- }
- }
- break;
- case MainToolButtonTagPercent:
- {
- // [self showProgressView];
- }
- break;
- default:
- break;
- }
- }
- }
- - (void)resetPlayBeatAndAccompany {
- if ([ClassroomService sharedService].currentRoom.isPlaySong) {
- DeviceType type = self.isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
- [[ClassroomService sharedService] enableMutilMemberDevice:NO type:type songId:[self.songId intValue] soundVolume:self.soundVolume forUser:@""];
- // 重置伴奏按钮
- self.accompanyView.isPlaying = NO;
- }
-
- if ([ClassroomService sharedService].currentRoom.isPlayBeat) {
- NSDictionary *parm = @{@"enable": @(NO),
- @"rate" : @(0),
- @"customType" : @(0),
- @"playVolume" : @(0),
- @"userId" : @"",
- };
-
- [[ClassroomService sharedService] enablePlayMessage:NO content:[parm mj_JSONString] userId:@""];
- [ClassroomService sharedService].currentRoom.isPlayBeat = NO;
- }
-
- [self unplayBeatNodeRefreshStream]; // 刷新音频流播放
- }
- - (void)changeSongPlayDisplay:(NSString *)userId {
- // 默认显示第一个学生的视频 单个操作不再次刷新主屏
- if (self.videoListView.videoDataSource.count >= 1 && [NSString isEmptyString:userId]) {
- for (RoomMember *member in self.videoListView.videoDataSource) {
- if (member.role == RoleStudent) {
- [self videoListView:nil didTap:member];
- break;
- }
- }
- }
- else if (![NSString isEmptyString:userId]) {
- [ClassroomService sharedService].currentRoom.currentPlayUserId = userId;
- [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:userId];
- }
- }
- - (void)showProgressView {
- [self.progressView showView:self.songName songId:self.songId];
- }
- - (void)exchangePreStudentToTinySteam {
- [ClassroomService sharedService].currentRoom.shareUserId = @"";
- }
- #pragma mark ---- TXRTCServiceDelegate
- - (void)didReportNetworkQuality:(TRTCQuality)quality remoteQuality:(NSArray<TRTCQualityInfo *> *)remoteQuality {
- if (quality >= 5) { // 网络质量不佳
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.view addSubview:self.networkLabel];
- [self.view bringSubviewToFront:self.networkLabel];
- self.networkLabel.hidden = NO;
- self.networkLabel.text = @"当前通话连接质量不佳";
- });
- }
- else { // 正常
- dispatch_async(dispatch_get_main_queue(), ^{
- self.networkLabel.hidden = YES;
- self.networkLabel.text = @"";
- [self.networkLabel removeFromSuperview];
- });
- }
- [self showNetworkingStatus:quality remoteQuality:remoteQuality];
- }
- - (void)showNetworkingStatus:(TRTCQuality)quality remoteQuality:(NSArray<TRTCQualityInfo *> *)remoteQuality {
- dispatch_async(dispatch_get_main_queue(), ^{
- // 本地
- NSString *currentUserID = [ClassroomService sharedService].currentRoom.currentMemberId;
- if ([self.containerView.member.userId isEqualToString:currentUserID]) {
- [self.containerView.displayView updateUserQualityNetWorkingStatus:[self getNetStatusWithQuality:quality]];
- }
- [self.videoListView updateUserQuality:currentUserID netWorkingStatus:[self getNetStatusWithQuality:quality]];
- // 更新full
- if (self.squareOn) {
- [self.squareView updateUserQuality:currentUserID netWorkingStatus:[self getNetStatusWithQuality:quality]];
- }
- // 远端
- for (TRTCQualityInfo *info in remoteQuality) {
- NSString *userId = info.userId;
- [self.videoListView updateUserQuality:userId netWorkingStatus:[self getNetStatusWithQuality:info.quality]];
- if ([info.userId isEqualToString:self.containerView.member.userId]) {
- [self.containerView.displayView updateUserQualityNetWorkingStatus:[self getNetStatusWithQuality:info.quality]];
- }
- // 更新full
- if (self.squareOn) {
- [self.squareView updateUserQuality:userId netWorkingStatus:[self getNetStatusWithQuality:info.quality]];
- }
- }
-
- });
- }
- - (TXNetWorkingStatus)getNetStatusWithQuality:(TRTCQuality)quality {
- TXNetWorkingStatus status = TXNetWorkingStatus_Full;
- if (quality == 1 || quality == 2) {
- status = TXNetWorkingStatus_Full;
- }
- else if (quality == 3) {
- status = TXNetWorkingStatus_Good;
- }
- else if (quality == 4) {
- status = TXNetWorkingStatus_Nomal;
- }
- else if (quality == 5) {
- status = TXNetWorkingStatus_Bad;
- }
- else { //
- status = TXNetWorkingStatus_Poor;
- }
- return status;
- }
- - (void)didReportUserVolume:(NSArray<TRTCVolumeInfo *> *)userVolumes {
- NSString *currentUserID = [ClassroomService sharedService].currentRoom.currentMemberId;
- for (TRTCVolumeInfo *info in userVolumes) {
- NSString *userId = info.userId;
- if ([NSString isEmptyString:userId]) {
- userId = currentUserID;
- }
- [self.videoListView updateMicStatus:userId volume:info.volume];
- // 更新title
- if ([currentUserID isEqualToString:userId]) {
- [self.titleView updateUserVolume:info.volume];
- }
- // 更新container
- if ([self.containerView.member.userId isEqualToString:userId]) {
- [self.containerView updateUserVolume:info.volume];
- }
- // 更新full
- if (self.squareOn) {
- [self.squareView updateMicStatus:userId volume:info.volume];
- }
- }
- }
- #pragma mark ------- 教学工具
- - (TXTeachToolView *)toolView {
- if (!_toolView) {
- _toolView = [[TXTeachToolView alloc] init];
- _toolView.delegate = self;
- }
- return _toolView;
- }
- - (AccompanyProgressView *)progressView {
- if (!_progressView) {
- _progressView = [[AccompanyProgressView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, KLandscapeHeight)];
- }
- return _progressView;
- }
- - (void)teachToolView:(UIButton *)button didTapAtTag:(TeachToolTag)tag {
- switch (tag) {
- case TeachToolTagWhiteboard:
- {
- // 停止伴奏和节拍器
- [self resetPlayBeatAndAccompany];
-
- self.hud = [self createProgressHUD];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.hud hideAnimated:YES];
- button.selected = YES;
- self.toolView.isVideoDisplay = NO;
- if ([ClassroomService sharedService].currentRoom.randomNumeric == 0) {
- [self.view addSubview:self.whiteboardListView];
- }
- self.whiteboardListView.isOpen = NO;
- // 之前共享的学生切换成小流
- [self exchangePreStudentToTinySteam];
- [TRTC_MANAGER cancleRenderUserVideo:[ClassroomService sharedService].currentRoom.currentDisplayURI];
- [ClassroomService sharedService].currentRoom.currentDisplayType = DisplayWhiteboard;
- [ClassroomService sharedService].currentRoom.currentDisplayURI = @"whiteboard";
- [[ClassroomService sharedService] displayWhiteboard:@"whiteboard"];
- [self renderMainContainerView];
- [self.videoListView showTeacherPrompt:NO];
- [self.whiteboardListView reloadDataSource];
- // 收起
- [self.toolView hiddenToolViewWithAnimation:YES];
- });
- }
- break;
- case TeachToolTagVideo:
- {
- // 停止伴奏和节拍器
- [self resetPlayBeatAndAccompany];
- button.selected = YES;
- self.toolView.isVideoDisplay = YES;
- // 收起
- [self.toolView hiddenToolViewWithAnimation:YES];
- // 之前共享的学生切换成小流
- [self exchangePreStudentToTinySteam];
- [ClassroomService sharedService].currentRoom.currentDisplayType = DisplayTeacher;
-
- [ClassroomService sharedService].currentRoom.currentDisplayURI = [ClassroomService sharedService].currentRoom.currentMember.userId;
- [[ClassroomService sharedService] displayTeacher];
- [self.containerView containerViewRenderView:[ClassroomService sharedService].currentRoom.currentMember];
- [self.videoListView showTeacherPrompt:YES];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self renderMainContainerView];
- });
- [self.whiteboardListView removeFromSuperview];
- }
- break;
- case TeachToolTagLibrary: // 选择伴奏曲库
- {
- [self.accompanyView showAccompanyView];
- }
- break;
- case TeachToolTagNode:
- {
- [self showNodeControlView];
- }
- break;
- default:
- break;
- }
- }
- #pragma mark - Getters & setters
- - (ClassroomTimerManager *)timeManager {
-
- if (!_timeManager) {
- _timeManager = [[ClassroomTimerManager alloc] initWithDelegate:self];
- _timeManager.autoClose = [ClassroomService sharedService].currentRoom.autoCloseFlag;
- // 统一15分钟关闭
- _timeManager.autoCloseNetworkRoomTime = [ClassroomService sharedService].currentRoom.autoCloseNetworkRoomTime;
- }
- return _timeManager;
- }
- - (TXTimeView *)timeView {
- if (!_timeView) {
- _timeView = [TXTimeView shareInstance];
- }
- return _timeView;
- }
- - (KSTipsView *)tipsView {
- if (!_tipsView) {
- _tipsView = [[KSTipsView alloc] initWithFrame:CGRectZero];
- }
- return _tipsView;
- }
- - (TXClassTitleView *)titleView {
- if (!_titleView) {
- _titleView = [[TXClassTitleView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, TitleViewHeight)];
- _titleView.delegate = self;
- }
- return _titleView;
- }
- - (TXClassroomVideoListView *)videoListView {
- if(!_videoListView) {
-
- CGFloat width = VIDEO_WIDTH + 20 + 10;
-
- CGFloat height = KLandscapeHeight;
-
- _videoListView = [[TXClassroomVideoListView alloc] initWithFrame:CGRectMake(KLandscapeWidth - width, 0, width, height)];
- _videoListView.delegate = self;
- }
- return _videoListView;
- }
- - (UIButton *)showButton {
- if (!_showButton) {
- _showButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _showButton.frame = CGRectMake(KLandscapeWidth-30, (KLandscapeHeight-30)/2.0, 30, 30);
- [_showButton setImage:[UIImage imageNamed:@"videoList_show"] forState:UIControlStateNormal];
- [_showButton addTarget:self action:@selector(showVideoList) forControlEvents:UIControlEventTouchUpInside];
- }
- return _showButton;
- }
- - (ClassMemberListView *)memberListView {
- if (!_memberListView) {
- _memberListView = [[ClassMemberListView alloc] initWithFrame:CGRectMake(KLandscapeWidth - PersonListViewWidth, 0, PersonListViewWidth, KLandscapeHeight)];
- _memberListView.delegate = self;
- }
- return _memberListView;
- }
- - (TXClassroomMainContainer *)containerView {
- if (!_containerView) {
- _containerView = [[TXClassroomMainContainer alloc] initWithFrame:[self mainContainerViewFrame]];
- _containerView.delegate = self;
- }
- return _containerView;
- }
- - (TXChatAreaView *)chatAreaView {
- if(!_chatAreaView) {
- _chatAreaView = [[TXChatAreaView alloc] initWithFrame:CGRectMake(KLandscapeWidth- 300,0, 300, KLandscapeHeight) chatGroupId:[ClassroomService sharedService].currentRoom.roomId];
- }
- return _chatAreaView;
- }
- - (KSWhiteboardControl *)wBoardCtrl {
- if (!_wBoardCtrl) {
- CGRect frame = [self getWBoardFrame];
- _wBoardCtrl = [[KSWhiteboardControl alloc] initWithDelegate:self viewFrame:frame];
- NSLog(@"----%@", [ClassroomService sharedService].currentRoom.roomId);
- _wBoardCtrl.randomNumeric = [ClassroomService sharedService].currentRoom.randomNumeric;
- NSString *roomId = [ClassroomService sharedService].currentRoom.roomId;
- if ([roomId containsString:@"S"] || [roomId containsString:@"I"]) {
- roomId = [roomId substringFromIndex:1];
- }
- _wBoardCtrl.roomId = roomId;
- _wBoardCtrl.subjectId = self.subjectId;
- [_wBoardCtrl moveToSuperView:self.view];
- }
- return _wBoardCtrl;
- }
- - (WhiteboardListView *)whiteboardListView {
- if (!_whiteboardListView) {
- _whiteboardListView = [[WhiteboardListView alloc] initWithFrame:CGRectMake(-140+iPhoneXSafeTopMargin, 0, WhiteboardListWidth, KLandscapeHeight)];
- _whiteboardListView.delegate = self;
- _whiteboardListView.whiteboardCtrl = self.wBoardCtrl;
- }
- return _whiteboardListView;
- }
- - (TXFullVideoView *)squareView {
- if (!_squareView) {
- _squareView = [[TXFullVideoView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, KLandscapeHeight)];
- _squareView.delegate = self;
- }
- return _squareView;
- }
- #pragma mark ----- 宫格模式
- // 点击视频
- - (void)fullVideoListView:(TXFullVideoView *)view didTap:(RoomMember *)member {
-
- // 放大当前视频
- if([[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
- if (member.cameraEnable) {
- self.maskView.closeCameraView.hidden = YES;
- }
- else {
- self.maskView.closeCameraView.hidden = NO;
- }
- [TRTC_MANAGER renderLocalUserInView:self.maskView.maskVideoView isCameraEnable:member.cameraEnable];
- }else {
- self.maskView.closeCameraView.hidden = YES;
- [TRTC_MANAGER renderRemoteUser:member.userId inView:self.maskView.maskVideoView];
- if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
- [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:member.userId];
- [ClassroomService sharedService].currentRoom.currentPlayUserId = member.userId;
- }
- }
- [self.view addSubview:self.maskView];
- }
- // 关闭宫格模式
- - (void)cancleFullVideoList {
- self.squareOn = NO;
- [self.squareView removeFromSuperview];
- if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
- [ClassroomService sharedService].currentRoom.currentPlayUserId = self.squareView.currentPlayUserId;
- NSString *userId = [ClassroomService sharedService].currentRoom.currentPlayUserId;
- [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:userId];
- }
- [self renderMainContainerView];
- [self.videoListView reloadVideoList];
- }
- - (VideoMaskView *)maskView {
- if (!_maskView) {
- CGFloat width = (KLandscapeWidth);
- CGRect frame = CGRectMake(0, 0, width, KLandscapeHeight);
- _maskView = [[VideoMaskView alloc] initWithFrame:frame];
- [_maskView addDismisTarget:self action:@selector(dismissMaskViewEvent)];
- }
- return _maskView;
- }
- - (void)dismissMaskViewEvent {
- // 切换成小流
- [self removeMaskViewIfNeed];
- [self.squareView showVideoList];
- self.squareView.displayUserId = @"";
- }
- - (void)removeMaskViewIfNeed {
- [self.maskView removeFromSuperview];
- _maskView = nil;
- }
- #pragma mark --------- 主动关闭教室
- - (void)showCouseCloseAlert {
-
- // 判断如果课程结束、不能进行此操作
- if (self.timeManager.showCloseTips) {
- [self.tipsView showTipsMessage:@"已结束课程不可使用该功能" inView:self.view];
- return;
- }
-
- self.closeCourseAlert = [KSCloseCourseView shareInstanceShowInView:self.view];
- self.imageArray = [NSMutableArray array];
- self.imageAsset = [NSMutableArray array];
- [self createImageButtonAndPhotosButton];
-
- MJWeakSelf;
- [self.closeCourseAlert sureCallback:^(NSString * _Nonnull message) {
- [weakSelf submitCloseMessge:message];
- }];
- [self.closeCourseAlert showAlert];
- }
- /**
- 图片和按钮的布局
- */
- #pragma marl 图片和按钮布局
- - (void)createImageButtonAndPhotosButton {
- for (UIView *subView in self.closeCourseAlert.imageContentView.subviews) {
- [subView removeFromSuperview];
- }
- if (self.imageArray.count == 0) {
- self.closeCourseAlert.hasChooseImage = NO;
- }
- else {
- self.closeCourseAlert.hasChooseImage = YES;
- }
- CGFloat space = 10;
- CGFloat buttonWidth = (COURSEVIEWWIDTH - KBUTTON_LEFTSPACE * 2 - space * 2) / 3.0f;
- CGFloat buttonHeight = 80;
- NSInteger section = self.imageArray.count/3 + 1;
- if (self.imageArray.count==MAXPHOTONUMBER) {
- section = MAXPHOTONUMBER / 3;
- }
- CGFloat currentX = 0;
- CGFloat currentY = 0;
- for (NSInteger i = 0; i < self.imageArray.count; i++) {
- currentX = i % 3 * (buttonWidth + space);
- currentY = i / 3 * (buttonHeight + space);
- UIImage *image = self.imageArray [i];
-
- CGRect frame = CGRectMake(currentX, currentY, buttonWidth, buttonHeight);
- MJWeakSelf;
- KSImageDisplayView *displayView = [KSImageDisplayView shareInstance];
- displayView.frame = frame;
- displayView.tag = 1000 + i;
- [displayView displayImage:image callback:^(IMAGEACTION action, NSInteger viewIndex) {
- if (action == IMAGEACTION_DISPLAY) {
- [weakSelf displayImageIndex:viewIndex];
- }
- else {
- [weakSelf deleteImage:viewIndex];
- }
- }];
- [self.closeCourseAlert.imageContentView addSubview:displayView];
- }
- currentX = self.imageArray .count % 3 * (buttonWidth + space);
- if (self.imageArray.count != MAXPHOTONUMBER) {
- //计算下一个添加按钮位置
- if (self.imageArray.count % 3 == 0) {
- currentY = (self.imageArray.count+1) / 3 * (buttonHeight + space);
- }
- UIButton *cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
- cameraButton.frame = CGRectMake(currentX, currentY, buttonWidth, buttonHeight);
- cameraButton.layer.cornerRadius = 5.0f;
- [cameraButton setImage:[UIImage imageNamed:@"common_image_choose"] forState:UIControlStateNormal];
- [cameraButton setBackgroundColor:[UIColor clearColor]];
- [cameraButton addTarget:self action:@selector(addImgAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.closeCourseAlert.imageContentView addSubview:cameraButton];
- }
- }
- - (void)displayImageIndex:(NSInteger)fileIndex {
- self.isPushChooseView = YES;
- // 展示大图
- LLPhotoBrowser *photoBrowser = [[LLPhotoBrowser alloc] initWithImages:self.imageArray currentIndex:fileIndex];
- photoBrowser.delegate = self;
- photoBrowser.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:photoBrowser animated:YES completion:nil];
- }
- - (void)deleteImage:(NSInteger)fileIndex {
- [self.imageArray removeObjectAtIndex:fileIndex];
- [self.imageAsset removeObjectAtIndex:fileIndex];
- [self createImageButtonAndPhotosButton];
- }
- #pragma mark 点击+按钮
- - (void)addImgAction:(UIButton *)sender {
- [self.view endEditing:YES];
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:IS_IPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
- [alertVC addAction:[UIAlertAction actionWithTitle:@"相机拍摄" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // 调用相机
- self.isPushChooseView = YES;
- [self takePhotos];
- }]];
-
- [alertVC addAction:[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- // 调用相册
- self.isPushChooseView = YES;
- [self pushImagePickerController];
-
- }]];
- [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }]];
- alertVC.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:alertVC animated:true completion:nil];
- }
- - (void)takePhotos {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = MAXPHOTONUMBER;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.imageArray = [self.imageArray mutableCopy];
- self.mediaManager.imageAsset = [self.imageAsset mutableCopy];
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- [weakSelf displayChooseImage:imageArray imageAsset:imageAsset];
- }];
- [self.mediaManager takePhoto];
- }
- - (void)pushImagePickerController {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = MAXPHOTONUMBER;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.imageArray = [self.imageArray mutableCopy];
- self.mediaManager.imageAsset = [self.imageAsset mutableCopy];
- self.mediaManager.needCropImage = NO;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- [weakSelf displayChooseImage:imageArray imageAsset:imageAsset];
- }];
- [self.mediaManager pushImagePickerController];
- }
- - (void)displayChooseImage:(NSMutableArray *)imageArray imageAsset:(NSMutableArray *)imageAsset {
-
- self.imageArray = [imageArray mutableCopy];
- self.imageAsset = [imageAsset mutableCopy];
- // 重新布局
- [self createImageButtonAndPhotosButton];
- }
- #pragma mark -- LLPhotoBrowserDelegate
- - (void)photoBrowser:(LLPhotoBrowser *)photoBrowser backImages:(NSMutableArray *)images {
- NSMutableArray * backImgArray = [images mutableCopy];
- NSMutableArray *imageArray = [NSMutableArray array];
- NSMutableArray *imageAsset = [NSMutableArray array];
- for (NSInteger i = 0; i < self.imageArray.count; i++) {
- UIImage *imagePic = self.imageArray[i];
- if ([backImgArray containsObject:imagePic]) { // 包含
- [imageArray addObject:imagePic];
- [imageAsset addObject:self.imageAsset[i]];
- }
- }
- self.imageArray = [imageArray mutableCopy];
- self.imageAsset = [imageAsset mutableCopy];
- //布局
- [self createImageButtonAndPhotosButton];
- }
- - (void)submitCloseMessge:(NSString *)message {
- self.hud = [self createProgressHUD];
- // 先上传图片
- NSMutableArray *imageDataArray = [NSMutableArray array];
- for (UIImage *image in self.imageArray) {
- NSData *imgData = [UIImage turnsImaegDataByImage:image];
- [imageDataArray addObject:imgData];
- }
-
- [[KSUploadManager shareInstance] configBucketName:@"daya"];
- [[KSUploadManager shareInstance] mutilUploadImage:imageDataArray fileName:@"onlineClassroomImg" successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSMutableArray *urlArray = [NSMutableArray array];
- for (NSString *url in fileUrlArray) {
- [urlArray addObject:url];
- }
- // 再提交申诉
- NSString *attachments = [urlArray componentsJoinedByString:@","];
- [self feedbackAction:attachments message:message];
- } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
- [self.hud hideAnimated:YES];
- if (![NSString isEmptyString:descMessaeg]) {
- [self.tipsView showTipsMessage:descMessaeg inView:self.view];
- }
- }];
- }
- - (void)feedbackAction:(NSString *)attachments message:(NSString *)message {
- }
- #pragma mark ------ 创建MBProgress
- - (MBProgressHUD *)createProgressHUD {
- [MBProgressHUD hideHUD];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeIndeterminate;
- hud.contentColor = [UIColor whiteColor];
- hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
- hud.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
- return hud;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- #pragma mark ----- accompany view
- - (AccompanyView *)accompanyView {
- if (!_accompanyView) {
- _accompanyView = [[AccompanyView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, KLandscapeHeight)];
- _accompanyView.volume = self.soundVolume;
- _accompanyView.hideDownloadStatus = YES;
- MJWeakSelf;
- [_accompanyView accompanyPlayAction:^(ACCOMPANYACTION action, NSString * _Nullable songId, NSString * _Nullable songName, BOOL isAccompany, NSString * _Nullable songUrl) {
- [weakSelf accompanyViewAction:action songId:songId songName:songName isAccompany:isAccompany songUrl:songUrl];
- }];
- }
- return _accompanyView;
- }
- - (void)accompanyViewAction:(ACCOMPANYACTION)action songId:(NSString *)songId songName:(NSString *)songName isAccompany:(BOOL)isAccompany songUrl:(NSString *)songUrl {
-
- NSLog(@"------------- song id %@", songId);
- self.soundVolume = self.accompanyView.volume;
- NSLog(@"-------sound volume %zd", self.soundVolume);
- if (action == ACCOMPANYACTION_ADDSONG) {
- // 添加伴奏
- [self.coursewareView showView];
- }
- else if (action == ACCOMPANYACTION_STOP) {
-
- DeviceType type = self.isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
- // 取消记录当前播放曲目
- [[ClassroomService sharedService] enableMutilMemberDevice:NO type:type songId:[songId intValue] soundVolume:self.soundVolume forUser:@""];
-
- [ClassroomService sharedService].currentRoom.isPlaySong = NO;
- [self unplayBeatNodeRefreshStream]; // 刷新音频流播放
- }
- else if (action == ACCOMPANYACTION_PLAYSONG) {
- // 如果之前有播放节拍器
- [ClassroomService sharedService].currentRoom.isPlaySong = YES;
- if ([ClassroomService sharedService].currentRoom.isPlayBeat) {
- [ClassroomService sharedService].currentRoom.isPlayBeat = NO;
- NSDictionary *parm = @{@"enable": @(NO),
- @"rate" : @(0),
- @"customType" : @(0),
- @"playVolume" : @(0),
- @"userId" : @"",
- };
- [[ClassroomService sharedService] enablePlayMessage:NO content:[parm mj_JSONString] userId:@""];
- }
- DeviceType type = isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
- // 记录当前播放曲目
- if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
- NSString *userId = [ClassroomService sharedService].currentRoom.shareUserId;
- [[ClassroomService sharedService] enableMutilMemberDevice:YES type:type songId:[songId intValue] soundVolume:self.soundVolume forUser:userId];
- [self changeSongPlayDisplay:userId];
- }
- else {
- [[ClassroomService sharedService] enableMutilMemberDevice:YES type:type songId:[songId intValue] soundVolume:self.soundVolume forUser:@""];
- [self changeSongPlayDisplay:@""];
- }
-
- [ClassroomService sharedService].currentRoom.isPlaySong = YES;
- // 同步主屏显示
- [self recordSongMessageWithSongId:songId songName:songName isAccompany:isAccompany songUrl:songUrl];
- }
- else if (action == ACCOMPANYACTION_DISPLAY) { // 显示弹窗
- // [self.progressView showView:songName songId:songId];
- }
- else if (action == ACCOMPANYACTION_CHOOSE) { // 选择的伴奏
- [self recordSongMessageWithSongId:songId songName:songName isAccompany:isAccompany songUrl:songUrl];
- }
- else if (action == ACCOMPANYACTION_MODIFY_VOLUME) {
- // TXAudioEffectManager *audioManager = [TRTCCloud sharedInstance].getAudioEffectManager;
- // [audioManager setAllMusicVolume:self.soundVolume];
- }
- }
- - (void)notiferStudentDownload:(NSString *)songId songUrl:(NSString *)songUrl accompanyUrl:(NSString *)accompanyUrl songName:(NSString *)songName {
- [self.coursewareView hideView];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- for (RoomMember *member in [ClassroomService sharedService].currentRoom.memberList) {
-
- if (member.songMessage.count == 0) { // 如果没有选择过曲目
-
- self.songName = songName;
- self.songId = songId;
- if ([NSString isEmptyString:songUrl]) {
- self.isAccompany = YES;
- self.songUrl = accompanyUrl;
- }
- else {
- self.isAccompany = NO;
- self.songUrl = songUrl;
- }
-
- member.accompanimentPlayStatus = NO;
- member.downStatus = 0;
- member.playStatus = NO;
- member.url = songUrl;
- member.mp3Url = accompanyUrl;
- member.examSongName = songName;
- member.musicScoreAccompanimentId = [songId intValue];
-
- ClassSongMessage *songModel = [[ClassSongMessage alloc] init];
- songModel.musicScoreAccompanimentId = [songId intValue];
- songModel.accompanimentPlayStatus = NO;
- songModel.downStatus = 0;
- songModel.playStatus = NO;
- songModel.url = songUrl;
- songModel.mp3Url = accompanyUrl;
- songModel.examSongName = songName;
- [member.songMessage addObject:songModel];
- }
- else {
- BOOL hasDownloadSong = NO;
- for (ClassSongMessage *songModel in member.songMessage) {
- if (songModel.musicScoreAccompanimentId == [songId intValue]) {
- hasDownloadSong = YES;
- break;
- }
- }
- if (hasDownloadSong == NO) { // 如果没有下载 添加到列表
- ClassSongMessage *songModel = [[ClassSongMessage alloc] init];
- songModel.musicScoreAccompanimentId = [songId intValue];
- songModel.accompanimentPlayStatus = NO;
- songModel.downStatus = 0;
- songModel.playStatus = NO;
- songModel.url = songUrl;
- songModel.mp3Url = accompanyUrl;
- songModel.examSongName = songName;
- [member.songMessage addObject:songModel];
- }
- }
- }
-
- dispatch_main_async_safe(^{
- // 刷新选择窗
- [self.accompanyView refreshView];
- if (![NSString isEmptyString:self.songName]) {
- [self.containerView.toolView showDownloadButtonWithSongName:self.songName isAccompany:self.isAccompany]; // 弹出 当前曲目的下载状态框
- }
- // 通知
- [[ClassroomService sharedService] pushDownloadMusicScoreMsgWithSongId:songId];
- });
- });
- }
- - (void)recordSongMessageWithSongId:(NSString *)songId songName:(NSString *)songName isAccompany:(BOOL)isAccompany songUrl:(NSString *)songUrl {
- self.songId = songId;
- self.songUrl = songUrl;
- self.songName = songName;
- self.isAccompany = isAccompany;
- [self.containerView.toolView showDownloadButtonWithSongName:songName isAccompany:isAccompany]; // 弹出 当前曲目的下载状态框
- }
- #pragma mark ----- 首页弹幕聊天
- - (TXDanMuView *)danView {
- if (!_danView) {
- _danView = [[TXDanMuView alloc] initWithFrame:CGRectMake(38, KLandscapeHeight - 160 - 20, 260, 160) chatGroupId:[ClassroomService sharedService].currentRoom.roomId];
- }
- return _danView;
- }
- - (CoursewareAlertView *)coursewareView {
- if (!_coursewareView) {
- _coursewareView = [CoursewareAlertView shareInstance];
- [_coursewareView configUI];
- MJWeakSelf;
- [_coursewareView chooseCoursewareCallback:^(NSString * _Nonnull musicUrl, NSString * _Nonnull musicName, NSString * _Nonnull songId) {
-
- [weakSelf notiferStudentDownload:songId songUrl:musicUrl accompanyUrl:nil songName:musicName];
- }];
- }
- return _coursewareView;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|