Polyv Help Center

Help Center

3_4-云课堂场景-连麦

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

1 Feature Overview

Polyv Cloud Classroom SDK supports the link mic feature, allowing free selection of hand-raising, audio, and video link mic, as well as multi-user link mic to enrich classroom content.

Link mic process: The instructor initiates a link mic -> Students raise their hands to apply -> The instructor approves the student's application -> The student officially joins the link mic.

2 Usage Demo

//初始化
ViewStub linkmicLayoutViewStub = findViewById(R.id.plvlc_linkmic_layout);
IPLVLCLinkMicLayout linkMicLayout = (IPLVLCLinkMicLayout) linkmicLayoutViewStub.inflate();
linkMicLayout.init(liveRoomDataManager, linkMicControlBar);
linkMicLayout.hideAll();
//设置连麦布局监听器
linkMicLayout.setOnPLVLinkMicLayoutListener();

For detailed calling code and communication with other modules, please refer to the code calls in the PLVLCCloudClassActivity class.

3 Interface Introduction

3.1 IPLVLCLinkMicControlBar

An Interface encapsulated for the link mic control bar layout in the cloud classroom scenario. It is used in [PLVLinkMicLayout] to update the latest link mic status to the control bar. Defines:

  1. Methods directly callable from outside
  2. Event listeners that require external responses
public interface IPLVLCLinkMicControlBar {

    // <editor-fold defaultstate="collapsed" desc="1. 外部直接调用的方法">

    /**
     * 设置监听器
     *
     * @param onPLCLinkMicControlBarListener listener
     */
    void setOnPLCLinkMicControlBarListener(OnPLCLinkMicControlBarListener onPLCLinkMicControlBarListener);

    /**
     * 设置讲师开启或关闭连麦
     *
     * @param isTeacherOpenLinkMic true表示讲师开启连麦
     */
    void setIsTeacherOpenLinkMic(boolean isTeacherOpenLinkMic);

    /**
     * 设置开关摄像头
     *
     * @param toOpen true表示要打开摄像头
     */
    void setCameraOpenOrClose(boolean toOpen);

    /**
     * 开关麦克风
     *
     * @param toOpen true表示要打开麦克风
     */
    void setMicrophoneOpenOrClose(boolean toOpen);


    /**
     * 设置上麦成功
     */
    void setJoinLinkMicSuccess();

    /**
     * 设置离开连麦
     */
    void setLeaveLinkMic();


    /**
     * 设置是音频连麦还是视频连麦
     *
     * @param isAudio true表示是音频连麦,false表示是视频连麦
     */
    void setIsAudio(boolean isAudio);

    /**
     * 显示
     */
    void show();

    /**
     * 隐藏
     */
    void hide();
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="2. 需要外部响应的事件监听器">
    interface OnPLCLinkMicControlBarListener {
        /**
         * 点击请求上麦
         */
        void onClickRingUpLinkMic();

        /**
         * 点击下麦
         */
        void onClickRingOffLinkMic();

        /**
         * 点击开关摄像头
         *
         * @param toClose true表示关闭。false表示开启
         */
        void onClickCameraOpenOrClose(boolean toClose);

        /**
         * 点击前后置摄像头
         *
         * @param toFront true表示前置,false表示后置
         */
        void onClickCameraFrontOfBack(boolean toFront);

        /**
         * 点击开关麦克风
         *
         * @param toClose true表示关闭。false表示开启
         */
        void onClickMicroPhoneOpenOrClose(boolean toClose);

    }
    // </editor-fold>

}

3.2 IPLVLCLinkMicLayout

An Interface encapsulated for the link mic layout in the cloud classroom scenario. Defines:

  1. The link mic layout interface used by the cloud classroom
  2. Event listeners that require external responses
public interface IPLVLCLinkMicLayout {

    
    // <editor-fold defaultstate="collapsed" desc="1. 外部直接调用的方法">

    /**
     * 初始化,设置数据
     *
     * @param liveRoomDataManager 频道数据
     */
    void init(IPLVLiveRoomDataManager liveRoomDataManager, IPLVLCLinkMicControlBar linkMicControlBar);

    /**
     * 销毁
     */
    void destroy();

    /**
     * 显示
     */
    void showAll();

    /**
     * 隐藏
     */
    void hideAll();

    /**
     * 隐藏连麦列表
     */
    void hideLinkMicList();

    /**
     * 显示连麦列表
     */
    void showLinkMicList();

    /**
     * 隐藏连麦控制条
     */
    void hideControlBar();

    /**
     * 显示连麦控制条
     */
    void showControlBar();

    /**
     * 设置是否讲师打开连麦
     *
     * @param isTeacherOpenLinkMic 讲师是否打开连麦
     */
    void setIsTeacherOpenLinkMic(boolean isTeacherOpenLinkMic);

    /**
     * 设置连麦类型
     *
     * @param isAudioLinkMic true表示是音频连麦,false表示是视频连麦
     */
    void setIsAudio(boolean isAudioLinkMic);

