本文共 2945 字,大约阅读时间需要 9 分钟。
阿里云播放器直接在线点播视频以及直播技术,此处记录直播实现过程
http://video-center.alivecdn.com
/appName/
vhost
用于接收拉流地址,即申请阿里云直播时准备的直播域名Constants.ALI_LIVE_PRIVATE_KEY
可在阿里云后端的直播鉴权处获取// 获取推流地址public String getPushUri(String roomName, Long endTime) { return getRoomName(roomName) + "vhost=" + Constants.ALI_LIVE_PULL_URL + "&" + generateAuthKey(roomName, endTime);}// 房间号private String getRoomName(String roomName) { return roomName + "?";}// 完整验签串private String generateAuthKey(String roomName, Long endTime) { return "auth_key=" + endTime + generateUuid() + generateEncryptStr(roomName, endTime);}// 唯一标识private String generateUuid() { String uuid = "0"; String uid = "0"; return "-" + uuid + "-" + uid + "-";}// 验签密钥private String generateEncryptStr(String roomName, Long endTime) { String uri = Constants.ALI_LIVE_APP_NAME + roomName; return md5(uri + "-" + endTime + generateUuid() + Constants.ALI_LIVE_PRIVATE_KEY);}
.m3u8
用于表示接受的直播视频类型,阿里云官方还提供其他几种类型,可在文档中查看vhost
告知阿里云直播域名,但拉流时不需要isLive: true
表名是直播操作vid
获取 playAuth
的方式,这不适用于直播source: url
即可public String getPullUrl(String roomName, Long endTime) { roomName += ".m3u8"; return "http://" + Constants.ALI_LIVE_PULL_URL + generateUri(roomName) + generateAuthKey(roomName, endTime);}// 获取请求参数private String generateUri(String roomName) { return Constants.ALI_LIVE_APP_NAME + getRoomName(roomName);}// 房间号private String getRoomName(String roomName) { return roomName + "?";}// 完整验签串private String generateAuthKey(String roomName, Long endTime) { return "auth_key=" + endTime + generateUuid() + generateEncryptStr(roomName, endTime);}// 唯一标识private String generateUuid() { String uuid = "0"; String uid = "0"; return "-" + uuid + "-" + uid + "-";}// 验签密钥private String generateEncryptStr(String roomName, Long endTime) { String uri = Constants.ALI_LIVE_APP_NAME + roomName; return md5(uri + "-" + endTime + generateUuid() + Constants.ALI_LIVE_PRIVATE_KEY);}