直播场景模式支持的功能有:媒体(播放器、PPT、浮窗、竖屏皮肤)、页面菜单、连麦、互动应用、横屏聊天室、横屏皮肤。 回放场景模式支持的功能有:媒体(播放器、PPT、浮窗、竖屏皮肤)、页面菜单、横屏聊天室、横屏皮肤。
- (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;
}
- (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){ // 视频类型为 直播回放
}
}
- (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
}
}
- (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];
}