云课堂场景(页面)
- 1 Feature Overview
- 2 Initialize Objects and Data
- 3 Initial Configuration (Add Screen Rotation and Interactive Notifications)
- 4 Initialize Page UI
- 5 Set AreaView Delegate Callbacks
- 6 Handle Screen Rotation
1 Feature Overview
The cloud classroom scene module is located in the PolyvLiveCloudClassScene folder, with the page implementation as PLVLCCloudClassViewController.
The cloud classroom supports two scene modes: live and playback. The UI interfaces for both modes are highly shared, with functional modules encapsulated into multiple UI areas (AreaView). Integration is achieved by simply combining layouts on the page.
The live scene mode supports the following features: media (player, PPT, floating window, portrait skin), page menu, live mic connection, interactive applications, landscape chat room, and landscape skin. The playback scene mode supports the following features: media (player, PPT, floating window, portrait skin), page menu, landscape chat room, and landscape skin.
The area classes for each UI functional module are as follows:
- Media Area: PLVLCMediaAreaView
- Live Mic Connection Area: PLVLCLinkMicAreaView
- Menu Area: PLVLCLivePageMenuAreaView
- Landscape Chat Area: PLVLCChatLandscapeView
- Landscape Skin Area: PLVLCLiveRoomPlayerSkinView
- Interactive Application Area: PLVInteractView
2 Initialize Objects and Data
Primarily initializes login channel information, settings, and listens to chat room sockets.
- (instancetype)init {
self = [super init];
if (self) {
[[PLVRoomDataManager sharedManager] addDelegate:self delegateQueue:dispatch_get_main_queue()];
PLVRoomData *roomData = [PLVRoomDataManager sharedManager].roomData;
PLVRoomUser *roomUser = roomData.roomUser;
/// Socket 登录管理
PLVSocketUserType userType = roomUser.viewerType == PLVRoomUserTypeStudent ? PLVSocketUserTypeStudent : PLVSocketUserTypeSlice;
[[PLVSocketManager sharedManager] loginWithChannelId:roomData.channelId
viewerId:roomUser.viewerId
viewerName:roomUser.viewerName
avatarUrl:roomUser.viewerAvatar actor:nil userType:userType];
socketDelegateQueue = dispatch_get_global_queue(0, DISPATCH_QUEUE_PRIORITY_DEFAULT);
[[PLVSocketManager sharedManager] addDelegate:self delegateQueue:socketDelegateQueue];
// 启动聊天室管理器
[[PLVLCChatroomViewModel sharedViewModel] setup];
[[PLVLCChatroomViewModel sharedViewModel] addDelegate:self delegateQueue:dispatch_get_main_queue()];
}
return self;
}
- For the specific implementation of
PLVRoomDataManagerandPLVRoomData, refer to 7_2 Core Common - Data - For the specific implementation of
PLVSocketManager, refer to 7_4 Core Common - Chat Room
3 Initial Configuration (Add Screen Rotation and Interactive Notifications)
- (void)setupModule{
// 通用的 配置
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(interfaceOrientationDidChange:)
name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
PLVRoomData *roomData = [PLVRoomDataManager sharedManager].roomData;
if (roomData.videoType == PLVChannelVideoType_Live) { // 视频类型为 直播
/// 监听事件
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationForOpenBulletin:) name:PLVLCChatroomOpenBulletinNotification object:nil];
} else if (roomData.videoType == PLVChannelVideoType_Playback){ // 视频类型为 直播回放
}
}
4 Initialize Page UI
- (void)setupUI {
/// 注意:1. 此处不建议将共同拥有的图层,提炼在 if 判断外,来做“代码简化”
/// 因为此处涉及到添加顺序,而影响图层顺序。放置在 if 内,能更加准确地配置图层顺序,也更清晰地预览图层顺序。
/// 2. 懒加载过程中(即Getter),已增加判断,若场景不匹配,将创建失败并返回nil
PLVRoomData *roomData = [PLVRoomDataManager sharedManager].roomData;
if (roomData.videoType == PLVChannelVideoType_Live) { // 视频类型为 直播
/// 初始化直播的UI
}else if (roomData.videoType == PLVChannelVideoType_Playback){ // 视频类型为 直播回放
/// 初始化回放的UI
}
}
Depending on whether the current mode is live or playback, different combinations of AreaView controls will be selected for initialization.
5 Set AreaView Delegate Callbacks
Since communication is required between various functions—for example, the player's live start and end states affect the display and hiding of media—each layout provides external callbacks to facilitate communication between functional modules.
For detailed interface descriptions, refer to the specific introduction articles for each functional module.
For callback setup and handling, refer to the Set AreaView Callbacks method block in the page.
6 Handle Screen Rotation
Both live and playback modes in the cloud classroom scene support landscape and portrait viewing, requiring corresponding code handling on the page.
Refer to the code block: Screen Rotation Handling
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
[self updateUI];
}
- (void)interfaceOrientationDidChange:(NSNotification *)notification {
BOOL fullScreen = [UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height;
self.fullScreenDifferent = (self.currentLandscape != fullScreen);
self.currentLandscape = fullScreen;
// 全屏播放器皮肤 liveRoomSkinView 的弹幕按钮 danmuButton 为显示状态,且为非选中状态,且当前为横屏时,才显示弹幕
BOOL danmuEnable = !self.liveRoomSkinView.danmuButton.selected && !self.liveRoomSkinView.danmuButton.hidden;
[self.mediaAreaView showDanmu:fullScreen && danmuEnable];
// 调用setStatusBarHidden后状态栏旋转横屏不自动隐藏
[[UIApplication sharedApplication] setStatusBarHidden:fullScreen];
}
