3_3-云课堂场景-PPT
1 Feature Overview
The PPT feature displays the PPT or document currently being operated by the instructor as a small floating window.
Since the PPT is embedded and displayed within the floating window, this module separates the floating window and the PPT into two interfaces: one interface represents the floating window with the embedded PPT, and the other interface represents the PPT itself.
2 Usage Demo
//初始化
IPLVLCFloatingPPTLayout floatingPPTLayout=findViewById(R.id.plvlc_ppt_floating_ppt_layout);
//设置悬浮窗点击监听器
floatingPPTLayout.setOnFloatingViewClickListener();
//设置关闭悬浮窗的点击监听器
floatingPPTLayout.setOnClickCloseListener();
//设置直播PPT事件监听器
floatingPPTLayout.getPPTView().initLivePPT();
//设置回放PPT事件监听
floatingPPTLayout.getPPTView().initPlaybackPPT();
//销毁
floatingPPTLayout.destroy();
For detailed calling code and communication with other modules, please refer to the code calls in the PLVLCCloudClassActivity class.
3 Interface Introduction
3.1 IPLVLCFloatingPPTLayout
IPLVLCFloatingPPTLayout is the PPT floating window layout defined for the cloud classroom scenario, which defines:
- Methods directly callable externally
- Event listeners that require external responses
public interface IPLVLCFloatingPPTLayout {
// <editor-fold defaultstate="collapsed" desc="1. 外部直接调用的方法">
/**
* 设置服务端的PPT开关
*
* @param enable true表示打开PPT,false表示关闭PPT
*/
void setServerEnablePPT(boolean enable);
/**
* 显示
*/
void show();
/**
* 隐藏
*/
void hide();
/**
* PPT是否在悬浮窗中
*/
boolean isPPTInFloatingLayout();
/**
* 获取PPTView
*/
IPLVLCPPTView getPPTView();
/**
* 设置悬浮窗点击监听器
*
* @param li listener
*/
void setOnFloatingViewClickListener(View.OnClickListener li);
/**
* 设置显示关闭悬浮窗的监听器
*
* @param onClickCloseListener listener
*/
void setOnClickCloseListener(IPLVOnClickCloseFloatingView onClickCloseListener);
/**
* 获取切换View
*/
PLVSwitchViewAnchorLayout getPPTSwitchView();
/**
* 销毁
*/
void destroy();
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="2. 需要外部响应的事件监听器">
interface IPLVOnClickCloseFloatingView {
/**
* 点击关闭
*/
void onClickCloseFloatingView();
}
// </editor-fold>
}
3.2 IPLVLCPPTView
An interface encapsulated for the PPT layout in the cloud classroom scenario, which defines:
- Methods directly callable externally
- Event listeners that require external responses
public interface IPLVLCPPTView {
// <editor-fold defaultstate="collapsed" desc="1. 外部直接调用的方法 - live部分,定义 直播PPT独有的方法">
/**
* 初始化直播PPT
*
* @param onPLVLCPPTViewListener listener
*/
void initLivePPT(OnPLVLCLivePPTViewListener onPLVLCPPTViewListener);
/**
* 移除延迟时间
*/
void removeDelayTime();
/**
* 恢复延迟时间
*/
void recoverDelayTime();
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="1. 外部直接调用的方法 - playback部分,定义回放PPT独有的方法">
/**
* 初始化回放PPT
*
* @param onPlaybackPPTViewListener listener
*/
void initPlaybackPPT(OnPLVLCPlaybackPPTViewListener onPlaybackPPTViewListener);
/**
* 设置当前回放视频播放的位置
*
* @param position 播放位置
*/
void setPlaybackCurrentPosition(int position);
/**
* 获取回放专用的PPTView,用于绑定到播放器内部
*
* @return 回放专用的PPTView的接口
*/
IPolyvPPTView getPlaybackPPTViewToBindInPlayer();
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="1. 外部直接调用的方法 - common部分,定义直播PPT和回放PPT通用的方法">
/**
* 发送消息到webView
*
* @param event 消息的事件
* @param message 消息内容
*/
void sendWebMessage(String event, String message);
/**
* 重新加载
*/
void reLoad();
/**
* 销毁
*/
void destroy();
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="2. 需要外部响应的事件监听器 - PPT直播事件监听器">
/**
* PPT直播事件监听器
*/
interface OnPLVLCLivePPTViewListener {
/**
* 直播回调,切换横竖屏
*
* @param toLandscape true表示切换到横屏,false表示切换到竖屏
*/
void onLiveChangeToLandscape(boolean toLandscape);
/**
* 直播回调,开始或暂停视频
*
* @param toStart true表示开始播放视频,false表示暂停播放视频
*/
void onLiveStartOrPauseVideoView(boolean toStart);
/**
* 直播回调,重播视频
*/
void onLiveRestartVideoView();
/**
* 直播回调,回到上一个Activity
*/
void onLiveBackTopActivity();
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="2. 需要外部响应的事件监听器 - PPT回放事件监听器">
/**
* PPT回放事件监听器
*/
interface OnPLVLCPlaybackPPTViewListener {
/**
* 回放回调,切换PPTView的位置
*
* @param toMainScreen true表示切换到主屏幕,false表示切回到小窗
*/
void onPlaybackSwitchPPTViewLocation(boolean toMainScreen);
}
// </editor-fold>
}
4 Implementation Introduction
The implementation class of IPLVLCFloatingPPTLayout is PLVLCFloatingPPTLayout.
The implementation class of IPLVLCPPTView is PLVLCPPTView.
4.1 PLVLCFloatingPPTLayout
PLVLCFloatingPPTLayout is a full-screen layout. Its child view, PLVTouchFloatingView, acts as the actual floating window control to handle the floating window's drag events.
4.1.2 View Initialization
During initialization, you can set the initial positions of the floating window for both landscape and portrait orientations, as well as the size of the floating window in each orientation.
//初始化View
private void initView() {
//...
//设置初始化位置
int screenWidth = Math.min(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight());
int screenHeight = Math.max(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight());
floatingView.setInitLocation(
screenWidth - PLVScreenUtils.dip2px(DP_FLOATING_PPT_WIDTH_PORT),
PLVScreenUtils.dip2px(DP_ORIGIN_MARGIN_TOP_PORTRAIT),
screenHeight - PLVScreenUtils.dip2px(DP_FLOATING_PPT_WIDTH_LAND) - PLVScreenUtils.dip2px(DP_ORIGIN_MARGIN_RIGHT_LANDSCAPE),
PLVScreenUtils.dip2px(DP_ORIGIN_MARGIN_TOP_LANDSCAPE)
);
}
4.1.2 Data Initialization
The floating window uses the MVP pattern internally, requiring the initialization of a Presenter.
//初始化数据
private void initData() {
presenter = new PLVLiveFloatingPresenter();
presenter.init(this);
}
The View layer interface implemented by the floating window is:
/**
* 悬浮窗View
*/
interface IPLVLiveFloatingView {
/**
* 设置讲师信息
*
* @param nick 讲师昵称
* @param picUrl 讲师图片Url
*/
void updateTeacherInfo(String nick, String picUrl);
}
It is used to update the instructor's information on the floating window.
4.2 PLVLCPPTView
PLVLCPPTView is the implementation of the PPT. The following points should be noted:
- It is a business encapsulation of the SDK class:
PolyvPPTWebView. - It uses the MVP pattern to handle logic such as sending and receiving server data.
- Since the PPT can be used in both live streaming and playback, its interfaces are divided into three groups: live, playback, and common. For details, refer directly to the interface comments.
4.2.1 View Initialization
//初始View
private void initialView(Context context) {
//...
//设置占位图
pptPlaceHolderView.setPlaceHolderImg(R.drawable.plvlc_ppt_placeholder);
//设置占位图文本
pptPlaceHolderView.setPlaceHolderText(getResources().getString(R.string.plv_ppt_no_document));
//...
//加载ppt的webView
pptWebView.loadWeb();
}
4.2.2 Data Initialization
The PPT uses the MVP pattern internally, requiring the initialization of a Presenter.
//初始化数据
private void initData() {
presenter = new PLVPPTPresenter();
presenter.init(this);
}
The View layer interface implemented by the PPT is:
/**
* PPTView
*/
interface IPLVPPTView {
/**
* 发送消息到webView
*
* @param msg 消息
*/
void sendMsgToWebView(String msg);
/**
* 发送消息到webView
*
* @param msg 消息
* @param event 事件
*/
void sendMsgToWebView(String msg, String event);
/**
* 隐藏加载中图片
* 直播时,则聊天室登录后,收到PPT控制消息时,隐藏加载中图片。
* 回放时,在收到PPT的prepare回调后,异常加载中图片。
*/
void hideLoading();
}
