165 lines
5.0 KiB
Plaintext
165 lines
5.0 KiB
Plaintext
|
|
let layer;
|
|||
|
|
let loadingMsg;
|
|||
|
|
let qxToken;
|
|||
|
|
let qxUrl;
|
|||
|
|
let item;
|
|||
|
|
|
|||
|
|
function setForm(data) {
|
|||
|
|
item = JSON.parse(data);
|
|||
|
|
layui.use('layer', function () {
|
|||
|
|
layer = layui.layer;
|
|||
|
|
//加载层-风格3
|
|||
|
|
loadingMsg = layer.msg('视频加载中,请稍候...', {icon: 16, scrollbar: false, time: 0, shade: [0.01, '#393D49']});
|
|||
|
|
});
|
|||
|
|
initVideo()
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
function initVideo() {
|
|||
|
|
getQXConnect();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 创建清新平台连接
|
|||
|
|
*/
|
|||
|
|
function getQXConnect() {
|
|||
|
|
let passWay = localStorage.getItem("passWay");
|
|||
|
|
if (passWay == null || passWay === '') {
|
|||
|
|
passWay = 'to-2';
|
|||
|
|
}
|
|||
|
|
let params = {
|
|||
|
|
"address": _cf.connParams.address,
|
|||
|
|
"port": _cf.connParams.port,
|
|||
|
|
"user": _cf.connParams.user,
|
|||
|
|
"password": _cf.connParams.password,
|
|||
|
|
"epid": _cf.connParams.epid,
|
|||
|
|
"fixaddr": _cf.connParams.bfix
|
|||
|
|
}
|
|||
|
|
if (passWay === 'to-2' || passWay === 'to-4') {
|
|||
|
|
posts(_cf.q2http_urlN, 'login', params, function (rv) {
|
|||
|
|
let result = {
|
|||
|
|
errcode: -1,
|
|||
|
|
token: ''
|
|||
|
|
}
|
|||
|
|
let respJSON = JSON.parse(rv.responseText);
|
|||
|
|
if (respJSON.hasOwnProperty('errcode')) {
|
|||
|
|
result.errcode = respJSON.errcode;
|
|||
|
|
}
|
|||
|
|
if (respJSON.hasOwnProperty('token')) {
|
|||
|
|
result.token = respJSON.token;
|
|||
|
|
result.errcode = 0;
|
|||
|
|
if (!isEmpty(result.token)) {
|
|||
|
|
qxUrl = _cf.q2http_urlN;
|
|||
|
|
qxToken = result.token;
|
|||
|
|
play(item);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
if (passWay === 'to-2' || passWay === 'to-3') {
|
|||
|
|
posts(_cf.q2http_url, 'login', params, function (rv) {
|
|||
|
|
let result = {
|
|||
|
|
errcode: -1,
|
|||
|
|
token: ''
|
|||
|
|
}
|
|||
|
|
let respJSON = JSON.parse(rv.responseText);
|
|||
|
|
if (respJSON.hasOwnProperty('errcode')) {
|
|||
|
|
result.errcode = respJSON.errcode;
|
|||
|
|
}
|
|||
|
|
if (respJSON.hasOwnProperty('token')) {
|
|||
|
|
result.token = respJSON.token;
|
|||
|
|
result.errcode = 0;
|
|||
|
|
if (!isEmpty(result.token)) {
|
|||
|
|
qxUrl = _cf.q2http_url;
|
|||
|
|
qxToken = result.token;
|
|||
|
|
play(item);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function play(item) {
|
|||
|
|
QXPlayVideo(item);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 时间字符串转时间戳
|
|||
|
|
* @param str
|
|||
|
|
*/
|
|||
|
|
function timeStrToTimestamp(str) {
|
|||
|
|
let date = new Date(str);
|
|||
|
|
return date.getTime();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 清新播放视频
|
|||
|
|
* @param item
|
|||
|
|
*/
|
|||
|
|
function QXPlayVideo(item) {
|
|||
|
|
//播视频接口
|
|||
|
|
let url;
|
|||
|
|
let durationSecond = timeStrToTimestamp(parseInt(item.end)) - timeStrToTimestamp(parseInt(item.begin))
|
|||
|
|
if (item.type === 'platform') {
|
|||
|
|
//平台
|
|||
|
|
url = qxUrl + "CSS/VODFile.flv?id=" + item.id + "&path=" + "" + item.path + item.name + "" + "&idx=0&puid=" + item.puid + "&durationSecond=" + durationSecond + "&resType=IV&start=0&stream=0&token=" + qxToken;
|
|||
|
|
} else {
|
|||
|
|
//前端
|
|||
|
|
url = qxUrl + "SG/VODFile.flv?path=" + "" + item.path + item.name + "" + "&idx=0&puid=" + item.puid + "&durationSecond=" + durationSecond + "&startTime=0&stream=0&token=" + qxToken;
|
|||
|
|
}
|
|||
|
|
console.log(url)
|
|||
|
|
if (flvjs.isSupported()) {
|
|||
|
|
let videoElement = document.getElementById('videoDemo');
|
|||
|
|
if (videoElement) {
|
|||
|
|
let flvPlayer = flvjs.createPlayer({
|
|||
|
|
type: 'flv', // => 媒体类型 flv 或 mp4,m3u8
|
|||
|
|
isLive: true, // => 是否为直播流
|
|||
|
|
hasAudio: false, // => 是否开启声音
|
|||
|
|
url: url, // => 视频流地址
|
|||
|
|
stashInitialSize: 128 // 减少首桢显示等待时长
|
|||
|
|
}, {
|
|||
|
|
enableWorker: false, //不启用分离线程
|
|||
|
|
enableStashBuffer: false, //关闭IO隐藏缓冲区
|
|||
|
|
reuseRedirectedURL: true, //重用301/302重定向url,用于随后的请求,如查找、重新连接等。
|
|||
|
|
autoCleanupSourceBuffer: true, //自动清除缓存
|
|||
|
|
fixAudioTimestampGap: false//false才会音视频同步
|
|||
|
|
});
|
|||
|
|
flvPlayer.attachMediaElement(videoElement);
|
|||
|
|
flvPlayer.load();
|
|||
|
|
flvPlayer.play();
|
|||
|
|
flvPlayer.on(flvjs.Events.ERROR, (errorType, errorDetail, errorInfo) => {
|
|||
|
|
if (flvPlayer) {
|
|||
|
|
layer.msg("视频播放失败", {icon: 2, time: 2000});
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
flvPlayer.on(flvjs.Events.SCRIPTDATA_ARRIVED, (errorType, errorDetail, errorInfo) => {
|
|||
|
|
if (flvPlayer) {
|
|||
|
|
layer.close(loadingMsg);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* post 请求
|
|||
|
|
* @param url
|
|||
|
|
* @param router
|
|||
|
|
* @param params
|
|||
|
|
* @param callback
|
|||
|
|
*/
|
|||
|
|
function posts(url, router, params, callback) {
|
|||
|
|
$.ajax({
|
|||
|
|
type: 'post',
|
|||
|
|
url: url + router,
|
|||
|
|
data: params,
|
|||
|
|
traditional: true,
|
|||
|
|
dataType: 'json',
|
|||
|
|
complete: function (rv) {
|
|||
|
|
if (typeof callback == 'function') callback(rv)
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|