WEB/public/hikvision/player.html
2026-07-18 18:23:45 +08:00

181 lines
5.5 KiB
HTML

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Expires" content="0" />
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #000;
}
#divPlugin {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="divPlugin"></div>
</body>
<script src="./jquery-1.7.1.min.js"></script>
<script src="./webVideoCtrl.js"></script>
<script src="./encryption/AES.js"></script>
<script src="./encryption/cryptico.min.js"></script>
<script src="./encryption/crypto-3.1.2.min.js"></script>
<script>
(function () {
var g_iWndIndex = 0;
var g_szDeviceIdentify = '';
var g_bInited = false;
// 初始化插件
function initPlugin() {
if (g_bInited) return;
WebVideoCtrl.I_InitPlugin('100%', '100%', {
bWndFull: true,
iWndowType: 1,
bNoPlugin: true,
cbSelWnd: function (xmlDoc) {
g_iWndIndex = parseInt($(xmlDoc).find('SelectWnd').eq(0).text(), 10);
},
cbInitPluginComplete: function () {
WebVideoCtrl.I_InsertOBJECTPlugin('divPlugin');
g_bInited = true;
postMessage({ type: 'ready' });
},
cbEvent: function (iEventType, iParam1, iParam2) {
if (2 === iEventType) {
postMessage({ type: 'playbackEnd', wndIndex: iParam1 });
} else if (-1 === iEventType) {
postMessage({ type: 'networkError', device: iParam1 });
}
},
cbPluginErrorHandler: function (iWndIndex, iErrorCode, oError) {
var errMap = {
1001:'码流传输异常',1002:'回放结束',1003:'取流失败',
1004:'对讲断开',1005:'广播断开',1006:'编码格式不支持',
1007:'WebSocket断开',1008:'首帧超时',1015:'获取播放URL失败',
1017:'密码错误'
};
postMessage({ type: 'error', wndIndex: iWndIndex, code: iErrorCode, msg: errMap[iErrorCode] || ('错误码:'+iErrorCode) });
}
});
}
// 登录设备
function doLogin(data) {
var szIP = data.ip;
var szPort = String(data.port || 80);
var szUsername = data.user || 'admin';
var szPassword = data.pass || '';
var iProtocol = location.protocol === 'https:' ? 2 : 1;
g_szDeviceIdentify = szIP + '_' + szPort;
WebVideoCtrl.I_Login(szIP, iProtocol, szPort, szUsername, szPassword, {
success: function () {
postMessage({ type: 'loginSuccess', device: g_szDeviceIdentify });
},
error: function (status, xmlDoc) {
postMessage({ type: 'loginError', status: status, device: g_szDeviceIdentify });
}
});
}
// 开始预览
function doStartRealPlay(data) {
if (!g_szDeviceIdentify) {
postMessage({ type: 'error', msg: '请先登录设备' });
return;
}
var iChannelID = parseInt(data.channel, 10) || 1;
var iStreamType = parseInt(data.streamType, 10) || 0;
WebVideoCtrl.I_StartRealPlay(g_szDeviceIdentify, {
iStreamType: iStreamType,
iChannelID: iChannelID,
bZeroChannel: false,
success: function () {
postMessage({ type: 'playSuccess', device: g_szDeviceIdentify, channel: iChannelID });
},
error: function (status, xmlDoc) {
postMessage({ type: 'playError', status: status });
}
});
}
// 停止预览
function doStop() {
WebVideoCtrl.I_Stop({
success: function () {
postMessage({ type: 'stopSuccess' });
},
error: function () {
postMessage({ type: 'stopError' });
}
});
}
// 退出登录
function doLogout() {
if (!g_szDeviceIdentify) return;
WebVideoCtrl.I_Logout(g_szDeviceIdentify);
g_szDeviceIdentify = '';
postMessage({ type: 'logoutSuccess' });
}
// 向父窗口发送消息
function postMessage(data) {
if (window.parent && window.parent !== window) {
window.parent.postMessage(JSON.stringify(data), '*');
}
}
// 监听父窗口消息
window.addEventListener('message', function (e) {
var data;
try {
data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;
} catch (err) {
return;
}
switch (data.type) {
case 'init':
initPlugin();
break;
case 'login':
doLogin(data);
break;
case 'startRealPlay':
doStartRealPlay(data);
break;
case 'stop':
doStop();
break;
case 'logout':
doLogout();
break;
}
});
// 页面加载后自动初始化
$(function () {
initPlugin();
});
// 页面卸载时清理
$(window).on('beforeunload', function () {
doStop();
doLogout();
});
})();
</script>
</html>