一稠诲、安裝bin目錄下的VideoWebPlugin.exe插件
二侦鹏、在vue項(xiàng)目的index.html文件中引入jsencrypt.min.js,web-control_1.2.5.min.js
三臀叙、頁(yè)面使用
創(chuàng)建容器
<div class="player_bg" id="playWnd" > </div>
創(chuàng)建實(shí)例略水,并配置相應(yīng)數(shù)據(jù)
// 創(chuàng)建插件
initPlugin () {
let that = this;
that.oWebControl = new WebControl({
szPluginContainer: "playWnd", // 指定容器id
iServicePortStart: 15900, // 指定起止端口號(hào),建議使用該值
iServicePortEnd: 15900,
szClassId:"23BF3B0A-2C56-4D97-9C03-0CB103AA8F11", // 用于IE10使用ActiveX的clsid
cbConnectSuccess: function () {
// 創(chuàng)建WebControl實(shí)例成功
that.oWebControl.JS_StartService("window", { // WebControl實(shí)例創(chuàng)建成功后需要啟動(dòng)服務(wù)
dllPath: "./VideoPluginConnect.dll" // 值"./VideoPluginConnect.dll"寫死
}).then(function () {
that.oWebControl.JS_SetWindowControlCallback({ // 設(shè)置消息回調(diào)
cbIntegrationCallBack: that.cbIntegrationCallBack
});// 啟動(dòng)插件服務(wù)成功
that.oWebControl.JS_CreateWnd("playWnd", that.boxWidth, that.boxHeight).then(function () { //JS_CreateWnd創(chuàng)建視頻播放窗口劝萤,寬高可設(shè)定渊涝,boxWidth, boxHeight容器
that.init(); // 創(chuàng)建播放實(shí)例成功后初始化
});
}, function () { // 啟動(dòng)插件服務(wù)失敗
});
},
cbConnectError: function () { // 創(chuàng)建WebControl實(shí)例失敗
that.oWebControl = null;
$("#playWnd").html("插件未啟動(dòng),正在嘗試啟動(dòng)床嫌,請(qǐng)稍候...");
WebControl.JS_WakeUp("VideoWebPlugin://"); // 程序未啟動(dòng)時(shí)執(zhí)行error函數(shù)跨释,采用wakeup來(lái)啟動(dòng)程序
that.initCount ++;
if (that.initCount < 3) {
setTimeout(function () {
that.initPlugin();
}, 3000)
} else {
$("#playWnd").html("插件啟動(dòng)失敗,請(qǐng)檢查插件是否安裝厌处!");
}
},
cbConnectClose: function (bNormalClose) {
// 異常斷開:bNormalClose = false
// JS_Disconnect正常斷開:bNormalClose = true
that.oWebControl = null;
$("#playWnd").html("插件未啟動(dòng)鳖谈,正在嘗試啟動(dòng),請(qǐng)稍候...");
WebControl.JS_WakeUp("VideoWebPlugin://");
that.initCount ++;
if (that.initCount < 3) {
setTimeout(function () {
that.initPlugin();
}, 3000)
} else {
$("#playWnd").html("插件啟動(dòng)失敗阔涉,請(qǐng)檢查插件是否安裝缆娃!");
}
}
});
},
// 消息回調(diào)
cbIntegrationCallBack(oData) {
let response = oData.responseMsg;
// response.type=1 選中窗口消息 type=2 播放消息
},
// 初始化
init(){
let that = this;
that.getPubKey(function () {
////////////////////////////////// 請(qǐng)自行修改以下變量值 ////////////////////////////////////
let appkey = "28631222"; //綜合安防管理平臺(tái)提供的appkey捷绒,必填
let secret = that.setEncrypt("vRfUmiilCd4EpLmtZKoT"); //綜合安防管理平臺(tái)提供的secret,必填
let ip = "112.48.8.98"; //綜合安防管理平臺(tái)IP地址龄恋,必填
let playMode = 0; //初始播放模式:0-預(yù)覽(實(shí)時(shí)流)疙驾,1-回放(視頻)
let port = 10443; //綜合安防管理平臺(tái)端口,若啟用HTTPS協(xié)議郭毕,默認(rèn)443
let snapDir = "D:\\SnapDir"; //抓圖存儲(chǔ)路徑
let videoDir = "D:\\VideoDir"; //緊急錄像或錄像剪輯存儲(chǔ)路徑
let layout = "4x1"; //playMode指定模式的布局
let enableHTTPS = 1; //是否啟用HTTPS協(xié)議與綜合安防管理平臺(tái)交互它碎,這里總是填1
let encryptedFields = 'secret'; //加密字段,默認(rèn)加密領(lǐng)域?yàn)閟ecret
let showToolbar = 1; //是否顯示工具欄显押,0-不顯示扳肛,非0-顯示
let showSmart = 1; //是否顯示智能信息(如配置移動(dòng)偵測(cè)后畫面上的線框),0-不顯示乘碑,非0-顯示
let buttonIDs = "0,16,256,257,258,259,260,513,514,515,516,517,768"; //自定義工具條按鈕
that.oWebControl.JS_RequestInterface({
funcName: "init",
argument: JSON.stringify({
appkey: appkey, //API網(wǎng)關(guān)提供的appkey
secret: secret, //API網(wǎng)關(guān)提供的secret
ip: ip, //API網(wǎng)關(guān)IP地址
playMode: playMode, //播放模式(決定顯示預(yù)覽還是回放界面)
port: port, //端口
snapDir: snapDir, //抓圖存儲(chǔ)路徑
videoDir: videoDir, //緊急錄像或錄像剪輯存儲(chǔ)路徑
layout: layout, //布局
enableHTTPS: enableHTTPS, //是否啟用HTTPS協(xié)議
encryptedFields: encryptedFields, //加密字段
showToolbar: showToolbar, //是否顯示工具欄
showSmart: showSmart, //是否顯示智能信息
buttonIDs: buttonIDs //自定義工具條按鈕
})
}).then(function (oData) {
that.oWebControl.JS_Resize(that.boxWidth, that.boxHeight); // 初始化后resize一次挖息,規(guī)避firefox下首次顯示窗口后插件窗口未與DIV窗口重合問(wèn)題
});
});
},
// 獲取公鑰
getPubKey(callback) {
this.oWebControl.JS_RequestInterface({
funcName: 'getRSAPubKey',
argument: JSON.stringify({
keyLength: 1024,
}),
}).then((oData) => {
if (oData.responseMsg.data) {
this.pubKey = oData.responseMsg.data
callback()
}
})
},
// RSA加密
setEncrypt (value) {
let that = this;
let encrypt = new JSEncrypt();
encrypt.setPublicKey(that.pubKey);
return encrypt.encrypt(value);
},
播放
// 監(jiān)控
that.oWebControl.JS_RequestInterface({
funcName: "startPreview",
argument: JSON.stringify({
cameraIndexCode:code, //監(jiān)控點(diǎn)編號(hào)
streamMode: 0, //主子碼流標(biāo)識(shí):0-主碼流,1-子碼流
transMode: 1, //傳輸協(xié)議:0-UDP兽肤,1-TCP
gpuMode: 0, //是否啟用GPU硬解套腹,0-不啟用,1-啟用
wndId:-1 //播放窗口序號(hào)(在2x2以上布局下可指定播放窗口)
})
}).then((oData) => {
if (oData.responseMsg.code===1){
console.log('success')
}
})
// 視頻回放
that.oWebControl.JS_RequestInterface({
funcName: "startPlayback",
argument: JSON.stringify({
cameraIndexCode: code, //監(jiān)控點(diǎn)編號(hào)
startTimeStamp: new Date(that.leftTime+' 00:00:00').getTime()/1000, //錄像查詢開始時(shí)間戳资铡,單位:秒
endTimeStamp: new Date(that.leftTime+' 23:59:59').getTime()/1000, //錄像結(jié)束開始時(shí)間戳电禀,單位:秒
recordLocation: 1, //錄像存儲(chǔ)類型:0-中心存儲(chǔ),1-設(shè)備存儲(chǔ)
transMode: 1, //傳輸協(xié)議:0-UDP笤休,1-TCP
gpuMode: 0, //是否啟用GPU硬解尖飞,0-不啟用,1-啟用
wndId:-1 // -1 或未指定-空閑窗口預(yù)覽(不管成功與失敗店雅,預(yù)覽后會(huì)自動(dòng)跳到下一個(gè)空閑窗口) 0-選中窗口預(yù)覽(預(yù)覽后不會(huì)自動(dòng)跳到下一個(gè)空閑窗口) 大于 0為由 wndId 指定的窗口上播放
})
}).then((oData) => {
console.log(oData)
})
頁(yè)面關(guān)閉時(shí)要記得銷毀插件政基,否則實(shí)時(shí)流一直播放
// 銷毀
destroyed() {
if (this.oWebControl) {
this.oWebControl.JS_HideWnd(); // 先讓窗口隱藏,規(guī)避插件窗口滯后于瀏覽器消失問(wèn)題
this.oWebControl.JS_Disconnect().then(function(){}, function() {});
}
}
注意要設(shè)置是自適應(yīng)闹啦,否則瀏覽器縮放沮明,播放器不會(huì)跟著縮放
$(window).resize(function() { // 窗口自適應(yīng)
if (that.oWebControl) {
that.oWebControl.JS_Resize($('#playWnd').width(), $('#playWnd').height());
}
});
運(yùn)行結(jié)果