基于海康威视SDK javaB/S
下载NetVideoActiveX23.cab文件,放在webRoot下面的codebase文件夹里
//全局变量定义
var m_iNowChanNo = -1; //当前通道号
var m_iLoginUserId = -1; //注册设备用户ID
var m_iChannelNum = -1; //模拟通道总数
var m_bDVRControl = null; //OCX控件对象
var m_iProtocolType = 0; //协议类型,0 – TCP, 1 - UDP
var m_iStreamType = 0; //码流类型,0 表示主码流, 1 表示子码流
var m_iPlay = 0; //当前是否正在预览
var m_iRecord = 0; //当前是否正在录像
var m_iTalk = 0; //当前是否正在对讲
var m_iVoice = 0; //当前是否打开声音
var m_iAutoPTZ = 0; //当前云台是否正在自转
var m_iPTZSpeed = 4; //云台速度
/*************************************************
Function: LogMessage
Description: 写执行结果日志
Input: msg:日志
Output: 无
Return: 无
*************************************************/
function LogMessage(msg) {
//var myDate = new Date();
//var szNowTime = myDate.toLocaleString( ); //获取日期与时间
document.getElementById("OperatLogBody").innerHTML = "--> " + msg;
}
/*************************************************
Function: onload
Description: 页面加载完后判断系统日期是否在1971-2037范围
Input: 无
Output: 无
Return: 无
*************************************************/
window.onload = function () {
function getIP() {
var obj = bzmis.vidio_index2.getIP();
return obj.value;
}
function getPort() {
var obj = bzmis.vidio_index2.getPort();
return obj.value;
}
function getUserName() {
var obj = bzmis.vidio_index2.getUserName();
return obj.value;
}
function getPassword() {
var obj = bzmis.vidio_index2.getPassword();
return obj.value;
}
function getChannelNo() {
var obj = bzmis.vidio_index2.getChannelNo();
return obj.value;
}
var myDate = new Date();
var iYear = myDate.getFullYear();
if (iYear < 1971 || iYear > 2037) {
alert("为了正常使用本软件,请将系统日期年限设置在1971-2037范围内!");
//parent.location.href = "../login.php";
}
if (document.getElementById("HIKOBJECT1").object == null) {
alert("请先下载控件并注册!");
m_bDVRControl = null;
}
else {
m_bDVRControl = document.getElementById("HIKOBJECT1");
ChangeStatus(1);
// ArrangeWindow(1);
}
var szDevIp = '192.168.32.31';
var szDevPort = '8000';
var szDevUser = 'admin';
var szDevPwd = '12345';
m_iLoginUserId = m_bDVRControl.Login(szDevIp, szDevPort, szDevUser, szDevPwd);
if (m_iLoginUserId == -1) {
LogMessage("注册失败!");
}
else {
LogMessage("注册成功!");
}
m_iNowChanNo = 3;
if (m_iNowChanNo > -1) {
if (m_iPlay == 1) {
m_bDVRControl.StopRealPlay();
}
var bRet = m_bDVRControl.StartRealPlay(m_iNowChanNo, m_iProtocolType, m_iStreamType);
if (bRet) {
LogMessage("预览通道" + (m_iNowChanNo + 1) + "成功!");
m_iPlay = 1;
}
else {
LogMessage("预览通道" + (m_iNowChanNo + 1) + "失败!");
}
}
}
/*************************************************
Function: ChangeStatus
Description: 选中窗口时,相应通道的状态显示
Input: iWindowNum : 选中窗口号
Output: 无
return: 无
*************************************************/
function ChangeStatus(iWindowNum) {
m_bDVRControl = document.getElementById("HIKOBJECT" + iWindowNum);
/*for(var i = 1; i <= 4; i ++)
{
if(i == iWindowNum)
{
document.getElementById("NetPlayOCX" + i).style.border = "1px solid #00F";
}
else
{
document.getElementById("NetPlayOCX" + i).style.border = "1px solid #EBEBEB";
}
}
LogMessage("当前选中窗口" + iWindowNum);
*/
}
//document.oncontextmenu = rightclick;
/*************************************************
Function: rightclick
Description: 网页禁用右键
Input: 无
Output: 无
Return: bool: true false
*************************************************/
function rightclick() {
return false;
}
function workaround() {
window.document.all.item("ocx").style.display = "none";
window.document.all.item("ocx").style.display = "";
document.getElementById("HIKOBJECT1").width = document.body.clientWidth;
document.getElementById("HIKOBJECT1").height = document.body.clientHeight;
}
//关闭资源,退出登录
function ExitApp() {
m_bDVRControl = document.getElementById("HIKOBJECT1");
this.m_bDVRControl.Logout();
}
//document.activex.url.value="https://192.0.7.213"
//OCXobj.SendCmd();
//OCXobj.NumBig();