    /**
     * 是否已经加入连麦
     *
     * @return true表示已经加入了连麦,false表示没有加入连麦
     */
    boolean isJoinLinkMic();

    /**
     * Media是否被切换到连麦列表了
     *
     * @return true表示media在连麦列表,false表示media不在连麦列表
     */
    boolean isMediaShowInLinkMicList();

    /**
     * 设置连麦布局监听器
     *
     * @param onPLVLinkMicLayoutListener 连麦布局监听器
     */
    void setOnPLVLinkMicLayoutListener(OnPLVLinkMicLayoutListener onPLVLinkMicLayoutListener);

    /**
     * 获取横屏时连麦布局的宽度
     *
     * @return 横屏宽
     */
    int getLandscapeWidth();
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="2. 需要外部响应的事件监听器">

    /**
     * 连麦布局监听器
     */
    interface OnPLVLinkMicLayoutListener {
        //todo 未来将支持画笔事件

        // <editor-fold defaultstate="collapsed" desc="画笔事件监听">
        //        //点击擦除PPT画笔
        //        void onUpdateEraseStatus(boolean toErase);
        //
        //        //更新画笔颜色
        //        void onUpdateBrushColor(String color);
        //
        //        //更新画笔状态
        //        boolean onUpdateBrushStatus(boolean unSelected);
        //        // </editor-fold>

        // <editor-fold defaultstate="collapsed" desc="连麦事件监听">

        /**
         * 加入连麦成功
         */
        void onJoinChannelSuccess();

        /**
         * 离开连麦
         */
        void onLeaveChannel();
        // </editor-fold>

        // <editor-fold defaultstate="collapsed" desc="点击事件监听器">

        /**
         * 切换连麦连麦中讲师的位置,因为纯视频的频道连麦时,讲师默认在主屏
         *
         * @param viewSwitcher switchView的切换器
         * @param switchView   讲师连麦Item的switch view
         */
        void onChangeTeacherLocation(PLVViewSwitcher viewSwitcher, PLVSwitchViewAnchorLayout switchView);

        /**
         * 点击连麦Item与media切换,只切换一次。
         * 当点击连麦列表item时,media在主屏幕,或刚好点击的item就是media,那么此时只发生一次切换,即media和连麦Item切换。
         *
         * @param switchView 连麦Item的switch view
         */
        void onClickSwitchWithMediaOnce(PLVSwitchViewAnchorLayout switchView);

        /**
         * 点击连麦Item与media切换,切换两次。
         * 当点击连麦列表item时,media在连麦列表中的其他item,那么要发生两次切换:
         * 1. 先将media和此时主屏幕的那个连麦item进行切换,回到初始默认的位置。
         * 2. 再将此次点击的连麦item与主屏幕的media进行切换。
         *
         * @param switchViewHasMedia     连麦列表的上有media的那个switch view
         * @param switchViewGoMainScreen 被点击的item的switch view,对应将会被切换到主屏幕的连麦item
         */
        void onClickSwitchWithMediaTwice(PLVSwitchViewAnchorLayout switchViewHasMedia, PLVSwitchViewAnchorLayout switchViewGoMainScreen);
        // </editor-fold>

    }
// </editor-fold>
}

4 Implementation Introduction

The implementation class of IPLVLCLinkMicControlBar is PLVLCLinkMicControlBar.

The implementation class of IPLVLCLinkMicLayout is PLVLCLinkMicLayout.

4.1 PLVLCLinkMicControlBar

PLVLCLinkMicControlBar is the implementation of the link mic control bar. The following points need attention:

  1. The link mic control bar is created in the Activity and passed as a parameter to PLVLCLinkMicLayout, where the link mic layout responds to control bar click events and refreshes the UI state of the link mic control bar.

  2. Two sets of Views are used for portrait and landscape orientations to implement the UI for each.

  3. The main logic focuses on animations, click event responses, and keeping the two sets of UI (portrait and landscape) synchronized.

4.2 PLVLCLinkMicLayout

The link mic layout is the main component of the link mic feature module, with the primary UI being the link mic list. The same link mic list object is shared between portrait and landscape orientations.

4.2.1 Initialize View

During initialization, the link mic list RecyclerView and the adapter PLVLinkMicListAdapter used for the link mic list must be initialized.

private void initView() {
    //...
    //init RecyclerView
    rvLinkMicList.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
    rvLinkMicList.addItemDecoration(landscapeItemDecoration);
    //init adapter
    linkMicListAdapter = new PLVLinkMicListAdapter(...)
    //init方向
    curIsLandscape = PLVScreenUtils.isLandscape(getContext());
}
4.2.2 Initialize Data

Data initialization occurs in the external API methods:

@Override
public void init(IPLVLiveRoomDataManager liveRoomDataManager, IPLVLCLinkMicControlBar linkMicControlBar) {
    linkMicPresenter = new PLVLinkMicPresenter(liveRoomDataManager, this);
    initLinkMicControlBar(linkMicControlBar);
}

