TXClassroomViewController.m 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105
  1. //
  2. // TXClassroomViewController.m
  3. // TeacherDaya
  4. //
  5. // Created by 王智 on 2023/4/14.
  6. // Copyright © 2023 DayaMusic. All rights reserved.
  7. //
  8. #import "TXClassroomViewController.h"
  9. #import "TXClassTitleView.h"
  10. #import "TXClassroomVideoListView.h"
  11. #import "TXClassroomMainContainer.h"
  12. #import "TXClassRoomAlertView.h"
  13. #import "LoginHelper.h"
  14. #import "TXRTCService.h"
  15. // 成员列表
  16. #import "ClassMemberListView.h"
  17. // 聊天列表
  18. #import "TXChatAreaView.h"
  19. #import "Classroom.h"
  20. #import "ClassroomService.h"
  21. #import <MBProgressHUD/MBProgressHUD.h>
  22. #import "AppDelegate.h"
  23. #import "KSWhiteboardControl.h"
  24. #import "UIDevice+TFDevice.h"
  25. #import "LocalRenderManager.h"
  26. #import "NSDate+Transform.h"
  27. #import "WhiteboardListView.h"
  28. #import "NewTXMetronomeAlertView.h"
  29. #import "UIViewController+zhStatusBarStyle.h"
  30. #import "KSTipsView.h"
  31. // 时间渲染
  32. #import "ClassroomTimerManager.h"
  33. //// 宫格视图
  34. #import "TXFullVideoView.h"
  35. #import "VideoMaskView.h"
  36. #import "TXTeachToolView.h"
  37. #import "AccompanyProgressView.h"
  38. #import "SongListViewController.h"
  39. #import "CustomNavViewController.h"
  40. #import "KSCloseCourseView.h"
  41. #import "KSImageDisplayView.h"
  42. #import "LLPhotoBrowser.h"
  43. #import "KSMediaManager.h"
  44. #import "UIImage+ResizeImage.h"
  45. #import "AccompanyView.h"
  46. #import "TXLiteAVSDK_Professional/TXLiteAVSDK.h"
  47. #import "KSRemoteUserManager.h"
  48. #import "TXQuitChooseView.h"
  49. #import "TXDanMuView.h"
  50. #import "TXTimeView.h"
  51. #import "CoursewareAlertView.h"
  52. #define MAXBIGPHOTONUMBER (3)
  53. #define MAXPHOTONUMBER (3)
  54. #define COLUMNNUMBER (3)
  55. #define KBUTTON_LEFTSPACE (16)
  56. #define TitleViewHeight (66)
  57. #define PersonListViewWidth (280)
  58. #define WhiteboardListWidth (140+33)
  59. #define TTimeLableWidth (180)
  60. #define TTimeLableHeight (20)
  61. // 需添加TRTC 回调
  62. @interface TXClassroomViewController ()<UIGestureRecognizerDelegate,TXClassTitleViewDelegate,KSWhiteboardControlDelegate,ClassroomDelegate,TXClassroomMainContainerDelegate,TXClassVideoListViewDelegate,ClassMemberListViewDelegate,WhiteboardListViewDelegate,ClassroomTimerManagerDelegate,TXFullVideoViewDelegate,TeachToolViewDelegate,LLPhotoBrowserDelegate,TRTCCloudDelegate, TXRTCServiceDelegate>
  63. @property (nonatomic, strong) KSMediaManager *mediaManager;
  64. @property (nonatomic, strong) NSMutableArray *imageArray; // 图片数组
  65. @property (nonatomic, strong) NSMutableArray *imageAsset; // 图片 asset
  66. @property (nonatomic, strong) TXClassTitleView *titleView;
  67. @property (nonatomic, strong) TXClassroomMainContainer *containerView;
  68. @property (nonatomic, strong) TXClassroomVideoListView *videoListView;
  69. @property (nonatomic, strong) ClassMemberListView *memberListView;
  70. @property (nonatomic, strong) KSWhiteboardControl *wBoardCtrl;
  71. // 聊天的area
  72. @property (nonatomic, strong) TXChatAreaView *chatAreaView;
  73. @property (nonatomic, strong) MBProgressHUD *hud;
  74. @property (nonatomic, strong) WhiteboardListView *whiteboardListView;
  75. @property (nonatomic, strong) UILabel *networkLabel;
  76. @property (nonatomic, assign) BOOL cancleAlert;
  77. @property (nonatomic, assign) BOOL isQuitRoom; // 是否正在退出房间
  78. @property (nonatomic, assign) BOOL hasShowAlert;
  79. @property (nonatomic, assign) BOOL isChat;
  80. @property (nonatomic, strong) NewTXMetronomeAlertView *controlView;
  81. @property (nonatomic, strong) KSTipsView *tipsView;
  82. @property (nonatomic, strong) ClassroomTimerManager *timeManager;
  83. @property (nonatomic, strong) TXFullVideoView *squareView; // 宫格视频
  84. @property (nonatomic, assign) BOOL squareOn; // 是否开启宫格模式
  85. @property (nonatomic, strong) VideoMaskView *maskView;
  86. @property (nonatomic, strong) NSString *fileUrl;
  87. @property (nonatomic, strong) TXTeachToolView *toolView;
  88. @property (nonatomic, strong) AccompanyProgressView *progressView;
  89. @property (nonatomic, strong) KSCloseCourseView *closeCourseAlert;
  90. @property (nonatomic, strong) TXClassRoomAlertView *alertView;
  91. @property (nonatomic, strong) AccompanyView *accompanyView;
  92. @property (nonatomic, strong) NSString *songName; // 当前选择的曲目名称
  93. @property (nonatomic, strong) NSString *songId; // 当前选择的曲目id
  94. @property (nonatomic, strong) NSString *songUrl; // 当前播放的url
  95. @property (nonatomic, assign) BOOL isAccompany; // 当前选择的是否为伴奏
  96. @property (nonatomic, assign) NSInteger soundVolume; // 伴奏音量
  97. @property (nonatomic, strong) CoursewareAlertView *coursewareView;
  98. @property (nonatomic, strong) TRTCCloud *engine;
  99. /** 节拍类型 */
  100. @property (nonatomic, assign) KSMetronomeType type;
  101. /** 播放速率,范围40~240 */
  102. @property (nonatomic, assign) int rate;
  103. // 播放节拍器音量
  104. @property (nonatomic, assign) NSInteger volome;
  105. // 是否隐藏了列表
  106. @property (nonatomic, assign) BOOL videoListHidden;
  107. @property (nonatomic, strong) TXDanMuView *danView;
  108. @property (nonatomic, strong) TXTimeView *timeView;
  109. @property (nonatomic, strong) UIButton *showButton;
  110. @end
  111. @implementation TXClassroomViewController
  112. -(BOOL)prefersHomeIndicatorAutoHidden {
  113. return YES;
  114. }
  115. - (void)changeOrientation:(BOOL)isLandScape {
  116. if (isLandScape) {
  117. // 切换到横屏
  118. if (IS_IPAD) {
  119. self.zh_statusBarHidden = YES;
  120. }
  121. AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
  122. delegate.allowAutoRotate = YES;
  123. [UIDevice switchNewOrientation:UIInterfaceOrientationLandscapeRight inController:self];
  124. }
  125. else {
  126. // 切换到横屏
  127. AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
  128. delegate.allowAutoRotate = NO;
  129. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  130. if (IS_IPAD) {
  131. self.zh_statusBarHidden = NO;
  132. }
  133. [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait inController:self];
  134. });
  135. }
  136. }
  137. - (void)viewWillAppear:(BOOL)animated {
  138. [super viewWillAppear:animated];
  139. // 切换到横屏
  140. [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
  141. _isPushChooseView = NO;
  142. if (_isPushChooseView) {
  143. NSLog(@"-----");
  144. }
  145. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  146. }
  147. - (void)viewWillDisappear:(BOOL)animated {
  148. [super viewWillDisappear:animated];
  149. // 竖屏
  150. [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
  151. if (_isPushChooseView == NO) {
  152. [self hideAlertView];
  153. [self judgeShowAlert];
  154. }
  155. [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
  156. }
  157. - (void)hideAlertView {
  158. if (self.alertView && self.alertView.isShow) {
  159. [self.alertView dismissAlertView];
  160. }
  161. [self.memberListView hiddenAlert];
  162. if (_accompanyView && _accompanyView.isShow) {
  163. [_accompanyView dismissAlertView];
  164. }
  165. if (self.controlView && self.controlView.isShow) {
  166. [self.controlView dismissAlertView];
  167. }
  168. }
  169. - (void)judgeShowAlert {
  170. if (self.cancleAlert || self.hasShowAlert) {
  171. return;
  172. }
  173. if (![NSString isEmptyString:self.classEndTime]) {
  174. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  175. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  176. NSDate *endDate = [dateFormatter dateFromString:self.classEndTime];
  177. NSDate *currentDate = [NSDate date];
  178. NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:endDate];
  179. if (timeInterval >= 0) { // 课程结束弹出评价
  180. self.hasShowAlert = YES;
  181. [[NSNotificationCenter defaultCenter] postNotificationName:@"showEvaluateAlert" object:self.courseId];
  182. }
  183. }
  184. }
  185. - (void)configBeatConfig {
  186. self.type = KSMetronomeType4V4;
  187. self.volome = 100;
  188. self.rate = 90;
  189. }
  190. - (void)configDefaultSoundVolume {
  191. self.soundVolume = 100;
  192. }
  193. - (void)viewDidAppear:(BOOL)animated {
  194. [super viewDidAppear:animated];
  195. // 切换到横屏
  196. [self changeOrientation:YES];
  197. }
  198. - (void)viewDidLoad {
  199. [super viewDidLoad];
  200. // Do any additional setup after loading the view.
  201. self.ks_prefersNavigationBarHidden = YES;
  202. self.view.backgroundColor = [UIColor whiteColor];
  203. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(leaveRoomAction) name:@"classroomLogout" object:nil];
  204. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(quitRoomAction) name:@"classroomQuit" object:nil];
  205. [self configBeatConfig]; // 设置默认节拍器数据
  206. [self configDefaultSoundVolume]; // 设置默认伴奏音量
  207. [self configClassroomDefault];
  208. UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
  209. [self.view addGestureRecognizer:tapGes];
  210. tapGes.delegate = self;
  211. [self showRoleHud];
  212. [TRTC_MANAGER useSpeaker:YES];
  213. self.isQuitRoom = NO;
  214. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgroundQuitRoomAction) name:@"backgroundQuit" object:nil];
  215. }
  216. - (void)configClassroomDefault {
  217. [self addSubviews];
  218. [self bindDelegates];
  219. [self publishStream];
  220. [self renderMainContainerView];
  221. self.timeManager.isDisplay = YES;
  222. }
  223. - (void)backgroundQuitRoomAction {
  224. self.isQuitRoom = YES;
  225. [[LoginHelper sharedInstance] logout];
  226. self.cancleAlert = YES;
  227. }
  228. #pragma mark ----- 账号异地登陆
  229. - (void)leaveRoomAction {
  230. [self showMessage:@"该账号在其他设备上登录"];
  231. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  232. self.isQuitRoom = YES;
  233. [[LoginHelper sharedInstance] logout];
  234. self.cancleAlert = YES;
  235. [self hideAlertView];
  236. [[NSNotificationCenter defaultCenter] postNotificationName:@"backLoginView" object:nil];
  237. });
  238. }
  239. - (void)quitRoomAction {
  240. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  241. self.isQuitRoom = YES;
  242. [[LoginHelper sharedInstance] logout];
  243. self.cancleAlert = YES;
  244. [self hideAlertView];
  245. [[NSNotificationCenter defaultCenter] postNotificationName:@"showOtherLoginAlert" object:nil];
  246. });
  247. }
  248. // 提示信息
  249. - (void)showMessage:(NSString *)message {
  250. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  251. [self.view bringSubviewToFront:hud];
  252. hud.removeFromSuperViewOnHide =YES;
  253. hud.mode = MBProgressHUDModeText;
  254. hud.label.text = message;
  255. hud.minSize = CGSizeMake(132.f, 60.0f);
  256. hud.label.textColor = [UIColor whiteColor];
  257. hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
  258. hud.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
  259. [hud hideAnimated:YES afterDelay:2];
  260. }
  261. - (void)tapGesture: (UITapGestureRecognizer *)tapGesture {
  262. if (self.titleView.isDisplay) {
  263. self.titleView.isDisplay = NO;
  264. self.timeManager.isDisplay = NO;
  265. }
  266. else {
  267. self.titleView.isDisplay = YES;
  268. self.timeManager.isDisplay = YES;
  269. }
  270. [self hidePersonListView];
  271. [self hideChatAreaView];
  272. [self.danView resetInputStatus];
  273. }
  274. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
  275. if ([touch.view isDescendantOfView:self.memberListView] || [touch.view isDescendantOfView:self.chatAreaView] || [touch.view isDescendantOfView:self.videoListView] || [touch.view isDescendantOfView:self.whiteboardListView]
  276. || [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]) {
  277. return NO;
  278. }
  279. // if ([touch.view isDescendantOfView:self.containerView]) {
  280. // [self tapGesture:(UITapGestureRecognizer *)gestureRecognizer];
  281. // }
  282. return YES;
  283. }
  284. - (void)showRoleHud {
  285. Role role = [ClassroomService sharedService].currentRoom.currentMember.role;
  286. if(role == RoleAudience) {
  287. [self.tipsView showTipsMessage:@"你当前身份是旁听人,其他人看/听不见你" inView:self.view];
  288. [self performSelector:@selector(showOnlyYouHUD) withObject:nil afterDelay:5.0f];
  289. } else{
  290. [self showOnlyYouHUD];
  291. }
  292. }
  293. - (void)showOnlyYouHUD {
  294. if ([ClassroomService sharedService].currentRoom.memberList.count == 1) {
  295. [self.tipsView showTipsMessage:@"当前课堂只有你一人,你可以等待或离开" inView:self.view];
  296. }
  297. }
  298. #pragma mark ------ ClassTitleViewDelegate
  299. - (void)classTitleView:(UIButton *)button didTapAtTag:(ClassTitleViewActionTag)tag {
  300. [self.chatAreaView resetInputStatus];
  301. [self.danView resetInputStatus];
  302. ClassRoomTitleButton *tagButton = [self.titleView viewWithTag:tag+1000];
  303. switch (tag) {
  304. case ClassTitleViewActionTagSwitchCamera:
  305. {
  306. [TRTC_MANAGER switchCamera];
  307. }
  308. break;
  309. case ClassTitleViewActionTagMic:
  310. {
  311. if (tagButton.isSelected == NO) { // 关闭
  312. [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeMicrophone];
  313. }
  314. else { // 打开
  315. [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeMicrophone];
  316. }
  317. }
  318. break;
  319. case ClassTitleViewActionTagCamera:
  320. {
  321. if (tagButton.isSelected == NO) {
  322. [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeCamera];
  323. }
  324. else {
  325. [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeCamera];
  326. }
  327. }
  328. break;
  329. case ClassTitleViewActionTagMute:
  330. {
  331. tagButton.isSelected = !tagButton.isSelected;
  332. [TRTC_MANAGER useSpeaker:!tagButton.isSelected];
  333. }
  334. break;
  335. case ClassTitleViewActionTagSquare: // 宫格模式
  336. {
  337. if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
  338. // 当前
  339. [self.tipsView showTipsMessage:@"当前有学生演示中" inView:self.view];
  340. return;
  341. }
  342. self.squareOn = YES;
  343. [self.squareView showInView:self.view];
  344. [self.squareView showVideoList];
  345. }
  346. break;
  347. case ClassTitleViewActionTagDan: // 弹幕开关
  348. {
  349. tagButton.isSelected = !tagButton.isSelected;
  350. if (tagButton.isSelected) { // 关闭弹幕
  351. [self hideDanChatView];
  352. }
  353. else { // 开启弹幕
  354. [self showDanChatView];
  355. }
  356. }
  357. break;
  358. case ClassTitleViewActionTagChat:
  359. {
  360. tagButton.isSelected = !tagButton.isSelected;
  361. tagButton.isSelected ? [self showChatAreaView] : [self hideChatAreaView];
  362. self.isChat = tagButton.isSelected;
  363. }
  364. break;
  365. case ClassTitleViewActionTagMember:
  366. {
  367. tagButton.isSelected = !tagButton.isSelected;
  368. tagButton.isSelected ? [self showPersonListView] : [self hidePersonListView];
  369. }
  370. break;
  371. case ClassTitleViewActionTagHangup:
  372. {
  373. [self showQuitAlert];
  374. }
  375. default:
  376. break;
  377. }
  378. }
  379. - (void)quitViewAction:(QUITCLASSTYPE)type {
  380. if (type == QUITCLASSTYPE_CLOSE) {
  381. [self showCouseCloseAlert];
  382. }
  383. else {
  384. [self showQuitAlert];
  385. }
  386. }
  387. - (void)showQuitAlert {
  388. MJWeakSelf;
  389. self.alertView = [TXClassRoomAlertView shareInstance];
  390. [self.alertView configWithTitle:@"提示" desc:@"确认退出课堂吗?" leftTitle:@"取消" rightTitle:@"退出" cancel:^{
  391. } confirm:^{
  392. weakSelf.isQuitRoom = YES;
  393. weakSelf.hud = [weakSelf createProgressHUD];
  394. [[LoginHelper sharedInstance] logout];
  395. }];
  396. }
  397. #pragma mark ---- 节拍器控制
  398. - (void)showNodeControlView {
  399. [self hidePersonListView];
  400. self.controlView = [NewTXMetronomeAlertView shareInstance];
  401. [self.controlView configRate:self.rate volume:self.volome beatType:self.type];
  402. self.controlView.isPlayBeat = [ClassroomService sharedService].currentRoom.isPlayBeat;
  403. MJWeakSelf;
  404. [self.controlView showAlertSureCallback:^(int rate, KSMetronomeType type, NSInteger volume) {
  405. weakSelf.type = type;
  406. weakSelf.rate = rate;
  407. weakSelf.volome = volume;
  408. }];
  409. [self.controlView metronomeClickAction:^(BOOL enable) {
  410. [weakSelf metronomeAction:enable];
  411. }];
  412. }
  413. - (void)metronomeAction:(BOOL)enable {
  414. MJWeakSelf;
  415. // 播放节拍器
  416. if (enable == YES) {
  417. [ClassroomService sharedService].currentRoom.isPlayBeat = YES;
  418. if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
  419. NSString *userId = [ClassroomService sharedService].currentRoom.shareUserId;
  420. [weakSelf operationStudentPlayNode:userId];
  421. }
  422. else {
  423. [weakSelf operationStudentPlayNode:@""];
  424. }
  425. if ([ClassroomService sharedService].currentRoom.isPlaySong) {
  426. [ClassroomService sharedService].currentRoom.isPlaySong = NO;
  427. DeviceType type = self.isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
  428. [[ClassroomService sharedService] enableMutilMemberDevice:NO type:type songId:[weakSelf.songId intValue] soundVolume:weakSelf.soundVolume forUser:@""];
  429. weakSelf.accompanyView.isPlaying = NO;
  430. }
  431. }
  432. else {
  433. NSDictionary *parm = @{@"enable": @(NO),
  434. @"rate" : @(0),
  435. @"customType" : @(0),
  436. @"playVolume" : @(0),
  437. @"userId" : @"",
  438. };
  439. [[ClassroomService sharedService] enablePlayMessage:NO content:[parm mj_JSONString] userId:@""];
  440. [ClassroomService sharedService].currentRoom.isPlayBeat = NO;
  441. [weakSelf unplayBeatNodeRefreshStream]; // 刷新音频流播放
  442. }
  443. }
  444. - (void)operationStudentPlayNode:(NSString *)userId {
  445. NSDictionary *parm = @{@"enable": @(YES),
  446. @"rate" : @(self.rate),
  447. @"customType" : @(self.type),
  448. @"playVolume" : @(self.volome),
  449. @"userId" : userId,
  450. };
  451. [[ClassroomService sharedService] enablePlayMessage:YES content:[parm mj_JSONString] userId:userId];
  452. // 默认显示第一个学生的视频 单个操作不再次刷新主屏
  453. if (self.videoListView.videoDataSource.count >= 1 && [NSString isEmptyString:userId]) {
  454. for (RoomMember *member in self.videoListView.videoDataSource) {
  455. if (member.role == RoleStudent) {
  456. [self videoListView:nil didTap:member];
  457. break;
  458. }
  459. }
  460. }
  461. else if (![NSString isEmptyString:userId]) {
  462. [ClassroomService sharedService].currentRoom.currentPlayUserId = userId;
  463. [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:userId];
  464. }
  465. }
  466. - (void)playNodeAction:(BOOL)enable userId:(NSString *)userId rate:(int)rate beatType:(BeatType)type {
  467. NSLog(@"playNodeAction userId:%@ enable:%@ beatType:%@ rate:%@",userId,@(enable),@(type), @(rate));
  468. // 刷新当前学生的节拍器状态
  469. if ([NSString isEmptyString:userId]) { // 全员
  470. for (RoomMember *member in [ClassroomService sharedService].currentRoom.memberList) {
  471. member.enable = enable;
  472. }
  473. }
  474. else { // 部分操作
  475. NSArray *userIdArray = [userId componentsSeparatedByString:@","];
  476. for (NSString *subUserId in userIdArray) {
  477. for (RoomMember *member in [ClassroomService sharedService].currentRoom.memberList) {
  478. if ([member.userId isEqualToString:subUserId]) {
  479. member.enable = enable;
  480. }
  481. }
  482. }
  483. }
  484. [self.containerView refreshToolView];
  485. }
  486. #pragma mark - ClassroomDelegate
  487. - (void)roomDidLeave {
  488. NSLog(@"roomDidLeave");
  489. // 关闭白板连接
  490. [self.wBoardCtrl.wbView.sdk setCommonCallbackDelegate:nil];
  491. [self.wBoardCtrl.wbView.room disconnect:^{
  492. }];
  493. [TRTC_MANAGER leaveRoom:^(NSInteger code) {
  494. }];
  495. [self dismissClassroom];
  496. }
  497. - (void)dismissClassroom {
  498. [self.hud hideAnimated:YES];
  499. [ClassroomService sharedService].currentRoom = nil;
  500. [self changeOrientation:NO];
  501. [self.timeManager stopDurationTimer];
  502. [self.timeView.timeLabel.layer removeAllAnimations];
  503. [self.navigationController popViewControllerAnimated:YES];
  504. }
  505. - (void)memberDidJoin:(RoomMember *)member {
  506. NSLog(@"memberDidJoin %@",member);
  507. if(member.role == RoleStudent) {
  508. [self.tipsView showTipsMessage:[NSString stringWithFormat:@"学生%@已经进入教室", member.name] inView:self.view];
  509. if (self.squareOn) {
  510. [self.squareView showVideoList];
  511. }
  512. else {
  513. [self.videoListView reloadVideoList];
  514. }
  515. // 如果在播放中
  516. if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
  517. if ([ClassroomService sharedService].currentRoom.memberList.count > 2) {
  518. [TRTC_MANAGER unPlayRemoteStudentWithId:member.userId];
  519. }
  520. }
  521. }
  522. [self.memberListView reloadPersonList];
  523. }
  524. - (void)memberDidLeave:(RoomMember *)member {
  525. NSLog(@"memberDidLeave %@",member);
  526. if(member.role != RoleAudience) {
  527. if (member.role == RoleStudent) {
  528. [self.tipsView showTipsMessage:[NSString stringWithFormat:@"学生%@已经离开教室", member.name] inView:self.view];
  529. if (self.squareOn && [member.userId isEqualToString:self.squareView.displayUserId]) {
  530. [self dismissMaskViewEvent];
  531. }
  532. // 如果主屏上台学生
  533. if ([ClassroomService sharedService].currentRoom.shareUserId == member.userId) {
  534. [self teachToolView:self.toolView.videoButton.actionButton didTapAtTag:TeachToolTagVideo];
  535. }
  536. else {
  537. if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayTypeStudent && [[ClassroomService sharedService].currentRoom.currentDisplayURI isEqualToString:member.userId]) {
  538. [self videoListView:self.videoListView didTap:[ClassroomService sharedService].currentRoom.currentMember];
  539. }
  540. }
  541. }
  542. if (self.squareOn) {
  543. [self.squareView showVideoList];
  544. }
  545. else {
  546. [self.videoListView reloadVideoList];
  547. }
  548. }
  549. [self.memberListView reloadPersonList:member tag:ClassPersonListTagRemove];
  550. if ([self.progressView isShow]) {
  551. [self.progressView requestData];
  552. }
  553. }
  554. - (void)memberDidKick:(RoomMember *)member {
  555. NSLog(@"memberDidKick %@",member);
  556. if ([ClassroomService sharedService].currentRoom.currentMember.role == RoleTeacher) {
  557. [self.tipsView showTipsMessage:[NSString stringWithFormat:@"你已将%@移出教室", member.name] inView:self.view];
  558. }
  559. if (self.squareOn) {
  560. [self.squareView showVideoList];
  561. }
  562. else {
  563. [self.videoListView reloadVideoList];
  564. }
  565. [self.memberListView reloadPersonList:member tag:ClassPersonListTagRemove];
  566. if (self.containerView.member.role == member.role) {
  567. [self.containerView cancelRenderView];
  568. }
  569. }
  570. - (void)errorDidOccur:(ErrorCode)code {
  571. NSLog(@"errorDidOccur %@",@(code));
  572. [self.hud hideAnimated:YES];
  573. if (code != ErrorCodeSuccess) {
  574. if (code == ErrorCodeOverMaxUserCount) {
  575. [self.tipsView showTipsMessage:@"超过人数限制" inView:self.view];
  576. }else {
  577. [self.tipsView showTipsMessage:@"操作失败,请稍后再试" inView:self.view];
  578. }
  579. }
  580. }
  581. - (void)deviceDidEnable:(BOOL)enable type:(DeviceType)type forUser:(RoomMember *)member operator:(nonnull NSString *)operatorId {
  582. NSLog(@"deviceDidEnable devicetype:%@ enable:%@ memeber:%@",@(type),@(enable),member);
  583. RoomMember *curMember = [ClassroomService sharedService].currentRoom.currentMember;
  584. NSString *hudMessage = @"";
  585. //只有老师和自己才有提示
  586. if (curMember.role == RoleTeacher && ![member.userId isEqualToString:curMember.userId]) {
  587. if (type == DeviceTypeCamera) {
  588. hudMessage = !enable ? [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetCameraClose", @"SealClass", nil),member.name] : [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetCameraOpen", @"SealClass", nil),member.name];
  589. [self refreshVideoView:member];
  590. } else if (type == DeviceTypeMicrophone) {
  591. hudMessage = !enable ? [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetMicorophoneClose", @"SealClass", nil),member.name] : [NSString stringWithFormat:NSLocalizedStringFromTable(@"SetMicorophoneOpen", @"SealClass", nil),member.name];
  592. [self.containerView refreshToolView];
  593. [self.memberListView reloadPersonList:member tag:ClassPersonListTagRefresh];
  594. [self.videoListView updateMicStatus:member.userId volume:40];
  595. }
  596. else if (type == DeviceTypeMusicMode) {
  597. }
  598. else if (type == DeviceTypeHandup) {
  599. if (![curMember.userId isEqualToString:operatorId]) {
  600. hudMessage = !enable ? [NSString stringWithFormat:@"%@已取消举手",member.name] : [NSString stringWithFormat:@"%@已举手",member.name];
  601. }
  602. if (self.squareOn) {
  603. [self.squareView showVideoList];
  604. }
  605. else {
  606. [self.videoListView reloadVideoList];
  607. }
  608. [self.memberListView reloadPersonList:member tag:ClassPersonListTagRefresh];
  609. }
  610. else if (type == DeviceTypeExamSong) { // 伴奏播放
  611. }
  612. else if (type == DeviceTypeAccompany || type == DeviceTypeMusicScore) { // 新伴奏 或原声播放
  613. }
  614. if (![NSString isEmptyString:hudMessage]) {
  615. [self.tipsView showTipsMessage:hudMessage inView:self.view];
  616. }
  617. }else {
  618. if ([curMember.userId isEqualToString:member.userId]) {
  619. if (type == DeviceTypeCamera) { // 摄像头
  620. // 非自己操作才需要做提示
  621. if(![curMember.userId isEqualToString:operatorId]){
  622. hudMessage = !enable ? NSLocalizedStringFromTable(@"YourCameraClosed", @"SealClass", nil) : NSLocalizedStringFromTable(@"CameraOpend", @"SealClass", nil);
  623. [self.tipsView showTipsMessage:hudMessage inView:self.view];
  624. }
  625. [self refreshHardwareStatus];
  626. [TRTC_MANAGER setCameraDisable:!enable];
  627. [self refreshVideoView:member];
  628. return;
  629. } else if (type == DeviceTypeMicrophone) { // 麦克风
  630. // 非自己操作才需要做提示
  631. if(![curMember.userId isEqualToString:operatorId]){
  632. hudMessage = !enable ? NSLocalizedStringFromTable(@"YourMicorophoneClosed", @"SealClass", nil) : NSLocalizedStringFromTable(@"MicorophoneOpend", @"SealClass", nil);
  633. [self.tipsView showTipsMessage:hudMessage inView:self.view];
  634. }
  635. [self refreshHardwareStatus];
  636. [TRTC_MANAGER setMicrophoneDisable:!enable];
  637. [self.videoListView updateMicStatus:member.userId volume:40];
  638. }
  639. else if (type == DeviceTypeMusicMode) {
  640. }
  641. }
  642. }
  643. }
  644. - (void)refreshHardwareStatus {
  645. [self.titleView refreshTitleView];
  646. [self.containerView refreshToolView];
  647. }
  648. // 刷新单个视频显示
  649. - (void)refreshVideoView:(RoomMember *)member {
  650. if (self.squareOn) {
  651. [self.squareView showVideoList];
  652. }
  653. else {
  654. // 刷新单个数据
  655. RoomMember *curMember = [ClassroomService sharedService].currentRoom.currentMember;
  656. if ([member.userId isEqualToString:curMember.userId]) {
  657. if ([ClassroomService sharedService].currentRoom.currentDisplayType != DisplayWhiteboard && [[ClassroomService sharedService].currentRoom.currentDisplayURI isEqualToString:member.userId]) {
  658. [self.wBoardCtrl hideBoard];
  659. [self.containerView containerViewRenderView:member];
  660. }
  661. else {
  662. [self.videoListView updateUserVideo:member.userId];
  663. }
  664. [self.titleView refreshTitleView];
  665. }
  666. else {
  667. if ([ClassroomService sharedService].currentRoom.currentDisplayType != DisplayWhiteboard && [[ClassroomService sharedService].currentRoom.currentDisplayURI isEqualToString:member.userId]) {
  668. [self.wBoardCtrl hideBoard];
  669. [self.containerView containerViewRenderView:member];
  670. }
  671. else {
  672. [self.videoListView updateUserVideo:member.userId];
  673. }
  674. [self.memberListView reloadPersonList:member tag:ClassPersonListTagRefresh];
  675. }
  676. }
  677. [self.containerView refreshToolView];
  678. }
  679. - (void)whiteboardDidDisplay:(NSString *)boardId {
  680. NSLog(@"whiteboardDidDisplay %@ ",boardId);
  681. [self renderMainContainerView];
  682. }
  683. - (void)sharedScreenDidDisplay:(NSString *)userId {
  684. NSLog(@"sharedScreenDidDisplay %@ ",userId);
  685. [self renderMainContainerView];
  686. }
  687. - (void)teacherDidDisplay {
  688. NSLog(@"teacherDidDisplay %@ ",[ClassroomService sharedService].currentRoom.teacher);
  689. [self renderMainContainerView];
  690. }
  691. - (void)studentDidDisplay:(NSString *)studentId {
  692. NSLog(@"studentDidDisplay %@", studentId);
  693. [self renderMainContainerView];
  694. }
  695. - (void)noneDidDisplay {
  696. NSLog(@"noneDidDisplay");
  697. [self renderMainContainerView];
  698. }
  699. #pragma mark ---- whiteboardListDelegate
  700. - (void)whiteboardSharedViewCellTap:(id)recentShared {
  701. if ([recentShared isKindOfClass:[WhiteScene class]]) {
  702. [LocalRenderManager shareInstance].hadRenderMainView = NO;
  703. [TRTC_MANAGER cancleRenderUserVideo:[ClassroomService sharedService].currentRoom.currentDisplayURI];
  704. WhiteScene *whiteBoard = (WhiteScene *)recentShared;
  705. [self displayWhiteboard:whiteBoard.name];
  706. [ClassroomService sharedService].currentRoom.currentDisplayURI = whiteBoard.name;
  707. }
  708. }
  709. #pragma mark ---- TRTC delegate
  710. #pragma mark - private method
  711. - (void)bindDelegates {
  712. [ClassroomService sharedService].classroomDelegate = self;
  713. TRTC_MANAGER.delegate = self;
  714. }
  715. - (void)addSubviews {
  716. [self.view addSubview:self.containerView];
  717. [self.view addSubview:self.timeView];
  718. [self.timeView mas_makeConstraints:^(MASConstraintMaker *make) {
  719. make.right.mas_equalTo(self.containerView.emptyView.mas_right).offset(-20);
  720. make.top.mas_equalTo(self.view.mas_top);
  721. make.height.mas_equalTo(44);
  722. }];
  723. [self.view bringSubviewToFront:self.timeView];
  724. [self.view addSubview:self.titleView];
  725. [self wBoardCtrl];
  726. [self chatAreaView];
  727. [self memberListView];
  728. [self.view addSubview:self.videoListView];
  729. [self.view addSubview:self.toolView];
  730. [self showDanChatView];
  731. CGFloat height = 275;
  732. [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
  733. make.right.mas_equalTo(self.containerView.emptyView.mas_right);
  734. make.width.mas_equalTo(82);
  735. make.height.mas_equalTo(height);
  736. make.bottom.mas_equalTo(self.containerView.emptyView.mas_bottom);
  737. }];
  738. [self.toolView hiddenToolViewWithAnimation:NO];
  739. [self.view bringSubviewToFront:self.toolView];
  740. [self.view bringSubviewToFront:self.titleView];
  741. }
  742. - (void)showPersonListView {
  743. [self.view addSubview:self.memberListView];
  744. [self.memberListView reloadPersonList];
  745. }
  746. - (void)showChatAreaView{
  747. [self.view addSubview:self.chatAreaView];
  748. [self.chatAreaView scrollToBottom];
  749. }
  750. - (void)hidePersonListView {
  751. self.titleView.memberBtn.isSelected = NO;
  752. [self.memberListView removeFromSuperview];
  753. }
  754. - (void)hideChatAreaView{
  755. [UIView animateWithDuration:0.2 animations:^{
  756. self.titleView.chatBtn.isSelected = NO;
  757. [self.chatAreaView resetInputStatus];
  758. [self.chatAreaView removeFromSuperview];
  759. }];
  760. }
  761. - (void)showDanChatView {
  762. // 视频页面添加弹幕
  763. [self.containerView.videoView addSubview:self.danView];
  764. }
  765. - (void)hideDanChatView {
  766. //
  767. [self.danView removeFromSuperview];
  768. }
  769. - (CGRect)mainContainerViewFrame {
  770. CGFloat x = 0;
  771. CGFloat y = 0;
  772. CGFloat width = KLandscapeWidth - x;
  773. CGFloat height = KLandscapeHeight - y;
  774. return CGRectMake(x, y, width, height);
  775. }
  776. - (void)displayWhiteboard:(NSString *)boardId {
  777. CGRect boardFrame = [self getWBoardFrame];
  778. [self.wBoardCtrl loadWBoardWithFrame:boardFrame name:boardId];
  779. for (UIView * view in self.view.subviews) {
  780. if ([view isKindOfClass:[ClassMemberListView class]] || [view isKindOfClass:[TXChatAreaView class]] || [view isKindOfClass:[WhiteboardListView class]]) {
  781. [self.view bringSubviewToFront:view];
  782. }
  783. }
  784. if (self.videoListHidden) {
  785. [self.view bringSubviewToFront:self.showButton];
  786. [self.view bringSubviewToFront:self.toolView];
  787. }
  788. self.toolView.isVideoDisplay = NO;
  789. [self.view bringSubviewToFront:self.timeView];
  790. [self.view bringSubviewToFront:self.titleView];
  791. }
  792. - (void)refreshWhiteBoardFrame {
  793. [self.wBoardCtrl setWBoardFrame:[self getWBoardFrame]];
  794. }
  795. - (CGRect)getWBoardFrame {
  796. CGRect mainVideoFrame = CGRectZero;
  797. CGFloat width = 0;
  798. CGFloat height = 0;
  799. if (self.videoListHidden) {
  800. width = KLandscapeWidth;
  801. height = KLandscapeHeight;
  802. }
  803. else {
  804. width = KLandscapeWidth -(144 + 20 + 10);
  805. height = KLandscapeHeight;
  806. }
  807. mainVideoFrame.size.width = width;
  808. mainVideoFrame.size.height = height;
  809. mainVideoFrame.origin.x += 0;
  810. mainVideoFrame.origin.y = 0;
  811. return mainVideoFrame;
  812. }
  813. - (void)publishStream {
  814. if ([ClassroomService sharedService].currentRoom.currentMember.role != RoleAudience) {
  815. [TRTC_MANAGER publishStream];
  816. }
  817. }
  818. - (void)renderMainContainerView {
  819. if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayTypeStudent) {
  820. // 有打开的屏幕
  821. for (RoomMember *displayMember in [ClassroomService sharedService].currentRoom.memberList) {
  822. if ([displayMember.userId isEqualToString:[ClassroomService sharedService].currentRoom.currentDisplayURI]) {
  823. [self.containerView refreshToolView];
  824. [self.wBoardCtrl hideBoard];
  825. [self.containerView containerViewRenderView:displayMember];
  826. [self.videoListView showTeacherPrompt:NO];
  827. break;
  828. }
  829. }
  830. } else if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayTeacher) {
  831. NSLog(@"%@",[ClassroomService sharedService].currentRoom.currentDisplayURI);
  832. [self.wBoardCtrl hideBoard];
  833. [self.containerView containerViewRenderView:[ClassroomService sharedService].currentRoom.teacher];
  834. [self.videoListView showTeacherPrompt:YES];
  835. } else if ([ClassroomService sharedService].currentRoom.currentDisplayType == DisplayWhiteboard) {
  836. [self.containerView cancelRenderView];
  837. [self displayWhiteboard:[ClassroomService sharedService].currentRoom.currentDisplayURI];
  838. [self.videoListView showTeacherPrompt:NO];
  839. } else if (([ClassroomService sharedService].currentRoom.currentDisplayType == DisplaySharedScreen)) {
  840. [self.wBoardCtrl hideBoard];
  841. [TRTC_MANAGER renderRemoteUser:[ClassroomService sharedService].currentRoom.currentDisplayURI inView:self.containerView.videoView];
  842. // 分享视频
  843. [self.videoListView showTeacherPrompt:NO];
  844. } else {
  845. [self.wBoardCtrl hideBoard];
  846. [self.containerView cancelRenderView];
  847. [self.videoListView showTeacherPrompt:NO];
  848. }
  849. }
  850. #pragma mark ----- ClassVideoListViewDelegate
  851. - (void)videoListView:(TXClassroomVideoListView *)view didTap:(RoomMember *)member {
  852. if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
  853. // 当前
  854. [self.tipsView showTipsMessage:@"当前有学生演示中" inView:self.view];
  855. return;
  856. }
  857. // 将视频投到主屏幕上
  858. NSString *currentDisplayUserId = member.userId;
  859. NSString *lastDisplayUserId = [ClassroomService sharedService].currentRoom.currentDisplayURI;
  860. if([currentDisplayUserId isEqualToString:lastDisplayUserId]) {
  861. [self.videoListView updateUserVideo:lastDisplayUserId];
  862. if(![[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
  863. // 记录当前演奏播放音频的学生
  864. if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
  865. [ClassroomService sharedService].currentRoom.currentPlayUserId = currentDisplayUserId;
  866. [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:member.userId];
  867. }
  868. }
  869. return;
  870. }
  871. DisplayType type = member.role == RoleTeacher ? DisplayTeacher : DisplayTypeStudent;
  872. [ClassroomService sharedService].currentRoom.currentDisplayURI = currentDisplayUserId;
  873. [ClassroomService sharedService].currentRoom.currentDisplayType = type;
  874. [self.videoListView updateUserVideo:member.userId];
  875. if(![[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
  876. // 记录当前演奏播放音频的学生
  877. if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
  878. [ClassroomService sharedService].currentRoom.currentPlayUserId = currentDisplayUserId;
  879. [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:member.userId];
  880. }
  881. }
  882. [self renderMainContainerView];
  883. }
  884. - (void)unplayBeatNodeRefreshStream {
  885. if ([ClassroomService sharedService].currentRoom.isPlayBeat == NO && [ClassroomService sharedService].currentRoom.isPlaySong == NO) { // 关闭节拍器后播放所有学生端声音
  886. [TRTC_MANAGER playAllRemoteStudentAudioStream];
  887. [ClassroomService sharedService].currentRoom.currentPlayUserId = nil;
  888. }
  889. }
  890. - (void)videoListView:(TXClassroomVideoListView *)view didHideView:(BOOL)isHideView {
  891. if (isHideView) { // 隐藏video list
  892. [self hideVideoList];
  893. }
  894. else { // 显示
  895. [self showVideoList];
  896. }
  897. }
  898. - (void)hideVideoList {
  899. self.videoListHidden = YES;
  900. CGRect frame = self.videoListView.frame;
  901. self.videoListView.frame = CGRectMake(KLandscapeWidth, frame.origin.y, frame.size.width, frame.size.height);
  902. [self.containerView changeVideoFrameFull:YES];
  903. [self refreshWhiteBoardFrame];
  904. [self.view addSubview:self.showButton];
  905. [self.view bringSubviewToFront:self.toolView];
  906. }
  907. - (void)showVideoList {
  908. self.videoListHidden = NO;
  909. CGRect frame = self.videoListView.frame;
  910. self.videoListView.frame = CGRectMake(KLandscapeWidth - frame.size.width, frame.origin.y, frame.size.width, frame.size.height);
  911. [self.containerView changeVideoFrameFull:NO];
  912. [self refreshWhiteBoardFrame];
  913. [self.showButton removeFromSuperview];
  914. }
  915. #pragma mark ---- ClassroomTimerManager delegate
  916. - (void)formatTime:(NSString *)timeString {
  917. self.timeView.timeLabel.text = timeString;
  918. }
  919. - (void)timeLabelAddAnimation:(CABasicAnimation *)animation {
  920. self.timeView.timeLabel.textColor = HexRGB(0x2DC7AA);
  921. [self.timeView.timeLabel.layer addAnimation:animation forKey:nil];
  922. }
  923. - (void)hiddenTitleView {
  924. self.titleView.isDisplay = NO;
  925. }
  926. - (void)quitClassroomNotifer {
  927. // 课程结束后15分钟自动退出房间 连堂课不退出(对内)
  928. if (self.isQuitRoom == NO) {
  929. self.isQuitRoom = YES;
  930. // 退出房间
  931. [self.tipsView showTipsMessage:@"课程已结束" inView:self.view];
  932. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  933. // 课程结束退出房间
  934. SealClassLog(@"ClassEnd!");
  935. self.hud = [self createProgressHUD];
  936. [[LoginHelper sharedInstance] logout];
  937. [self.titleView clearUnreadMessage];
  938. });
  939. }
  940. }
  941. #pragma mark --- whiteboard
  942. - (void)didTurnPage:(NSInteger)pageNum {
  943. }
  944. - (void)whiteboardViewDidChangeZoomScale:(float)scale {
  945. }
  946. - (void)needRefreshWhiteboardList {
  947. [self.whiteboardListView reloadDataSource];
  948. }
  949. - (void)needShowTopTitleView:(UIView *)touchView {
  950. if ([touchView isDescendantOfView:self.whiteboardListView]) {
  951. return;
  952. }
  953. self.titleView.isDisplay = YES;
  954. self.timeManager.isDisplay = YES;
  955. [self hidePersonListView];
  956. [self hideChatAreaView];
  957. [self.danView resetInputStatus];
  958. }
  959. // 白板连接状态回调
  960. - (void)connectionWhiteboardStatus:(JOINROOMSTATUS)status {
  961. if (status == JOINROOMSTATUS_FAILED) {
  962. [self.tipsView showTipsMessage:@"白板连接失败,请检查您的网络" inView:self.view];
  963. }
  964. else if (status == JOINROOMSTATUS_PARAMERROR) {
  965. [self.tipsView showTipsMessage:@"获取白板参数错误" inView:self.view];
  966. }
  967. }
  968. #pragma mark ---- mainContainer
  969. - (void)mainContainerOpertionMember:(RoomMember *)member tapButton:(UIButton *)button didTapAtTag:(MainToolButtonTag)tag {
  970. RoomMember *curMember = [ClassroomService sharedService].currentRoom.currentMember;
  971. // 操作自己
  972. MainToolButton *toolButton = [self.containerView.toolView viewWithTag:tag+1000];
  973. // 操作自己
  974. if ([member.userId isEqualToString:curMember.userId]) {
  975. switch (tag) {
  976. case MainToolButtonTagMic: // 麦克风
  977. {
  978. if (toolButton.isSelected) { // 打开
  979. [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeMicrophone];
  980. }
  981. else { // 关闭
  982. [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeMicrophone];
  983. }
  984. }
  985. break;
  986. case MainToolButtonTagCamero: // 摄像头
  987. {
  988. if (toolButton.isSelected) { // 打开
  989. [[ClassroomService sharedService] enableDevice:YES songId:0 withType:DeviceTypeCamera];
  990. }
  991. else { // 关闭
  992. [[ClassroomService sharedService] enableDevice:NO songId:0 withType:DeviceTypeCamera];
  993. }
  994. }
  995. break;
  996. case MainToolButtonTagShare: // 老师无此状态操作
  997. {
  998. }
  999. break;
  1000. case MainToolButtonTagPercent:
  1001. {
  1002. // [self showProgressView];
  1003. }
  1004. break;
  1005. default:
  1006. break;
  1007. }
  1008. }
  1009. else { // 操作学生
  1010. switch (tag) {
  1011. case MainToolButtonTagMic:
  1012. {
  1013. if (toolButton.isSelected) { // 打开
  1014. self.alertView = [TXClassRoomAlertView shareInstance];
  1015. [self.alertView configWithTitle:@"提示" desc:@"确认打开学生的麦克风吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
  1016. } confirm:^{
  1017. [[ClassroomService sharedService] enableDevice:YES type:DeviceTypeMicrophone songId:0 soundVolume:0 forUser:member.userId];
  1018. }];
  1019. }
  1020. else { // 关闭
  1021. self.alertView = [TXClassRoomAlertView shareInstance];
  1022. [self.alertView configWithTitle:@"提示" desc:@"确认关闭学生的麦克风吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
  1023. } confirm:^{
  1024. [[ClassroomService sharedService] enableDevice:NO type:DeviceTypeMicrophone songId:0 soundVolume:0 forUser:member.userId];
  1025. }];
  1026. }
  1027. }
  1028. break;
  1029. case MainToolButtonTagCamero:
  1030. {
  1031. if (toolButton.isSelected) { // 打开
  1032. self.alertView = [TXClassRoomAlertView shareInstance];
  1033. [self.alertView configWithTitle:@"提示" desc:@"邀请学生打开摄像头吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
  1034. } confirm:^{
  1035. [[ClassroomService sharedService] enableDevice:YES type:DeviceTypeCamera songId:0 soundVolume:0 forUser:member.userId];
  1036. }];
  1037. }
  1038. else { // 关闭
  1039. self.alertView = [TXClassRoomAlertView shareInstance];
  1040. [self.alertView configWithTitle:@"提示" desc:@"确认关闭学生的摄像头吗?" leftTitle:@"取消" rightTitle:@"确认" cancel:^{
  1041. } confirm:^{
  1042. [[ClassroomService sharedService] enableDevice:NO type:DeviceTypeCamera songId:0 soundVolume:0 forUser:member.userId];
  1043. }];
  1044. }
  1045. }
  1046. break;
  1047. case MainToolButtonTagShare:
  1048. {
  1049. if (toolButton.isSelected) { // 下台 显示老师
  1050. // 停止伴奏和节拍器
  1051. [self resetPlayBeatAndAccompany];
  1052. // 之前共享的学生切换成小流
  1053. [self exchangePreStudentToTinySteam];
  1054. [self.containerView refreshToolView];
  1055. [ClassroomService sharedService].currentRoom.currentDisplayType = DisplayTeacher;
  1056. [ClassroomService sharedService].currentRoom.currentDisplayURI = [ClassroomService sharedService].currentRoom.currentMember.userId;
  1057. [[ClassroomService sharedService] displayTeacher];
  1058. [self.containerView containerViewRenderView:[ClassroomService sharedService].currentRoom.currentMember];
  1059. [self.videoListView showTeacherPrompt:YES];
  1060. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1061. [self renderMainContainerView];
  1062. });
  1063. }
  1064. else { // 上台共享学生
  1065. // 停止伴奏和节拍器
  1066. [self resetPlayBeatAndAccompany];
  1067. // 如果之前显示的白板 关闭掉
  1068. self.toolView.isVideoDisplay = YES;
  1069. [self.whiteboardListView removeFromSuperview];
  1070. [ClassroomService sharedService].currentRoom.shareUserId = member.userId;
  1071. [self.containerView refreshToolView];
  1072. [[ClassroomService sharedService] displayStudent:member.userId];
  1073. [self.containerView refreshShareStatus];
  1074. [self.videoListView showTeacherPrompt:NO];
  1075. if (member.handUpOn) {
  1076. [[ClassroomService sharedService] enableDevice:NO type:DeviceTypeHandup songId:0 soundVolume:0 forUser:member.userId];
  1077. }
  1078. }
  1079. }
  1080. break;
  1081. case MainToolButtonTagPercent:
  1082. {
  1083. // [self showProgressView];
  1084. }
  1085. break;
  1086. default:
  1087. break;
  1088. }
  1089. }
  1090. }
  1091. - (void)resetPlayBeatAndAccompany {
  1092. if ([ClassroomService sharedService].currentRoom.isPlaySong) {
  1093. DeviceType type = self.isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
  1094. [[ClassroomService sharedService] enableMutilMemberDevice:NO type:type songId:[self.songId intValue] soundVolume:self.soundVolume forUser:@""];
  1095. // 重置伴奏按钮
  1096. self.accompanyView.isPlaying = NO;
  1097. }
  1098. if ([ClassroomService sharedService].currentRoom.isPlayBeat) {
  1099. NSDictionary *parm = @{@"enable": @(NO),
  1100. @"rate" : @(0),
  1101. @"customType" : @(0),
  1102. @"playVolume" : @(0),
  1103. @"userId" : @"",
  1104. };
  1105. [[ClassroomService sharedService] enablePlayMessage:NO content:[parm mj_JSONString] userId:@""];
  1106. [ClassroomService sharedService].currentRoom.isPlayBeat = NO;
  1107. }
  1108. [self unplayBeatNodeRefreshStream]; // 刷新音频流播放
  1109. }
  1110. - (void)changeSongPlayDisplay:(NSString *)userId {
  1111. // 默认显示第一个学生的视频 单个操作不再次刷新主屏
  1112. if (self.videoListView.videoDataSource.count >= 1 && [NSString isEmptyString:userId]) {
  1113. for (RoomMember *member in self.videoListView.videoDataSource) {
  1114. if (member.role == RoleStudent) {
  1115. [self videoListView:nil didTap:member];
  1116. break;
  1117. }
  1118. }
  1119. }
  1120. else if (![NSString isEmptyString:userId]) {
  1121. [ClassroomService sharedService].currentRoom.currentPlayUserId = userId;
  1122. [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:userId];
  1123. }
  1124. }
  1125. - (void)showProgressView {
  1126. [self.progressView showView:self.songName songId:self.songId];
  1127. }
  1128. - (void)exchangePreStudentToTinySteam {
  1129. [ClassroomService sharedService].currentRoom.shareUserId = @"";
  1130. }
  1131. #pragma mark ---- TXRTCServiceDelegate
  1132. - (void)didReportNetworkQuality:(TRTCQuality)quality remoteQuality:(NSArray<TRTCQualityInfo *> *)remoteQuality {
  1133. if (quality >= 5) { // 网络质量不佳
  1134. dispatch_async(dispatch_get_main_queue(), ^{
  1135. [self.view addSubview:self.networkLabel];
  1136. [self.view bringSubviewToFront:self.networkLabel];
  1137. self.networkLabel.hidden = NO;
  1138. self.networkLabel.text = @"当前通话连接质量不佳";
  1139. });
  1140. }
  1141. else { // 正常
  1142. dispatch_async(dispatch_get_main_queue(), ^{
  1143. self.networkLabel.hidden = YES;
  1144. self.networkLabel.text = @"";
  1145. [self.networkLabel removeFromSuperview];
  1146. });
  1147. }
  1148. [self showNetworkingStatus:quality remoteQuality:remoteQuality];
  1149. }
  1150. - (void)showNetworkingStatus:(TRTCQuality)quality remoteQuality:(NSArray<TRTCQualityInfo *> *)remoteQuality {
  1151. dispatch_async(dispatch_get_main_queue(), ^{
  1152. // 本地
  1153. NSString *currentUserID = [ClassroomService sharedService].currentRoom.currentMemberId;
  1154. if ([self.containerView.member.userId isEqualToString:currentUserID]) {
  1155. [self.containerView.displayView updateUserQualityNetWorkingStatus:[self getNetStatusWithQuality:quality]];
  1156. }
  1157. [self.videoListView updateUserQuality:currentUserID netWorkingStatus:[self getNetStatusWithQuality:quality]];
  1158. // 更新full
  1159. if (self.squareOn) {
  1160. [self.squareView updateUserQuality:currentUserID netWorkingStatus:[self getNetStatusWithQuality:quality]];
  1161. }
  1162. // 远端
  1163. for (TRTCQualityInfo *info in remoteQuality) {
  1164. NSString *userId = info.userId;
  1165. [self.videoListView updateUserQuality:userId netWorkingStatus:[self getNetStatusWithQuality:info.quality]];
  1166. if ([info.userId isEqualToString:self.containerView.member.userId]) {
  1167. [self.containerView.displayView updateUserQualityNetWorkingStatus:[self getNetStatusWithQuality:info.quality]];
  1168. }
  1169. // 更新full
  1170. if (self.squareOn) {
  1171. [self.squareView updateUserQuality:userId netWorkingStatus:[self getNetStatusWithQuality:info.quality]];
  1172. }
  1173. }
  1174. });
  1175. }
  1176. - (TXNetWorkingStatus)getNetStatusWithQuality:(TRTCQuality)quality {
  1177. TXNetWorkingStatus status = TXNetWorkingStatus_Full;
  1178. if (quality == 1 || quality == 2) {
  1179. status = TXNetWorkingStatus_Full;
  1180. }
  1181. else if (quality == 3) {
  1182. status = TXNetWorkingStatus_Good;
  1183. }
  1184. else if (quality == 4) {
  1185. status = TXNetWorkingStatus_Nomal;
  1186. }
  1187. else if (quality == 5) {
  1188. status = TXNetWorkingStatus_Bad;
  1189. }
  1190. else { //
  1191. status = TXNetWorkingStatus_Poor;
  1192. }
  1193. return status;
  1194. }
  1195. - (void)didReportUserVolume:(NSArray<TRTCVolumeInfo *> *)userVolumes {
  1196. NSString *currentUserID = [ClassroomService sharedService].currentRoom.currentMemberId;
  1197. for (TRTCVolumeInfo *info in userVolumes) {
  1198. NSString *userId = info.userId;
  1199. if ([NSString isEmptyString:userId]) {
  1200. userId = currentUserID;
  1201. }
  1202. [self.videoListView updateMicStatus:userId volume:info.volume];
  1203. // 更新title
  1204. if ([currentUserID isEqualToString:userId]) {
  1205. [self.titleView updateUserVolume:info.volume];
  1206. }
  1207. // 更新container
  1208. if ([self.containerView.member.userId isEqualToString:userId]) {
  1209. [self.containerView updateUserVolume:info.volume];
  1210. }
  1211. // 更新full
  1212. if (self.squareOn) {
  1213. [self.squareView updateMicStatus:userId volume:info.volume];
  1214. }
  1215. }
  1216. }
  1217. #pragma mark ------- 教学工具
  1218. - (TXTeachToolView *)toolView {
  1219. if (!_toolView) {
  1220. _toolView = [[TXTeachToolView alloc] init];
  1221. _toolView.delegate = self;
  1222. }
  1223. return _toolView;
  1224. }
  1225. - (AccompanyProgressView *)progressView {
  1226. if (!_progressView) {
  1227. _progressView = [[AccompanyProgressView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, KLandscapeHeight)];
  1228. }
  1229. return _progressView;
  1230. }
  1231. - (void)teachToolView:(UIButton *)button didTapAtTag:(TeachToolTag)tag {
  1232. switch (tag) {
  1233. case TeachToolTagWhiteboard:
  1234. {
  1235. // 停止伴奏和节拍器
  1236. [self resetPlayBeatAndAccompany];
  1237. self.hud = [self createProgressHUD];
  1238. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1239. [self.hud hideAnimated:YES];
  1240. button.selected = YES;
  1241. self.toolView.isVideoDisplay = NO;
  1242. if ([ClassroomService sharedService].currentRoom.randomNumeric == 0) {
  1243. [self.view addSubview:self.whiteboardListView];
  1244. }
  1245. self.whiteboardListView.isOpen = NO;
  1246. // 之前共享的学生切换成小流
  1247. [self exchangePreStudentToTinySteam];
  1248. [TRTC_MANAGER cancleRenderUserVideo:[ClassroomService sharedService].currentRoom.currentDisplayURI];
  1249. [ClassroomService sharedService].currentRoom.currentDisplayType = DisplayWhiteboard;
  1250. [ClassroomService sharedService].currentRoom.currentDisplayURI = @"whiteboard";
  1251. [[ClassroomService sharedService] displayWhiteboard:@"whiteboard"];
  1252. [self renderMainContainerView];
  1253. [self.videoListView showTeacherPrompt:NO];
  1254. [self.whiteboardListView reloadDataSource];
  1255. // 收起
  1256. [self.toolView hiddenToolViewWithAnimation:YES];
  1257. });
  1258. }
  1259. break;
  1260. case TeachToolTagVideo:
  1261. {
  1262. // 停止伴奏和节拍器
  1263. [self resetPlayBeatAndAccompany];
  1264. button.selected = YES;
  1265. self.toolView.isVideoDisplay = YES;
  1266. // 收起
  1267. [self.toolView hiddenToolViewWithAnimation:YES];
  1268. // 之前共享的学生切换成小流
  1269. [self exchangePreStudentToTinySteam];
  1270. [ClassroomService sharedService].currentRoom.currentDisplayType = DisplayTeacher;
  1271. [ClassroomService sharedService].currentRoom.currentDisplayURI = [ClassroomService sharedService].currentRoom.currentMember.userId;
  1272. [[ClassroomService sharedService] displayTeacher];
  1273. [self.containerView containerViewRenderView:[ClassroomService sharedService].currentRoom.currentMember];
  1274. [self.videoListView showTeacherPrompt:YES];
  1275. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1276. [self renderMainContainerView];
  1277. });
  1278. [self.whiteboardListView removeFromSuperview];
  1279. }
  1280. break;
  1281. case TeachToolTagLibrary: // 选择伴奏曲库
  1282. {
  1283. [self.accompanyView showAccompanyView];
  1284. }
  1285. break;
  1286. case TeachToolTagNode:
  1287. {
  1288. [self showNodeControlView];
  1289. }
  1290. break;
  1291. default:
  1292. break;
  1293. }
  1294. }
  1295. #pragma mark - Getters & setters
  1296. - (ClassroomTimerManager *)timeManager {
  1297. if (!_timeManager) {
  1298. _timeManager = [[ClassroomTimerManager alloc] initWithDelegate:self];
  1299. _timeManager.autoClose = [ClassroomService sharedService].currentRoom.autoCloseFlag;
  1300. // 统一15分钟关闭
  1301. _timeManager.autoCloseNetworkRoomTime = [ClassroomService sharedService].currentRoom.autoCloseNetworkRoomTime;
  1302. }
  1303. return _timeManager;
  1304. }
  1305. - (TXTimeView *)timeView {
  1306. if (!_timeView) {
  1307. _timeView = [TXTimeView shareInstance];
  1308. }
  1309. return _timeView;
  1310. }
  1311. - (KSTipsView *)tipsView {
  1312. if (!_tipsView) {
  1313. _tipsView = [[KSTipsView alloc] initWithFrame:CGRectZero];
  1314. }
  1315. return _tipsView;
  1316. }
  1317. - (TXClassTitleView *)titleView {
  1318. if (!_titleView) {
  1319. _titleView = [[TXClassTitleView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, TitleViewHeight)];
  1320. _titleView.delegate = self;
  1321. }
  1322. return _titleView;
  1323. }
  1324. - (TXClassroomVideoListView *)videoListView {
  1325. if(!_videoListView) {
  1326. CGFloat width = VIDEO_WIDTH + 20 + 10;
  1327. CGFloat height = KLandscapeHeight;
  1328. _videoListView = [[TXClassroomVideoListView alloc] initWithFrame:CGRectMake(KLandscapeWidth - width, 0, width, height)];
  1329. _videoListView.delegate = self;
  1330. }
  1331. return _videoListView;
  1332. }
  1333. - (UIButton *)showButton {
  1334. if (!_showButton) {
  1335. _showButton = [UIButton buttonWithType:UIButtonTypeCustom];
  1336. _showButton.frame = CGRectMake(KLandscapeWidth-30, (KLandscapeHeight-30)/2.0, 30, 30);
  1337. [_showButton setImage:[UIImage imageNamed:@"videoList_show"] forState:UIControlStateNormal];
  1338. [_showButton addTarget:self action:@selector(showVideoList) forControlEvents:UIControlEventTouchUpInside];
  1339. }
  1340. return _showButton;
  1341. }
  1342. - (ClassMemberListView *)memberListView {
  1343. if (!_memberListView) {
  1344. _memberListView = [[ClassMemberListView alloc] initWithFrame:CGRectMake(KLandscapeWidth - PersonListViewWidth, 0, PersonListViewWidth, KLandscapeHeight)];
  1345. _memberListView.delegate = self;
  1346. }
  1347. return _memberListView;
  1348. }
  1349. - (TXClassroomMainContainer *)containerView {
  1350. if (!_containerView) {
  1351. _containerView = [[TXClassroomMainContainer alloc] initWithFrame:[self mainContainerViewFrame]];
  1352. _containerView.delegate = self;
  1353. }
  1354. return _containerView;
  1355. }
  1356. - (TXChatAreaView *)chatAreaView {
  1357. if(!_chatAreaView) {
  1358. _chatAreaView = [[TXChatAreaView alloc] initWithFrame:CGRectMake(KLandscapeWidth- 300,0, 300, KLandscapeHeight) chatGroupId:[ClassroomService sharedService].currentRoom.roomId];
  1359. }
  1360. return _chatAreaView;
  1361. }
  1362. - (KSWhiteboardControl *)wBoardCtrl {
  1363. if (!_wBoardCtrl) {
  1364. CGRect frame = [self getWBoardFrame];
  1365. _wBoardCtrl = [[KSWhiteboardControl alloc] initWithDelegate:self viewFrame:frame];
  1366. NSLog(@"----%@", [ClassroomService sharedService].currentRoom.roomId);
  1367. _wBoardCtrl.randomNumeric = [ClassroomService sharedService].currentRoom.randomNumeric;
  1368. NSString *roomId = [ClassroomService sharedService].currentRoom.roomId;
  1369. if ([roomId containsString:@"S"] || [roomId containsString:@"I"]) {
  1370. roomId = [roomId substringFromIndex:1];
  1371. }
  1372. _wBoardCtrl.roomId = roomId;
  1373. _wBoardCtrl.subjectId = self.subjectId;
  1374. [_wBoardCtrl moveToSuperView:self.view];
  1375. }
  1376. return _wBoardCtrl;
  1377. }
  1378. - (WhiteboardListView *)whiteboardListView {
  1379. if (!_whiteboardListView) {
  1380. _whiteboardListView = [[WhiteboardListView alloc] initWithFrame:CGRectMake(-140+iPhoneXSafeTopMargin, 0, WhiteboardListWidth, KLandscapeHeight)];
  1381. _whiteboardListView.delegate = self;
  1382. _whiteboardListView.whiteboardCtrl = self.wBoardCtrl;
  1383. }
  1384. return _whiteboardListView;
  1385. }
  1386. - (TXFullVideoView *)squareView {
  1387. if (!_squareView) {
  1388. _squareView = [[TXFullVideoView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, KLandscapeHeight)];
  1389. _squareView.delegate = self;
  1390. }
  1391. return _squareView;
  1392. }
  1393. #pragma mark ----- 宫格模式
  1394. // 点击视频
  1395. - (void)fullVideoListView:(TXFullVideoView *)view didTap:(RoomMember *)member {
  1396. // 放大当前视频
  1397. if([[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
  1398. if (member.cameraEnable) {
  1399. self.maskView.closeCameraView.hidden = YES;
  1400. }
  1401. else {
  1402. self.maskView.closeCameraView.hidden = NO;
  1403. }
  1404. [TRTC_MANAGER renderLocalUserInView:self.maskView.maskVideoView isCameraEnable:member.cameraEnable];
  1405. }else {
  1406. self.maskView.closeCameraView.hidden = YES;
  1407. [TRTC_MANAGER renderRemoteUser:member.userId inView:self.maskView.maskVideoView];
  1408. if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
  1409. [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:member.userId];
  1410. [ClassroomService sharedService].currentRoom.currentPlayUserId = member.userId;
  1411. }
  1412. }
  1413. [self.view addSubview:self.maskView];
  1414. }
  1415. // 关闭宫格模式
  1416. - (void)cancleFullVideoList {
  1417. self.squareOn = NO;
  1418. [self.squareView removeFromSuperview];
  1419. if ([ClassroomService sharedService].currentRoom.isPlayBeat || [ClassroomService sharedService].currentRoom.isPlaySong) {
  1420. [ClassroomService sharedService].currentRoom.currentPlayUserId = self.squareView.currentPlayUserId;
  1421. NSString *userId = [ClassroomService sharedService].currentRoom.currentPlayUserId;
  1422. [TRTC_MANAGER unPlayRemoteStudentAudioStreamExcept:userId];
  1423. }
  1424. [self renderMainContainerView];
  1425. [self.videoListView reloadVideoList];
  1426. }
  1427. - (VideoMaskView *)maskView {
  1428. if (!_maskView) {
  1429. CGFloat width = (KLandscapeWidth);
  1430. CGRect frame = CGRectMake(0, 0, width, KLandscapeHeight);
  1431. _maskView = [[VideoMaskView alloc] initWithFrame:frame];
  1432. [_maskView addDismisTarget:self action:@selector(dismissMaskViewEvent)];
  1433. }
  1434. return _maskView;
  1435. }
  1436. - (void)dismissMaskViewEvent {
  1437. // 切换成小流
  1438. [self removeMaskViewIfNeed];
  1439. [self.squareView showVideoList];
  1440. self.squareView.displayUserId = @"";
  1441. }
  1442. - (void)removeMaskViewIfNeed {
  1443. [self.maskView removeFromSuperview];
  1444. _maskView = nil;
  1445. }
  1446. #pragma mark --------- 主动关闭教室
  1447. - (void)showCouseCloseAlert {
  1448. // 判断如果课程结束、不能进行此操作
  1449. if (self.timeManager.showCloseTips) {
  1450. [self.tipsView showTipsMessage:@"已结束课程不可使用该功能" inView:self.view];
  1451. return;
  1452. }
  1453. self.closeCourseAlert = [KSCloseCourseView shareInstanceShowInView:self.view];
  1454. self.imageArray = [NSMutableArray array];
  1455. self.imageAsset = [NSMutableArray array];
  1456. [self createImageButtonAndPhotosButton];
  1457. MJWeakSelf;
  1458. [self.closeCourseAlert sureCallback:^(NSString * _Nonnull message) {
  1459. [weakSelf submitCloseMessge:message];
  1460. }];
  1461. [self.closeCourseAlert showAlert];
  1462. }
  1463. /**
  1464. 图片和按钮的布局
  1465. */
  1466. #pragma marl 图片和按钮布局
  1467. - (void)createImageButtonAndPhotosButton {
  1468. for (UIView *subView in self.closeCourseAlert.imageContentView.subviews) {
  1469. [subView removeFromSuperview];
  1470. }
  1471. if (self.imageArray.count == 0) {
  1472. self.closeCourseAlert.hasChooseImage = NO;
  1473. }
  1474. else {
  1475. self.closeCourseAlert.hasChooseImage = YES;
  1476. }
  1477. CGFloat space = 10;
  1478. CGFloat buttonWidth = (COURSEVIEWWIDTH - KBUTTON_LEFTSPACE * 2 - space * 2) / 3.0f;
  1479. CGFloat buttonHeight = 80;
  1480. NSInteger section = self.imageArray.count/3 + 1;
  1481. if (self.imageArray.count==MAXPHOTONUMBER) {
  1482. section = MAXPHOTONUMBER / 3;
  1483. }
  1484. CGFloat currentX = 0;
  1485. CGFloat currentY = 0;
  1486. for (NSInteger i = 0; i < self.imageArray.count; i++) {
  1487. currentX = i % 3 * (buttonWidth + space);
  1488. currentY = i / 3 * (buttonHeight + space);
  1489. UIImage *image = self.imageArray [i];
  1490. CGRect frame = CGRectMake(currentX, currentY, buttonWidth, buttonHeight);
  1491. MJWeakSelf;
  1492. KSImageDisplayView *displayView = [KSImageDisplayView shareInstance];
  1493. displayView.frame = frame;
  1494. displayView.tag = 1000 + i;
  1495. [displayView displayImage:image callback:^(IMAGEACTION action, NSInteger viewIndex) {
  1496. if (action == IMAGEACTION_DISPLAY) {
  1497. [weakSelf displayImageIndex:viewIndex];
  1498. }
  1499. else {
  1500. [weakSelf deleteImage:viewIndex];
  1501. }
  1502. }];
  1503. [self.closeCourseAlert.imageContentView addSubview:displayView];
  1504. }
  1505. currentX = self.imageArray .count % 3 * (buttonWidth + space);
  1506. if (self.imageArray.count != MAXPHOTONUMBER) {
  1507. //计算下一个添加按钮位置
  1508. if (self.imageArray.count % 3 == 0) {
  1509. currentY = (self.imageArray.count+1) / 3 * (buttonHeight + space);
  1510. }
  1511. UIButton *cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
  1512. cameraButton.frame = CGRectMake(currentX, currentY, buttonWidth, buttonHeight);
  1513. cameraButton.layer.cornerRadius = 5.0f;
  1514. [cameraButton setImage:[UIImage imageNamed:@"common_image_choose"] forState:UIControlStateNormal];
  1515. [cameraButton setBackgroundColor:[UIColor clearColor]];
  1516. [cameraButton addTarget:self action:@selector(addImgAction:) forControlEvents:UIControlEventTouchUpInside];
  1517. [self.closeCourseAlert.imageContentView addSubview:cameraButton];
  1518. }
  1519. }
  1520. - (void)displayImageIndex:(NSInteger)fileIndex {
  1521. self.isPushChooseView = YES;
  1522. // 展示大图
  1523. LLPhotoBrowser *photoBrowser = [[LLPhotoBrowser alloc] initWithImages:self.imageArray currentIndex:fileIndex];
  1524. photoBrowser.delegate = self;
  1525. photoBrowser.modalPresentationStyle = UIModalPresentationFullScreen;
  1526. [self presentViewController:photoBrowser animated:YES completion:nil];
  1527. }
  1528. - (void)deleteImage:(NSInteger)fileIndex {
  1529. [self.imageArray removeObjectAtIndex:fileIndex];
  1530. [self.imageAsset removeObjectAtIndex:fileIndex];
  1531. [self createImageButtonAndPhotosButton];
  1532. }
  1533. #pragma mark 点击+按钮
  1534. - (void)addImgAction:(UIButton *)sender {
  1535. [self.view endEditing:YES];
  1536. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:IS_IPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
  1537. [alertVC addAction:[UIAlertAction actionWithTitle:@"相机拍摄" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1538. // 调用相机
  1539. self.isPushChooseView = YES;
  1540. [self takePhotos];
  1541. }]];
  1542. [alertVC addAction:[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1543. // 调用相册
  1544. self.isPushChooseView = YES;
  1545. [self pushImagePickerController];
  1546. }]];
  1547. [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1548. }]];
  1549. alertVC.modalPresentationStyle = UIModalPresentationFullScreen;
  1550. [self presentViewController:alertVC animated:true completion:nil];
  1551. }
  1552. - (void)takePhotos {
  1553. // 调用相册
  1554. self.mediaManager = [[KSMediaManager alloc] init];
  1555. self.mediaManager.mediaType = MEDIATYPE_PHOTO;
  1556. self.mediaManager.maxPhotoNumber = MAXPHOTONUMBER;
  1557. self.mediaManager.baseCtrl = self;
  1558. self.mediaManager.imageArray = [self.imageArray mutableCopy];
  1559. self.mediaManager.imageAsset = [self.imageAsset mutableCopy];
  1560. self.mediaManager.needCropImage = NO;
  1561. MJWeakSelf;
  1562. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  1563. [weakSelf displayChooseImage:imageArray imageAsset:imageAsset];
  1564. }];
  1565. [self.mediaManager takePhoto];
  1566. }
  1567. - (void)pushImagePickerController {
  1568. // 调用相册
  1569. self.mediaManager = [[KSMediaManager alloc] init];
  1570. self.mediaManager.mediaType = MEDIATYPE_PHOTO;
  1571. self.mediaManager.maxPhotoNumber = MAXPHOTONUMBER;
  1572. self.mediaManager.baseCtrl = self;
  1573. self.mediaManager.imageArray = [self.imageArray mutableCopy];
  1574. self.mediaManager.imageAsset = [self.imageAsset mutableCopy];
  1575. self.mediaManager.needCropImage = NO;
  1576. MJWeakSelf;
  1577. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  1578. [weakSelf displayChooseImage:imageArray imageAsset:imageAsset];
  1579. }];
  1580. [self.mediaManager pushImagePickerController];
  1581. }
  1582. - (void)displayChooseImage:(NSMutableArray *)imageArray imageAsset:(NSMutableArray *)imageAsset {
  1583. self.imageArray = [imageArray mutableCopy];
  1584. self.imageAsset = [imageAsset mutableCopy];
  1585. // 重新布局
  1586. [self createImageButtonAndPhotosButton];
  1587. }
  1588. #pragma mark -- LLPhotoBrowserDelegate
  1589. - (void)photoBrowser:(LLPhotoBrowser *)photoBrowser backImages:(NSMutableArray *)images {
  1590. NSMutableArray * backImgArray = [images mutableCopy];
  1591. NSMutableArray *imageArray = [NSMutableArray array];
  1592. NSMutableArray *imageAsset = [NSMutableArray array];
  1593. for (NSInteger i = 0; i < self.imageArray.count; i++) {
  1594. UIImage *imagePic = self.imageArray[i];
  1595. if ([backImgArray containsObject:imagePic]) { // 包含
  1596. [imageArray addObject:imagePic];
  1597. [imageAsset addObject:self.imageAsset[i]];
  1598. }
  1599. }
  1600. self.imageArray = [imageArray mutableCopy];
  1601. self.imageAsset = [imageAsset mutableCopy];
  1602. //布局
  1603. [self createImageButtonAndPhotosButton];
  1604. }
  1605. - (void)submitCloseMessge:(NSString *)message {
  1606. self.hud = [self createProgressHUD];
  1607. // 先上传图片
  1608. NSMutableArray *imageDataArray = [NSMutableArray array];
  1609. for (UIImage *image in self.imageArray) {
  1610. NSData *imgData = [UIImage turnsImaegDataByImage:image];
  1611. [imageDataArray addObject:imgData];
  1612. }
  1613. [[KSUploadManager shareInstance] configBucketName:@"daya"];
  1614. [[KSUploadManager shareInstance] mutilUploadImage:imageDataArray fileName:@"onlineClassroomImg" successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  1615. NSMutableArray *urlArray = [NSMutableArray array];
  1616. for (NSString *url in fileUrlArray) {
  1617. [urlArray addObject:url];
  1618. }
  1619. // 再提交申诉
  1620. NSString *attachments = [urlArray componentsJoinedByString:@","];
  1621. [self feedbackAction:attachments message:message];
  1622. } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
  1623. [self.hud hideAnimated:YES];
  1624. if (![NSString isEmptyString:descMessaeg]) {
  1625. [self.tipsView showTipsMessage:descMessaeg inView:self.view];
  1626. }
  1627. }];
  1628. }
  1629. - (void)feedbackAction:(NSString *)attachments message:(NSString *)message {
  1630. }
  1631. #pragma mark ------ 创建MBProgress
  1632. - (MBProgressHUD *)createProgressHUD {
  1633. [MBProgressHUD hideHUD];
  1634. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  1635. hud.mode = MBProgressHUDModeIndeterminate;
  1636. hud.contentColor = [UIColor whiteColor];
  1637. hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
  1638. hud.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
  1639. return hud;
  1640. }
  1641. - (void)dealloc {
  1642. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1643. }
  1644. #pragma mark ----- accompany view
  1645. - (AccompanyView *)accompanyView {
  1646. if (!_accompanyView) {
  1647. _accompanyView = [[AccompanyView alloc] initWithFrame:CGRectMake(0, 0, KLandscapeWidth, KLandscapeHeight)];
  1648. _accompanyView.volume = self.soundVolume;
  1649. _accompanyView.hideDownloadStatus = YES;
  1650. MJWeakSelf;
  1651. [_accompanyView accompanyPlayAction:^(ACCOMPANYACTION action, NSString * _Nullable songId, NSString * _Nullable songName, BOOL isAccompany, NSString * _Nullable songUrl) {
  1652. [weakSelf accompanyViewAction:action songId:songId songName:songName isAccompany:isAccompany songUrl:songUrl];
  1653. }];
  1654. }
  1655. return _accompanyView;
  1656. }
  1657. - (void)accompanyViewAction:(ACCOMPANYACTION)action songId:(NSString *)songId songName:(NSString *)songName isAccompany:(BOOL)isAccompany songUrl:(NSString *)songUrl {
  1658. NSLog(@"------------- song id %@", songId);
  1659. self.soundVolume = self.accompanyView.volume;
  1660. NSLog(@"-------sound volume %zd", self.soundVolume);
  1661. if (action == ACCOMPANYACTION_ADDSONG) {
  1662. // 添加伴奏
  1663. [self.coursewareView showView];
  1664. }
  1665. else if (action == ACCOMPANYACTION_STOP) {
  1666. DeviceType type = self.isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
  1667. // 取消记录当前播放曲目
  1668. [[ClassroomService sharedService] enableMutilMemberDevice:NO type:type songId:[songId intValue] soundVolume:self.soundVolume forUser:@""];
  1669. [ClassroomService sharedService].currentRoom.isPlaySong = NO;
  1670. [self unplayBeatNodeRefreshStream]; // 刷新音频流播放
  1671. }
  1672. else if (action == ACCOMPANYACTION_PLAYSONG) {
  1673. // 如果之前有播放节拍器
  1674. [ClassroomService sharedService].currentRoom.isPlaySong = YES;
  1675. if ([ClassroomService sharedService].currentRoom.isPlayBeat) {
  1676. [ClassroomService sharedService].currentRoom.isPlayBeat = NO;
  1677. NSDictionary *parm = @{@"enable": @(NO),
  1678. @"rate" : @(0),
  1679. @"customType" : @(0),
  1680. @"playVolume" : @(0),
  1681. @"userId" : @"",
  1682. };
  1683. [[ClassroomService sharedService] enablePlayMessage:NO content:[parm mj_JSONString] userId:@""];
  1684. }
  1685. DeviceType type = isAccompany ? DeviceTypeAccompany : DeviceTypeMusicScore;
  1686. // 记录当前播放曲目
  1687. if (![NSString isEmptyString:[ClassroomService sharedService].currentRoom.shareUserId]) {
  1688. NSString *userId = [ClassroomService sharedService].currentRoom.shareUserId;
  1689. [[ClassroomService sharedService] enableMutilMemberDevice:YES type:type songId:[songId intValue] soundVolume:self.soundVolume forUser:userId];
  1690. [self changeSongPlayDisplay:userId];
  1691. }
  1692. else {
  1693. [[ClassroomService sharedService] enableMutilMemberDevice:YES type:type songId:[songId intValue] soundVolume:self.soundVolume forUser:@""];
  1694. [self changeSongPlayDisplay:@""];
  1695. }
  1696. [ClassroomService sharedService].currentRoom.isPlaySong = YES;
  1697. // 同步主屏显示
  1698. [self recordSongMessageWithSongId:songId songName:songName isAccompany:isAccompany songUrl:songUrl];
  1699. }
  1700. else if (action == ACCOMPANYACTION_DISPLAY) { // 显示弹窗
  1701. // [self.progressView showView:songName songId:songId];
  1702. }
  1703. else if (action == ACCOMPANYACTION_CHOOSE) { // 选择的伴奏
  1704. [self recordSongMessageWithSongId:songId songName:songName isAccompany:isAccompany songUrl:songUrl];
  1705. }
  1706. else if (action == ACCOMPANYACTION_MODIFY_VOLUME) {
  1707. // TXAudioEffectManager *audioManager = [TRTCCloud sharedInstance].getAudioEffectManager;
  1708. // [audioManager setAllMusicVolume:self.soundVolume];
  1709. }
  1710. }
  1711. - (void)notiferStudentDownload:(NSString *)songId songUrl:(NSString *)songUrl accompanyUrl:(NSString *)accompanyUrl songName:(NSString *)songName {
  1712. [self.coursewareView hideView];
  1713. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1714. for (RoomMember *member in [ClassroomService sharedService].currentRoom.memberList) {
  1715. if (member.songMessage.count == 0) { // 如果没有选择过曲目
  1716. self.songName = songName;
  1717. self.songId = songId;
  1718. if ([NSString isEmptyString:songUrl]) {
  1719. self.isAccompany = YES;
  1720. self.songUrl = accompanyUrl;
  1721. }
  1722. else {
  1723. self.isAccompany = NO;
  1724. self.songUrl = songUrl;
  1725. }
  1726. member.accompanimentPlayStatus = NO;
  1727. member.downStatus = 0;
  1728. member.playStatus = NO;
  1729. member.url = songUrl;
  1730. member.mp3Url = accompanyUrl;
  1731. member.examSongName = songName;
  1732. member.musicScoreAccompanimentId = [songId intValue];
  1733. ClassSongMessage *songModel = [[ClassSongMessage alloc] init];
  1734. songModel.musicScoreAccompanimentId = [songId intValue];
  1735. songModel.accompanimentPlayStatus = NO;
  1736. songModel.downStatus = 0;
  1737. songModel.playStatus = NO;
  1738. songModel.url = songUrl;
  1739. songModel.mp3Url = accompanyUrl;
  1740. songModel.examSongName = songName;
  1741. [member.songMessage addObject:songModel];
  1742. }
  1743. else {
  1744. BOOL hasDownloadSong = NO;
  1745. for (ClassSongMessage *songModel in member.songMessage) {
  1746. if (songModel.musicScoreAccompanimentId == [songId intValue]) {
  1747. hasDownloadSong = YES;
  1748. break;
  1749. }
  1750. }
  1751. if (hasDownloadSong == NO) { // 如果没有下载 添加到列表
  1752. ClassSongMessage *songModel = [[ClassSongMessage alloc] init];
  1753. songModel.musicScoreAccompanimentId = [songId intValue];
  1754. songModel.accompanimentPlayStatus = NO;
  1755. songModel.downStatus = 0;
  1756. songModel.playStatus = NO;
  1757. songModel.url = songUrl;
  1758. songModel.mp3Url = accompanyUrl;
  1759. songModel.examSongName = songName;
  1760. [member.songMessage addObject:songModel];
  1761. }
  1762. }
  1763. }
  1764. dispatch_main_async_safe(^{
  1765. // 刷新选择窗
  1766. [self.accompanyView refreshView];
  1767. if (![NSString isEmptyString:self.songName]) {
  1768. [self.containerView.toolView showDownloadButtonWithSongName:self.songName isAccompany:self.isAccompany]; // 弹出 当前曲目的下载状态框
  1769. }
  1770. // 通知
  1771. [[ClassroomService sharedService] pushDownloadMusicScoreMsgWithSongId:songId];
  1772. });
  1773. });
  1774. }
  1775. - (void)recordSongMessageWithSongId:(NSString *)songId songName:(NSString *)songName isAccompany:(BOOL)isAccompany songUrl:(NSString *)songUrl {
  1776. self.songId = songId;
  1777. self.songUrl = songUrl;
  1778. self.songName = songName;
  1779. self.isAccompany = isAccompany;
  1780. [self.containerView.toolView showDownloadButtonWithSongName:songName isAccompany:isAccompany]; // 弹出 当前曲目的下载状态框
  1781. }
  1782. #pragma mark ----- 首页弹幕聊天
  1783. - (TXDanMuView *)danView {
  1784. if (!_danView) {
  1785. _danView = [[TXDanMuView alloc] initWithFrame:CGRectMake(38, KLandscapeHeight - 160 - 20, 260, 160) chatGroupId:[ClassroomService sharedService].currentRoom.roomId];
  1786. }
  1787. return _danView;
  1788. }
  1789. - (CoursewareAlertView *)coursewareView {
  1790. if (!_coursewareView) {
  1791. _coursewareView = [CoursewareAlertView shareInstance];
  1792. [_coursewareView configUI];
  1793. MJWeakSelf;
  1794. [_coursewareView chooseCoursewareCallback:^(NSString * _Nonnull musicUrl, NSString * _Nonnull musicName, NSString * _Nonnull songId) {
  1795. [weakSelf notiferStudentDownload:songId songUrl:musicUrl accompanyUrl:nil songName:musicName];
  1796. }];
  1797. }
  1798. return _coursewareView;
  1799. }
  1800. /*
  1801. #pragma mark - Navigation
  1802. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1803. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1804. // Get the new view controller using [segue destinationViewController].
  1805. // Pass the selected object to the new view controller.
  1806. }
  1807. */
  1808. @end