Polyv Help Center

Help Center

6_1-互动学堂场景(Activity)

Updated: 2023-04-17 15:27:57

1 Feature Overview

The interface implementation for the Interactive Classroom scenario is PLVHCLiveHiClassActivity.

This is the shared interface for both instructors and students in the Interactive Classroom scenario. Supported features include: mic connection, chat room, documents, and classroom management.

2 Interface Introduction

/**
  * 启动互动学堂上课页
  *
  * @param activity      上下文Activity
  * @param channelId     频道号
  * @param courseCode    课程号,课程登录时需要传
  * @param lessonId      课节Id
  * @param token         token
  * @param sessionId     场次Id
  * @param userType      用户类型
  * @param viewerId      上课者Id
  * @param viewerName    上课者昵称
  * @param avatarUrl     上课者头像url
  * @return PLVLaunchResult.isSuccess=true表示启动成功,PLVLaunchResult.isSuccess=false表示启动失败
  */
@SuppressWarnings("ConstantConditions")
@NonNull
public static PLVLaunchResult launchHiClass(@NonNull Activity activity,
                                            @NonNull String channelId,
                                            String courseCode,
                                            long lessonId,
                                            @NonNull String token,
                                            @NonNull String sessionId,
                                            @NonNull String userType,
                                            @NonNull String viewerId,
                                            @NonNull String viewerName,
                                            @NonNull String avatarUrl,
                                            boolean isShowDeviceDetectionLayout);

3 Implementation Overview

In the Interactive Classroom, each functional module is encapsulated as a layout class. These layouts are combined in Fragments based on display requirements, and integration is achieved by simply adding Fragments in the Activity.

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 avatar = intent.getStringExtra(EXTRA_AVATAR_URL);
    String userType = intent.getStringExtra(EXTRA_USER_TYPE);

    String token = intent.getStringExtra(EXTRA_TOKEN);
    long lessonId = intent.getLongExtra(EXTRA_LESSON_ID, 0);
    String courseCode = intent.getStringExtra(EXTRA_COURSE_CODE);

    // 设置Config数据
    PLVLiveChannelConfigFiller.setupUser(viewerId, viewerName, avatar, userType);
    PLVLiveChannelConfigFiller.setupChannelId(channelId);
    PLVLiveChannelConfigFiller.setHiClassConfig(token, lessonId, courseCode);
    // 配置互动学堂信息,页面销毁时需调用PLVHiClassGlobalConfig.clear方法清除
    PLVHiClassGlobalConfig.setupConfig(token, userType, PLVSocketUserConstant.USERTYPE_TEACHER.equals(userType), courseCode, lessonId, channelId);
}

3.2 Initialize Live Room Data Manager

private void initLiveRoomManager() {
    // 使用PLVLiveChannelConfigFiller配置好直播参数后,用其创建直播间数据管理器实例
    liveRoomDataManager = new PLVLiveRoomDataManager(PLVLiveChannelConfigFiller.generateNewChannelConfig());
    // 设置场次Id
    String sessionId = getIntent().getStringExtra(EXTRA_SESSION_ID);
    liveRoomDataManager.setSessionId(sessionId);
    // 进行网络请求,获取详情课节数据
    liveRoomDataManager.requestLessonDetail();
}

3.3 Initialize Page UI

private void initView() {
    // 先初始化连麦布局
    plvhcLinkmicLy.init(liveRoomDataManager);
    // 初始化状态栏布局
    plvhcStatusBarLy.init(liveRoomDataManager);
    // 初始化工具栏布局
    plvhcToolBarLy.init(liveRoomDataManager);

    // 初始化连麦的媒体配置
    // 省略代码 ...

    // 初始化文档布局
    plvhcDocumentLy.init(liveRoomDataManager);
    // 初始化学生观看倒计时布局
    // ... 省略代码

    // 注册linkMicView
    // 省略代码 ...

    // 进入横屏模式
    PLVScreenUtils.enterLandscape(this);
}

Different layout combinations can be selected for initialization based on specific business needs.

The layout interfaces for each functional module are as follows:

Mic Connection Layout Interface: IPLVHCLinkMicLayout

Chat Room Layout Interface: PLVHCChatroomLayout

Document Layout Interface: IPLVHCDocumentLayout

Status Bar Layout Interface: IPLVHCStatusBarLayout

Toolbar Layout Interface: IPLVHCToolBarLayout

3.4 Set Layout Callbacks

Since the various functions need to communicate with each other—for example, a change in the mic connection's network status requires updating the network status UI in the status bar, and the toolbar's class start/end button status also changes based on the lesson state—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.

联系客服,在线咨询