目标
本文档将一步一步带领在10分钟内快速完成一场直播的完整业务流程,本文档适合快速搭建一个直播间,设置相关信息后,完成直播,查看直播详细观看数据优化直播流程的业务场景。
注意:每创建一个频道,会默认创建4个助教子频道,子频道用于协助主讲老师教学或者和用户互动,当然也可以创建自己的子频道,例如客服、班主任、嘉宾等,具体见下面带子频道直播教学场景和带子频道纯视频场景
直播教学场景
此场景适合于通用的线上教学场景,相当于一个虚拟的教室,包括频道创建、频道初始化、暖场图片/视频、引导图片、讲师信息、直播文档上传等设置,相关代码可以参考下面代码,直接拷贝后修改成为适合自己的课程信息就可以。
注意:每一个频道会默认创建4个子频道,通过示例代码的返回对象可以获取到所有的子频道信息
效果展示
讲师端效果:
助教端:
助教可以对聊天室严禁词、禁言人员、踢人等进行管理;
嘉宾端:
嘉宾默认以连麦的方式进入直播间,和讲师互动;
观看端效果:
体验链接:https://live.polyv.cn/watch/2094038
流程
以下示例代码会根据设置的参数,自动选择调用哪些接口,默认会调用创建频道、频道初始化设置等接口,如果不需要相关功能,去除相关代码即可,例如:不需要创建子频道功能,去除示例代码中的liveCreateSonChannelListRequest.setSonChannels(sonChannels);即可。注:如果同时设置了暖场视频和暖场图片,暖场视频会覆盖暖场图片;
Copy graph LR
style A fill:#00ae9d,stroke:#323232,stroke-width:1px
style B fill:#f29952,stroke:#323232,stroke-width:1px
style C fill:#608913,stroke:#323232,stroke-width:1px
style D fill:#2ca9e0,stroke:#323232,stroke-width:1px
style E fill:#fbdd2d,stroke:#323232,stroke-width:1px
style F fill:#90d6ab,stroke:#323232,stroke-width:1px
style G fill:#2ca9e0,stroke:#323232,stroke-width:1px
style H fill:#e7372a,stroke:#323232,stroke-width:1px
style I fill:#40c1dd,stroke:#323232,stroke-width:1px
style J fill:#bf83ff,stroke:#323232,stroke-width:1px
A[创建频道] --> B[频道初始化设置]
B --> C[暖场图片设置]
B --> D[暖场视频设置]
B --> E[设置讲师信息]
B --> J[创建子频道]
B --> F[设置课件]
subgraph "频道设置(可多选)"
C
D
E
F
J
end
C --> G[封装频道返回]
D --> G
E --> G
J --> G
F --> G
G --> H[开始直播]
H --> I["结束直播,获取观看数据"]
代码示例
Copy /**
* 快速创建带子频道的三分屏频道,适用于直播教学场景
* @throws IOException IO异常
* @throws NoSuchAlgorithmException 系统异常
*/
// @Test
public void testQuickCreatePPTAndSonChannel() throws IOException, NoSuchAlgorithmException {
//初始化系统,请配置自己的账号信息,正式使用时请全局统一设置
String userId = "xxx";
String appId = "xxx";
String appSecret = "xxx";
LiveGlobalConfig.init(appId, userId, appSecret);
log.debug("--初始化完成--");
QuickCreatePPTChannelRequest quickCreatePPTChannelRequest = new QuickCreatePPTChannelRequest();
QuickCreateChannelResponse quickCreateChannelResponse;
String path = LiveChannelQuickCreatorTest.class.getResource("/file/PPT.pptx").getPath();
Calendar instance = Calendar.getInstance();
instance.set(Calendar.DAY_OF_MONTH, instance.get(Calendar.DAY_OF_MONTH) + 1);
//创建频道
//频道相关基础设置-频道名
quickCreatePPTChannelRequest.setName("带子频道的直播教学场景")
//频道相关基础设置-频道密码
.setChannelPasswd(getRandomString(6))
//频道相关基础设置-连麦人数
.setLinkMicLimit(5)
//频道相关基础设置-主持人名称
.setPublisher("thomas教授")
//频道相关基础设置-是否无延迟
.setPureRtcEnabled(LiveConstant.Flag.YES.getFlag())
//频道相关基础设置-开播时间
.setStartTime(instance.getTime().getTime())
//==========================================
//频道初始化设置-频道图标地址
.setCoverImg("https://wwwimg.polyv.net/assets/dist/images/v2020/page-home/brand-advantage/row-2-3.svg")
//频道初始化设置-引导图地址
.setSplashImg(
"https://wwwimg.polyv.net/assets/dist/images/v2020/news-info-md/product-dynamic-bg_v3.jpg")
//频道初始化设置-频道描述
.setDesc("POLYV保利威是易方信息科技股份有限公司旗下拥有自主知识产权的视频云计算服务平台,其中包含 云点播 、云直播 " +
"和其它视频服务,提供API、SDK技术支持,并拥有国家专利级别的PlaySafe®视频版权保护技术及三套CDN加速,致力为用户提供稳定、安全、快速的企业级视频云服务。")
//频道初始化设置-设置暖场图
.setCoverImage("https://s1.videocc.net/live-watch/assets/img/default-splash-img.07657078.jpg")
//频道初始化设置-点击暖场图跳转的地址
.setCoverHref("http://www.baidu.com")
//频道初始化设置-设置暖场视频
// .setWarmUpFlv("http://www.w3school.com.cn/example/html5/mov_bbb.mp4")
//==========================================
//聊天室讲师信息-昵称
.setNickname("thomas-gogo")
//聊天室讲师信息-讲师头衔
.setActor("刘老师")
//聊天室讲师信息-讲师头像
.setAvatar(
"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2069606413,3553249962&fm=26&gp=0" +
".jpg")
//==========================================
// 讲课文档设置-讲课文档,当前支持DOC、PPT、PDF
.setFile(new File(path))
//讲课PPT设置-转换类型(‘common’:转普通图片, ‘animate’:转动画效果)
.setType("common")
//讲课PPT设置-文档名称
.setDocName("直播教学课件");
// //讲课PPT设置-文档转换完成后的回调地址,不需要不传
// .setCallbackUrl("http://www.baidu.com/callback")
LiveCreateSonChannelListRequest liveCreateSonChannelListRequest = new LiveCreateSonChannelListRequest();
List<LiveCreateSonChannelListRequest.SonChannel> sonChannels = new ArrayList<LiveCreateSonChannelListRequest.SonChannel>();
sonChannels.add(setSonChannelsInfo1());
sonChannels.add(setSonChannelsInfo2());
liveCreateSonChannelListRequest.setSonChannels(sonChannels);
quickCreateChannelResponse = new LiveChannelQuickCreatorServiceImpl().quickCreatePPTSence(quickCreatePPTChannelRequest,
liveCreateSonChannelListRequest);
Assert.assertNotNull(quickCreateChannelResponse);
log.debug("快速创建三分屏频道成功,{}", JSON.toJSONString(quickCreateChannelResponse));
log.debug("网页开播地址:https://live.polyv.net/web-start/login?channelId={} , 登录密码: {}",
quickCreateChannelResponse.getLiveChannelBasicInfoResponse().getChannelId(),
quickCreatePPTChannelRequest.getChannelPasswd());
log.debug("网页观看地址:https://live.polyv.cn/watch/{} ",
quickCreateChannelResponse.getLiveChannelBasicInfoResponse().getChannelId());
log.debug("嘉宾进入直播间地址:http://live.polyv.net/web-start/guest?channelId={} ,登录密码: {} ",
quickCreateChannelResponse.getSonChannelInfos().get(0).getAccount(),
sonChannels.get(0).getPasswd());
log.debug("助教进入直播间地址:https://live.polyv.net/teacher.html , 登录频道: {}, 登录密码: {}",
quickCreateChannelResponse.getSonChannelInfos().get(1).getAccount(),
sonChannels.get(1).getPasswd());
/**
* todo : B端客户的业务逻辑,将quickCreateChannelResponse的相关信息保持到自己的DB中组织业务逻辑
*/
/**
* todo : 采用网页开播或者客户端开播,直播结束后 ,可以拉取用户观看直播的观看数据,对观看效果做进一步的分析,改进直播流程和细节
*/
//打印观看日志
printViewLog(quickCreateChannelResponse.getLiveChannelBasicInfoResponse().getChannelId());
}
/**
* 设置子频道信息-嘉宾
* @return 子频道列表
*/
private LiveCreateSonChannelListRequest.SonChannel setSonChannelsInfo1() {
LiveCreateSonChannelListRequest.SonChannel sonChannel1 = new LiveCreateSonChannelListRequest.SonChannel();
//设置子频道信息,子频道代表助教、嘉宾信息
sonChannel1
//子频道角色-默认不传为助教,传Guest为嘉宾
.setRole("Guest")
//子频道昵称
.setNickname("嘉宾-陈先生")
//子频道登录密码
.setPasswd(getRandomString(10))
//子频道头衔
.setActor("教授")
//子频道头像
.setAvatar(
"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2480846186,1530344&fm=15&gp=0.jpg");
return sonChannel1;
}
/**
* 设置子频道信息-助教
* @return 子频道列表
*/
private LiveCreateSonChannelListRequest.SonChannel setSonChannelsInfo2() {
LiveCreateSonChannelListRequest.SonChannel sonChannel2 = new LiveCreateSonChannelListRequest.SonChannel();
sonChannel2.setRole(null)
.setNickname("助教-王小姐")
.setPasswd(getRandomString(10))
.setActor("王老师")
.setAvatar("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=356414612,1103487565&fm=15&gp=0" +
".jpg");
return sonChannel2;
}
/**
* 打印频道观看日志
* @param channelId
* @throws IOException
* @throws NoSuchAlgorithmException
*/
private void printViewLog(String channelId) throws IOException, NoSuchAlgorithmException {
LiveListChannelViewlogRequest liveListChannelViewlogRequest = new LiveListChannelViewlogRequest();
LiveListChannelViewlogResponse liveListChannelViewlogResponse;
Calendar instance = Calendar.getInstance();
instance.set(Calendar.DAY_OF_MONTH, instance.get(Calendar.DAY_OF_MONTH) + 2);
//依据频道号和起止时间查询观看日志
liveListChannelViewlogRequest.setChannelId(channelId)
.setStartTime(new Date())
.setEndTime(instance.getTime());
liveListChannelViewlogResponse = new LiveChannelViewdataServiceImpl().listChannelViewlog(
liveListChannelViewlogRequest);
Assert.assertNotNull(liveListChannelViewlogResponse);
if (liveListChannelViewlogResponse != null) {
//to do something ......
log.debug("测试分页查询频道观看日志成功,{}", JSON.toJSONString(liveListChannelViewlogResponse));
}
}
请求描述
自定义频道名称,一般是课程主题、会议主题、培训主题等,例如 财务制度培训、乌镇峰会
自定义频道密码,B端讲师通过该密码进入直播间开播,长度不能超过16位,必须同时包含字母和数字
连麦人数,-1=<取值范围<=账号级的连麦人数,-1:表示使用账号默认的连麦人数,最大16人(注:账号级连麦人数需通知平台管理员设置才生效)
直播开始时间,13位时间戳,设置为0 表示关闭直播开始时间显示
暖场图片地址,图片大小建议:800x450,支持PNG、JPEG、GIF格式
暖场视频地址(http地址),移动端不支持FLV视频文件,建议使用MP4视频文件
上传的文件不超过50M,格式限制为(ppt, pdf,pptx,doc,docx,wps, xls,xlsx)
转换类型(‘common’:转普通图片, ‘animate’:转动画效果)默认不传转普通,因为只有ppt,pptx可以转动画,其他类型文件会自动转成普通;文件转动画转失败会直接把类型转为普通
文档名称(不传默认使用ppt上传的文件获取到的文件名作为文档名称,文档名称不得超过100个字符)
返回描述
liveChannelBasicInfoResponse
LiveChannelBasicInfoResponse
LiveChannelBasicInfoResponse参数描述
频道的观看页状态,取值为:live(直播中)、end(直播结束)、playback(回放中)、waiting(等待直播)
LiveSonChannelInfoResponse参数描述
POLYV用户ID,和保利威官网一致,获取路径:官网->登录->直播(开发设置)
UserCategory参数描述
POLYV用户ID,和保利威官网一致,获取路径:官网->登录->直播(开发设置)
AuthSetting参数描述
POLYV用户ID,和保利威官网一致,获取路径:官网->登录->直播(开发设置)
用于实现一个频道设置两个观看条件,为1或2(1为主要条件,2为次要条件)
观看条件类型(1. 无限制 none 2. 验证码观看 code 3. 付费观看 pay 4. 白名单观看 phone 5. 登记观看 info 6. 分享观看 wxshare 7. 自定义授权观看 custom 8. 外部授权观看 external)
付费观看,截止时间,为null表示:一次付费,永久有效
普通视频场景
此场景适合非教学情况下的其他场景,比如直播带货、会议直播、年会直播的场景,和直播教学场景的区别是主播端和观看端的页面排版不同,直播教学场景以三分屏的方式将讲师头像、课件、白板、聊天室集成到一个页面呈现给终端用户,而普通视频场景同时只能呈现讲师摄像头、文档、电脑屏幕的一种,一般情况直接展现讲师摄像头采集的画面。
注意:每一个频道会默认创建4个子频道,通过示例代码的返回对象可以获取到所有的子频道信息
效果展示
讲师端效果(呈现文档给终端用户):
讲师端效果(呈现讲师摄像头采集信息给终端用户):
观看端效果:
助教端:
助教可以对聊天室严禁词、禁言人员、踢人等进行管理;
流程
如下流程除了 频道创建 和 频道初始化 必须执行,其他都是可选,暖场图片/视频 、讲师信息 、 直播PPT上传,不设相关参数,这些接口将不会被调用,暖场视频和暖场图片只有一个有效,如果同时设置了暖场视频和暖场图片,暖场视频会覆盖暖场图片;
Copy graph LR
style A fill:#00ae9d,stroke:#323232,stroke-width:1px
style B fill:#f29952,stroke:#323232,stroke-width:1px
style C fill:#608913,stroke:#323232,stroke-width:1px
style D fill:#2ca9e0,stroke:#323232,stroke-width:1px
style E fill:#fbdd2d,stroke:#323232,stroke-width:1px
style F fill:#90d6ab,stroke:#323232,stroke-width:1px
style G fill:#2ca9e0,stroke:#323232,stroke-width:1px
style H fill:#e7372a,stroke:#323232,stroke-width:1px
style I fill:#40c1dd,stroke:#323232,stroke-width:1px
style J fill:#bf83ff,stroke:#323232,stroke-width:1px
A[创建频道] --> B[频道初始化设置]
B --> C[暖场图片设置]
B --> D[暖场视频设置]
B --> E[设置讲师信息]
B --> J[创建子频道]
B --> F[设置课件]
subgraph "频道设置(可多选)"
C
D
E
F
J
end
C --> G[封装频道返回]
D --> G
E --> G
J --> G
F --> G
G --> H[开始直播]
H --> I["结束直播,获取观看数据"]
代码示例
Copy /**
* 快速创建纯视频频道,适合直播带货、会议、年会、活动拍摄、大会直播等直播业务场景
* 约束:2、同时设置暖场图片和暖场视频只生效暖场视频。
* @throws IOException IO异常
* @throws NoSuchAlgorithmException 系统异常
*/
// @Test
public void testQuickCreateVideoAndSonChannel() throws IOException, NoSuchAlgorithmException {
//初始化系统,请配置自己的账号信息,正式使用时请全局统一设置
String userId = "xxx";
String appId = "xxx";
String appSecret = "xxx";
LiveGlobalConfig.init(appId, userId, appSecret);
log.debug("--初始化完成--");
QuickCreateVideoChannelRequest quickCreateVideoChannelRequest = new QuickCreateVideoChannelRequest();
QuickCreateChannelResponse quickCreateChannelResponse;
Calendar instance = Calendar.getInstance();
instance.set(Calendar.DAY_OF_MONTH, instance.get(Calendar.DAY_OF_MONTH) + 1);
//创建频道
//频道相关基础设置-频道名
quickCreateVideoChannelRequest.setName("带子频道的纯视频直播场景")
//频道相关基础设置-频道密码
.setChannelPasswd(getRandomString(6))
//频道相关基础设置-连麦人数
.setLinkMicLimit(5)
//频道相关基础设置-观看页显示的主讲人描述
.setPublisher("thomas教授")
//频道相关基础设置-是否无延迟
.setPureRtcEnabled(LiveConstant.Flag.YES.getFlag())
//频道相关基础设置-开播时间
.setStartTime(instance.getTime().getTime())
//==========================================
//频道初始化设置-频道图标地址
.setCoverImg("https://wwwimg.polyv.net/assets/dist/images/v2020/page-home/brand-advantage/row-2-3.svg")
//频道初始化设置-引导图地址
.setSplashImg(
"https://wwwimg.polyv.net/assets/dist/images/v2020/news-info-md/product-dynamic-bg_v3.jpg")
//频道初始化设置-频道描述
.setDesc("POLYV保利威是易方信息科技股份有限公司旗下拥有自主知识产权的视频云计算服务平台,其中包含 云点播 、云直播 " +
"和其它视频服务,提供API、SDK技术支持,并拥有国家专利级别的PlaySafe®视频版权保护技术及三套CDN加速,致力为用户提供稳定、安全、快速的企业级视频云服务。")
//频道初始化设置-设置暖场图
.setCoverImage("https://s1.videocc.net/live-watch/assets/img/default-splash-img.07657078.jpg")
//频道初始化设置-点击暖场图跳转的地址
.setCoverHref("http://www.baidu.com")
//频道初始化设置-设置暖场视频
// .setWarmUpFlv("http://www.w3school.com.cn/example/html5/mov_bbb.mp4")
//==========================================
//聊天室讲师信息-昵称
.setNickname("thomas-gogo")
//聊天室讲师信息-讲师头衔
.setActor("刘老师")
//聊天室讲师信息-讲师头像
.setAvatar(
"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2069606413,3553249962&fm=26&gp=0" +
".jpg");
LiveCreateSonChannelListRequest liveCreateSonChannelListRequest = new LiveCreateSonChannelListRequest();
List<LiveCreateSonChannelListRequest.SonChannel> sonChannels = new ArrayList<>();
//纯视频场景只能创建助教,不允许创建嘉宾
sonChannels.add(setSonChannelsInfo2());
liveCreateSonChannelListRequest.setSonChannels(sonChannels);
//请求服务器,创建带子频道的纯视频频道
quickCreateChannelResponse = new LiveChannelQuickCreatorServiceImpl().quickCreateVideoSence(quickCreateVideoChannelRequest,
liveCreateSonChannelListRequest);
Assert.assertNotNull(quickCreateChannelResponse);
log.debug("快速创建纯视频直播频道成功,{}", JSON.toJSONString(quickCreateChannelResponse));
//无延迟纯视频模式只支持客户端开播
if (LiveConstant.Flag.YES.getFlag().equals(quickCreateVideoChannelRequest.getPureRtcEnabled())) {
log.debug("客户端开播地址:https://live.polyv.net/start-client.html?channelId={} , 登录密码: {}",
quickCreateChannelResponse.getLiveChannelBasicInfoResponse().getChannelId(),
quickCreateVideoChannelRequest.getChannelPasswd());
} else {
log.debug("网页开播地址:https://live.polyv.net/web-start/login?channelId={} , 登录密码: {}",
quickCreateChannelResponse.getLiveChannelBasicInfoResponse().getChannelId(),
quickCreateVideoChannelRequest.getChannelPasswd());
}
log.debug("网页观看地址:https://live.polyv.cn/watch/{} ",
quickCreateChannelResponse.getLiveChannelBasicInfoResponse().getChannelId());
//无延迟纯视频模式只支持客户端助教视频连麦
if (LiveConstant.Flag.YES.getFlag().equals(quickCreateVideoChannelRequest.getPureRtcEnabled())) {
log.debug("助教客户端进入直播间地址:https://live.polyv.net/teacher.html , 登录频道: {}, 登录密码: {}",
quickCreateChannelResponse.getSonChannelInfos().get(0).getAccount(),
sonChannels.get(0).getPasswd());
} else {
log.debug("助教进入直播间地址:https://live.polyv.net/teacher.html , 登录频道: {}, 登录密码: {}",
quickCreateChannelResponse.getSonChannelInfos().get(0).getAccount(),
sonChannels.get(0).getPasswd());
}
/**
* todo : B端客户的业务逻辑,将quickCreateChannelResponse的相关信息保持到自己的DB中组织业务逻辑
*/
/**
* todo : 采用网页开播或者客户端开播,直播结束后 ,可以拉取用户观看直播的观看数据,对观看效果做进一步的分析,改进直播流程和细节
*/
//打印观看日志
printViewLog(quickCreateChannelResponse.getLiveChannelBasicInfoResponse().getChannelId());
}
/**
* 设置子频道信息-助教
* @return 子频道列表
*/
private LiveCreateSonChannelListRequest.SonChannel setSonChannelsInfo2() {
LiveCreateSonChannelListRequest.SonChannel sonChannel2 = new LiveCreateSonChannelListRequest.SonChannel();
sonChannel2.setRole(null)
.setNickname("助教-王小姐")
.setPasswd(getRandomString(10))
.setActor("王老师")
.setAvatar("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=356414612,1103487565&fm=15&gp=0" +
".jpg");
return sonChannel2;
}
/**
* 打印频道观看日志
* @param channelId
* @throws IOException
* @throws NoSuchAlgorithmException
*/
private void printViewLog(String channelId) throws IOException, NoSuchAlgorithmException {
LiveListChannelViewlogRequest liveListChannelViewlogRequest = new LiveListChannelViewlogRequest();
LiveListChannelViewlogResponse liveListChannelViewlogResponse;
Calendar instance = Calendar.getInstance();
instance.set(Calendar.DAY_OF_MONTH, instance.get(Calendar.DAY_OF_MONTH) + 2);
//依据频道号和起止时间查询观看日志
liveListChannelViewlogRequest.setChannelId(channelId)
.setStartTime(new Date())
.setEndTime(instance.getTime());
liveListChannelViewlogResponse = new LiveChannelViewdataServiceImpl().listChannelViewlog(
liveListChannelViewlogRequest);
Assert.assertNotNull(liveListChannelViewlogResponse);
if (liveListChannelViewlogResponse != null) {
//to do something ......
log.debug("测试分页查询频道观看日志成功,{}", JSON.toJSONString(liveListChannelViewlogResponse));
}
}
请求描述
自定义频道名称,一般是课程主题、会议主题、培训主题等,例如 财务制度培训、乌镇峰会
自定义频道密码,B端讲师通过该密码进入直播间开播,长度不能超过16位,必须同时包含字母和数字
连麦人数,-1=<取值范围<=账号级的连麦人数,-1:表示使用账号默认的连麦人数,最大16人(注:账号级连麦人数需通知平台管理员设置才生效)
直播开始时间,13位时间戳,设置为0 表示关闭直播开始时间显示
暖场图片地址,图片大小建议:800x450,支持PNG、JPEG、GIF格式
暖场视频地址(http地址),移动端不支持FLV视频文件,建议使用MP4视频文件
返回描述
liveChannelBasicInfoResponse
LiveChannelBasicInfoResponse
LiveChannelBasicInfoResponse参数描述
频道的观看页状态,取值为:live(直播中)、end(直播结束)、playback(回放中)、waiting(等待直播)
LiveSonChannelInfoResponse参数描述
POLYV用户ID,和保利威官网一致,获取路径:官网->登录->直播(开发设置)
UserCategory参数描述
POLYV用户ID,和保利威官网一致,获取路径:官网->登录->直播(开发设置)
AuthSetting参数描述
POLYV用户ID,和保利威官网一致,获取路径:官网->登录->直播(开发设置)
用于实现一个频道设置两个观看条件,为1或2(1为主要条件,2为次要条件)
观看条件类型(1. 无限制 none 2. 验证码观看 code 3. 付费观看 pay 4. 白名单观看 phone 5. 登记观看 info 6. 分享观看 wxshare 7. 自定义授权观看 custom 8. 外部授权观看 external)
付费观看,截止时间,为null表示:一次付费,永久有效