保利威文档中心

幫助中心

5_1-手机开播场景(页面)

更新時間:2023-04-27 09:43:40

1 功能概述

手機開播場景的頁面實作為 PLVLSStreamerViewController

手機開播場景支援的功能有推流、連麥、聊天、PPT&白板、文件管理。

2 使用介紹

由於頻道資訊、登入使用者帳號資訊等手機開播頁面所需的初始化參數,在登入時已透過類別 PLVRoomLoginClient 進行配置,並在 PLVRoomLoginClient 內部使用 PLVRoomDataManager 類別的單例對這些直播間數據資訊進行管理,進入手機開播場景的頁面只需要以下程式碼:

PLVLSStreamerViewController *vctrl = [[PLVLSStreamerViewController alloc] init];
vctrl.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vctrl animated:YES completion:nil];

離開手機開播頁面除了把頁面從頁面堆疊移出,務必呼叫 PLVRoomLoginClient 的登出介面,移除 PLVRoomDataManager 單例對當前直播間數據的持有和監聽:

[PLVRoomLoginClient logout];
[self dismissViewControllerAnimated:YES completion:nil];

3 頁面介紹

3.1 頁面 UI

手機開播場景頁面佈局,由以下頁面 UI 控制項組成:

@property (nonatomic, strong) PLVLSStatusAreaView *statusAreaView;     // 顶部状态栏区域
@property (nonatomic, strong) UIView *streamerAreaView;				   // 右侧推流&连麦区域
@property (nonatomic, strong) PLVLSDocumentAreaView *documentAreaView; // 左侧白板&PPT区域
@property (nonatomic, strong) PLVLSChatroomAreaView *chatroomAreaView; // 左下角聊天室区域

其次,手機開播頁面還包含以下(不長駐) UI 控制項:

@property (nonatomic, strong) PLVLSChannelInfoSheet *channelInfoSheet; // 频道信息弹层
@property (nonatomic, strong) PLVLSSettingSheet *settingSheet;		   // 设置弹层
@property (nonatomic, strong) PLVLSMemberSheet *memberSheet;		   // 成员管理弹层
@property (nonatomic, strong) PLVLSCountDownView *coutBackView; // 开始上课时的倒数蒙层

最後,手機開播頁面不支援直立,只支援橫向,因此需對父類別 UIViewController 的以下方法進行覆寫:

- (BOOL)shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}

3.2 直播間數據監聽

頁面需要對直播間數據 PLVRoomData 進行即時監聽並作出相應的 UI 更新,首先,需要導入標頭檔 #import "PLVRoomDataManager.h",並讓 PLVLSStreamerViewController 遵循協定 PLVRoomDataManagerProtocol,然後添加監聽,程式碼範例如下:

[[PLVRoomDataManager sharedManager] addDelegate:self delegateQueue:dispatch_get_main_queue()];

程式碼範例中,delegateQueue 參數傳入 dispatch_get_main_queue() 表示希望回呼方法從主執行緒執行,這是由於當前頁面相關回呼裡執行的操作都是更新 UI。

關於 PLVRoomDataManager 的更多介紹,詳見文件《6_2 核心common-數據》。

手機開播頁面需要監聽的 delegate 方法如下:

#pragma mark - PLVRoomDataManager Protocol

/// 菜单信息 menuInfo 更新
- (void)roomDataManager_didMenuInfoChanged:(PLVLiveVideoChannelMenuInfo *)menuInfo {
    // 此时更新频道信息弹层数据不能使用self,会过早触发弹层初始化,导致弹层高度计算错误
    [_channelInfoSheet updateChannelInfoWithData:menuInfo];
}

監聽的移除在 2 使用介紹 裡面提到的 PLVRoomLoginClient 的登出方法 +logout 內部進行,所以無需額外做移除監聽的操作。

联系客服,在线咨询