4_1-带货场景(Activity)
1 Feature Overview
The interface implementation for the e-commerce scenario is PLVECLiveEcommerceActivity.
This is the shared interface for both live and replay modes in the e-commerce scenario.
Features supported in live mode include: player, chat room, products, tipping, and interactive applications.
Features supported in replay mode include: player.
2 Interface Introduction
//1.3.0增加viewerAvatar参数
/**
* 启动直播带货直播页
*
* @param activity 上下文Activity
* @param channelId 频道号
* @param viewerId 观众ID
* @param viewerName 观众昵称
* @param viewerAvatar 观众头像地址
* @return PLVLaunchResult.isSuccess=true表示启动成功,PLVLaunchResult.isSuccess=false表示启动失败
*/
public static PLVLaunchResult launchLive(@NonNull Activity activity,
@NonNull String channelId,
@NonNull String viewerId,
@NonNull String viewerName,
@NonNull String viewerAvatar);
/**
* 启动直播带货回放页
*
* @param activity 上下文Activity
* @param channelId 频道号
* @param vid 视频ID
* @param viewerId 观众ID
* @param viewerName 观众昵称
* @param viewerAvatar 观众头像地址
* @param videoListType 回放视频类型,参考{@link PolyvPlaybackListType}
* @return PLVLaunchResult.isSuccess=true表示启动成功,PLVLaunchResult.isSuccess=false表示启动失败
*/
public static PLVLaunchResult launchPlayback(@NonNull Activity activity,
@NonNull String channelId,
@NonNull String vid,
@NonNull String viewerId,
@NonNull String viewerName,
@NonNull String viewerAvatar,
int videoListType);
3 Implementation Overview
In live e-commerce, each functional module is encapsulated as a Layout class. Based on display requirements, layouts are combined in Fragments, and integration is completed by simply adding Fragments in the Activity.
3.1 Initialize Page Parameters
private void initParams() {
// 获取输入数据
Intent intent = getIntent();
boolean isLive = intent.getBooleanExtra(EXTRA_IS_LIVE, true);
String channelId = intent.getStringExtra(EXTRA_CHANNEL_ID);
String viewerId = intent.getStringExtra(EXTRA_VIEWER_ID);
String viewerName = intent.getStringExtra(EXTRA_VIEWER_NAME);
// 设置Config数据
PLVLiveChannelConfigFiller.setIsLive(isLive);
PLVLiveChannelConfigFiller.setupUser(viewerId, viewerName);
PLVLiveChannelConfigFiller.setupChannelId(channelId);
// 根据不同模式,设置对应参数
if (!isLive) { // 回放模式
String vid = intent.getStringExtra(EXTRA_VID);
int videoListType = intent.getIntExtra(EXTRA_VIDEO_LIST_TYPE, PolyvPlaybackListType.PLAYBACK);
PLVLiveChannelConfigFiller.setupVid(vid);
PLVLiveChannelConfigFiller.setupVideoListType(videoListType);
}
}
3.2 Initialize Live Room Data Manager
private void initLiveRoomManager() {
// 使用PLVLiveChannelConfigFiller配置好直播参数后,用其创建直播间数据管理器实例
liveRoomDataManager = new PLVLiveRoomDataManager(PLVLiveChannelConfigFiller.generateNewChannelConfig());
// 进行网络请求,获取上报观看热度
liveRoomDataManager.requestPageViewer();
// 进行网络请求,获取直播详情数据
liveRoomDataManager.requestChannelDetail();
}
3.3 Initialize Page UI
private void initView() {
// 页面上层ViewPage
viewPager = findViewById(R.id.watch_info_vp);
// 初始化共用的UI Fragment
initEmptyFragment();
initLiveDetailFragment();
initCommonHomeFragment();
// 添加Fragment到页面上层ViewPager中
PLVViewInitUtils.initViewPager(
getSupportFragmentManager(),
viewPager,
1,
liveDetailFragment,
commonHomeFragment,
emptyFragment
);
if(liveRoomDataManager.getConfig().isLive()){
// 初始化直播的播放器Layout
videoLayout = new PLVECLiveVideoLayout(this);
}else{
// 初始化回放的播放器Layout
videoLayout = new PLVECPlaybackVideoLayout(this);
}
}
Depending on different business needs, different Fragment combinations can be selected for initialization.
The various Fragment pages and their supported features are as follows:
- Live Home Page: PLVECLiveHomeFragment (Supports: host info, chat room, likes, products, tipping)
- Replay Home Page: PLVECPalybackHomeFragment (Supports: host info, playback controls, progress bar)
- Live Detail Page: PLVECLiveDetailFragment (Supports: announcements, live introduction)
Each functional module is also encapsulated as a Layout class, allowing different Layout components to be combined.
Features supported in live mode include: player, chat room, products, tipping, and interactive applications.
Features supported in replay mode include: player.
The layouts for each functional module are as follows:
- Player Layout: IPLVECVideoLayout
- Product Push Layout: PLVECCommodityPushLayout
- Interactive Application Layout: IPLVInteractLayout
- Tipping Popup Layout: PLVECRewardPopupView
3.4 Set Layout Callbacks
Since communication is required between various Fragments and the Activity (e.g., the live start and end states of the player affect the display of playback information in Fragments), each Fragment page provides external callbacks to facilitate communication.
For callback setup and data processing, please refer to the Data Monitoring - Monitor Business Data and Anonymous Inner Class - View Interaction Event Listener method blocks in the Activity.