Since the link mic feature module uses the MVP pattern, the Presenter is initialized first.

Additionally, the link mic control bar is initialized, and click events on the link mic control bar are monitored.

The main logic of the link mic layout is primarily concentrated in the implementation of the View layer interface of the MVP pattern. Refer to the comments and implementation of this interface:

interface IPLVLinkMicView {
    /**
     * 响应连麦错误
     */
    void onLinkMicError(int errorCode, Throwable throwable);
    /**
     * 响应讲师开启连麦
     */
    void onTeacherOpenLinkMic();
    /**
     * 响应讲师关闭连麦
     */
    void onTeacherCloseLinkMic();
    /**
     * 响应讲师允许连麦
     */
    void onTeacherAllowJoin();
    /**
     * 响应加入连麦频道超时
     */
    void onAllowButJoinTimeout();
    /**
     * 响应在加入频道之前,View层应创建连麦适配器和初始化连麦布局
     *
     * @param linkMicUid  我的连麦Id
     * @param isAudio     是否是音频连麦
     * @param linkMicList 连麦列表。在实现中,要用该列表去渲染
     */
    void onBeforeJoinChannel(String linkMicUid, boolean isAudio, List<PLVLinkMicItemDataBean> linkMicList);
    /**
     * 响应加入连麦频道成功
     */
    void onJoinChannelSuccess();
    /**
     * 响应离开连麦频道
     */
    void onLeaveChannel();
    /**
     * 响应用户加入连麦频道
     *
     * @param uids
     */
    void onUsersJoin(List<String> uids);
    /**
     * 响应用户离开连麦频道
     *
     * @param uids
     */
    void onUsersLeave(List<String> uids);
    /**
     * 回调我当前不在连麦列表
     */
    void onNotInLinkMicList();
    /**
     * 响应用户开关视频
     *
     * @param uid  用户id
     * @param mute true表示关闭视频,false表示开启视频
     * @param pos  列表中的位置
     */
    void onUserMuteVideo(final String uid, final boolean mute, int pos);
    /**
     * 响应用户开关音频
     *
     * @param uid  用户id
     * @param mute true表示关闭音频,false表示开启音频
     * @param pos  列表中的位置
     */
    void onUserMuteAudio(final String uid, final boolean mute, int pos);
    /**
     * 响应本地用户麦克风音量变化
     */
    void onLocalUserMicVolumeChanged();
    /**
     * 响应远端用户麦克风音量变化
     */
    void onRemoteUserVolumeChanged(List<PLVLinkMicItemDataBean> linkMicList);
    /**
     * 切换第一画面
     *
     * @param linkMicId 新的第一画面的连麦Id
     */
    void onSwitchFirstScreen(String linkMicId);
    /**
     * 设置第一画面的连麦ID
     *
     * @param linkMicId 新的第一画面的连麦Id
     */
    void setFirstScreenLinkMicId(String linkMicId);
    /**
     * 隐藏连麦列表中的讲师item,并根据isNeedSwitchToMain参数决定是否要把该item的view切换到主屏
     *
     * @param linkMicId          讲师的连麦id
     * @param teacherPos         讲师item在当前连麦列表中的索引
     * @param isNeedSwitchToMain 是否要切换到主屏
     */
    void onAdjustTeacherLocation(String linkMicId, int teacherPos, boolean isNeedSwitchToMain);
    /**
     * 切换PPT View和第一画面的位置
     *
     * @param toMainScreen true表示切换到主屏幕,false表示切回到悬浮窗
     */
    void onSwitchPPTViewLocation(boolean toMainScreen);
    /**
     * PPT是否被切换到连麦列表了
     *
     * @return true表示PPT在连麦列表,false表示PPT不在连麦列表
     */
    boolean isMediaShowInLinkMicList();
    /**
     * 获取PPTView在连麦列表中的位置index
     *
     * @return ppt在连麦列表中的位置
     */
    int getMediaViewIndexInLinkMicList();
    /**
     * 点击连麦列表[index]位置上的画面
     *
     * @param index 连麦列表中的位置
     */
    void performClickInLinkMicListItem(int index);
    /**
     * 更新所有整个连麦列表
     */
    void updateAllLinkMicList();
}

5 Subdirectory Introduction

5.1 adapter directory

  1. PLVLinkMicListAdapter

    The adapter for the link mic list RecyclerView. This class handles each specific link mic item and exposes click events for the link mic items.

5.2 service directory

  1. PLVLCLinkMicForegroundService

    Starts a foreground service during a link mic to ensure normal link mic functionality when in the background.

5.3 widget directory

This is the custom View directory for the link mic module.

  1. PLVLCLinkMicRingButton

    The link mic microphone button.

  2. PLVLinkMicRvLandscapeItemDecoration

    The ItemDecoration for the landscape link mic list.

联系客服,在线咨询