5_1-手机开播场景(Activity)
1 Feature Overview
The interface implementation for the mobile streaming scenario is PLVLSLiveStreamerActivity.
The mobile streaming scenario supports features such as streaming, co-hosting, chat, and documents.
2 Interface Introduction
/**
* 启动手机开播页
*
* @param activity 上下文Activity
* @param channelId 频道号
* @param viewerId 开播者ID
* @param viewerName 开播者昵称
* @param avatarUrl 开播者头像url
* @param actor 开播者头衔
* @param isOpenMic 是否打开麦克风
* @param isOpenCamera 是否打开相机
* @param isFrontCamera 是否使用前置摄像头
* @return PLVLaunchResult.isSuccess=true表示启动成功,PLVLaunchResult.isSuccess=false表示启动失败
*/
public static PLVLaunchResult launchStreamer(@NonNull Activity activity,
@NonNull String channelId,
@NonNull String viewerId,
@NonNull String viewerName,
@NonNull String avatarUrl,
@NonNull String actor,
boolean isOpenMic,
boolean isOpenCamera,
boolean isFrontCamera);
3 Implementation Introduction
Mobile streaming encapsulates each functional module into a layout class. Integration can be achieved in the Activity by simply combining these layouts.
3.1 Initialize Page Parameters
private void initParams() {
// 获取输入数据
Intent intent = getIntent();
String channelId = intent.getStringExtra(EXTRA_CHANNEL_ID);
String viewerId = intent.getStringExtra(EXTRA_VIEWER_ID);
String viewerName = intent.getStringExtra(EXTRA_VIEWER_NAME);
String avatarUrl = intent.getStringExtra(EXTRA_AVATAR_URL);
String actor = intent.getStringExtra(EXTRA_ACTOR);
// 设置Config数据
PLVLiveChannelConfigFiller.setupUser(viewerId, viewerName, avatarUrl, PLVSocketUserConstant.USERTYPE_TEACHER, actor);
PLVLiveChannelConfigFiller.setupChannelId(channelId);
}
3.2 Initialize Live Room Data Manager
private void initLiveRoomManager() {
// 使用PLVLiveChannelConfigFiller配置好直播参数后,用其创建直播间数据管理器实例
liveRoomDataManager = new PLVLiveRoomDataManager(PLVLiveChannelConfigFiller.generateNewChannelConfig());
// 进行网络请求,获取直播详情数据
liveRoomDataManager.requestChannelDetail();
}
3.3 Initialize Page UI
private void initView() {
// 初始化推流和连麦布局
plvlsStreamerLy.init(liveRoomDataManager);
// 初始化推流的媒体配置
boolean isOpenMic = getIntent().getBooleanExtra(EXTRA_IS_OPEN_MIC, true);
boolean isOpenCamera = getIntent().getBooleanExtra(EXTRA_IS_OPEN_CAMERA, true);
boolean isFrontCamera = getIntent().getBooleanExtra(EXTRA_IS_FRONT_CAMERA, true);
plvlsStreamerLy.enableRecordingAudioVolume(isOpenMic);
plvlsStreamerLy.enableLocalVideo(isOpenCamera);
plvlsStreamerLy.setCameraDirection(isFrontCamera);
// 初始化状态栏布局
plvlsStatusBarLy.init(liveRoomDataManager);
// 注册成员列表中的streamerView,并请求成员列表接口
plvlsStreamerLy.getStreamerPresenter().registerView(plvlsStatusBarLy.getMemberLayoutStreamerView());
plvlsStreamerLy.getStreamerPresenter().requestMemberList();
// 初始化聊天室布局
plvlsChatroomLy.init(liveRoomDataManager);
// 初始化文档布局
plvlsDocumentLy.init(liveRoomDataManager);
// 进入横屏模式
PLVScreenUtils.enterLandscape(this);
}
The Demo combines layouts for streaming, status bar, member list, chat room, and documents.
The layout interfaces for each functional module are as follows:
Streaming and co-hosting layout interface: IPLVLSStreamerLayout
Status bar layout interface: IPLVLSStatusBarLayout
Chat room layout interface: IPLVLSChatroomLayout
Document layout interface: IPLVLSDocumentLayout
3.4 Set Layout Callbacks
Since communication is required between various functions—for example, clicking the document button in the status bar should trigger the document list display—each layout provides external callbacks to facilitate communication between functional modules.
For detailed interface introductions, please refer to the specific articles for each functional module.
For callback setup and handling, please refer to the Set Layout Callbacks method block in the Activity.
