1.1 获取直播活动信息接口.md
4.98 KB
/* Title: 1.1 获取直播活动信息接口 */
接口描述
接口地址
http://api.cnlive.com/open/api2/zbsc/getLiveActivityPlayInfo
接口协议
HTTP GET
接口请求参数
- sp_id:应用ID
- customID:活动ID(由开发者通过API创建接口或者在直播云管理端创建,保证唯一性)
- timestamp:时间戳,精确到秒
返回值
返回JSON格式的节目元数据信息,json示例如下:
{
"errorCode":"0",
"mp4_url_rate2":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"mp4_url_rate1":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"mp4_url_rate4":"",
"mp4_url_rate3":"",
"status":"1",
"hls_url_rate2":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"hls_url_rate1":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"hls_url_rate4":"",
"hls_url_rate3":"",
"msg":"请求成功",
"title":"测试活动",
"smallImg":"小图图片URL",
"bigImg":"大图图片URL"
}
多路流
{
"errorCode":"0",
"status":"1",
"msg":"请求成功",
"title":"测试活动",
"smallImg":"小图图片URL",
"bigImg":"大图图片URL",
"views" :[
"mp4_url_rate2":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"mp4_url_rate1":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"mp4_url_rate4":"",
"mp4_url_rate3":"",
"hls_url_rate2":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"hls_url_rate1":"http://api.cnlive.com/open/api3/play/IPS/liveplay?cid=xinyingshi&sp_id=iqhpk8pl19",
"hls_url_rate4":"",
"hls_url_rate3":"",
]
}
JSON属性说明: 四路播放地址至少一个有效
| 字段名称 | 描述 | 备注 |
| ret | 返回码 | 0:成功 |
| msg | 返回信息 | |
| status | 状态 | 0:未开始/1:直播中/2:直播结束、回放生成中/3:已结束 |
| mp4_url_rate1 | 播放地址,流畅 | 地址有防盗链,需要做播放签名 |
| mp4_url_rate2 | 播放地址,标清 | 地址有防盗链,需要做播放签名 |
| mp4_url_rate3 | 播放地址,高清 | 地址有防盗链,需要做播放签名 |
| mp4_url_rate4 | 播放地址,超清 | 地址有防盗链,需要做播放签名 |
| hls_url_rate1 | 播放地址,流畅 | 地址有防盗链,需要做播放签名 |
| hls_url_rate2 | 播放地址,标清 | 地址有防盗链,需要做播放签名 |
| hls_url_rate3 | 播放地址,高清 | 地址有防盗链,需要做播放签名 |
| hls_url_rate4 | 播放地址,超清 | 地址有防盗链,需要做播放签名 |
参数需进行加密,示例:
public String getPlayVideo(ModelMap model,HttpServletRequest request) {
String result = "";
Map params = new HashMap<>();
params.put("sp_id", "iqhpk8pl19");
params.put("customID", "d849bb4277be42799df3ffc21654d949");
params.put("timestamp", System.currentTimeMillis()/1000+"");
String url = OpenUtil.buildURL("http://api.cnlive.com/open/api2/zbsc/getLiveActivityPlayInfo", params, "672db30805f848f59ec3728f8347a4a0");
HttpURLConnection connection;
try {
URL requestUrl = new URL(url);
connection = (HttpURLConnection)requestUrl.openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();//连接
//获得返回值
if(connection.getResponseCode() == HttpURLConnection.HTTP_OK){
InputStream in = connection.getInputStream();
String currentLine = "";
if(in != null){
BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8"));
while((currentLine = br.readLine()) != null){
result += currentLine;
}
br.close();
}
}
}catch (Exception e) {
e.printStackTrace();
}
if(BaseUtil.notBlank(result)) {
JSONObject resultJson = JSONObject.parseObject(result);
model.put("videoInfo", resultJson);
}
return "play_demo";
}