demo.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. // 初始化插件
  2. function GetArgsFromHref(sHref, sArgName) {
  3. var args = sHref.split("?");
  4. var retval = "";
  5. if (args[0] == sHref) /*参数为空*/ {
  6. return retval; /*无需做任何处理*/
  7. }
  8. var str = args[1];
  9. args = str.split("&");
  10. for (var i = 0; i < args.length; i++) {
  11. str = args[i];
  12. var arg = str.split("=");
  13. if (arg.length <= 1) continue;
  14. if (arg[0] == sArgName) retval = arg[1];
  15. }
  16. return retval;
  17. }
  18. var urlinfo = window.location.href; //获取当前页面的
  19. $("#loginip").val(GetArgsFromHref(urlinfo, "szIP"));
  20. $("#port").val(GetArgsFromHref(urlinfo, "szPort")) ;
  21. $("#username").val(GetArgsFromHref(urlinfo, "szUsername"));
  22. $("#password").val(GetArgsFromHref(urlinfo, "szPassword"));
  23. // var szIP = '10.16.4.13';
  24. // var szPort = '80';
  25. // var szUsername = 'admin';
  26. // var szPassword = 'Syj1986111';
  27. var width = GetArgsFromHref(urlinfo, "width");
  28. var height = GetArgsFromHref(urlinfo, "height");
  29. document.getElementById("divPlugin").style.width = width + 'px';
  30. document.getElementById("divPlugin").style.height = height + 'px';
  31. // 全局保存当前选中窗口
  32. var g_iWndIndex = 0; //可以不用设置这个变量,有窗口参数的接口中,不用传值,开发包会默认使用当前选择窗口
  33. $(function () {
  34. // 检查插件是否已经安装过
  35. var iRet = WebVideoCtrl.I_CheckPluginInstall();
  36. if (-1 == iRet) {
  37. alert("您还未安装过插件,双击开发包目录里的WebComponentsKit.exe安装!");
  38. return;
  39. }
  40. // 初始化插件参数及插入插件
  41. WebVideoCtrl.I_InitPlugin(width, height, {
  42. bWndFull: true, //是否支持单窗口双击全屏,默认支持 true:支持 false:不支持
  43. iPackageType: 2, //2:PS 11:MP4
  44. iWndowType: 1,
  45. bNoPlugin: true,
  46. //窗口选中事件回调函数,只包含一个字符串参数,里面的值是 XML
  47. cbSelWnd: function (xmlDoc) {
  48. g_iWndIndex = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
  49. var szInfo = "当前选择的窗口编号:" + g_iWndIndex;
  50. showCBInfo(szInfo);
  51. },
  52. //窗口双击回调函数,有两个参数,第一个参数是窗口号,第二个参
  53. // 数是是否全屏
  54. cbDoubleClickWnd: function (iWndIndex, bFullScreen) {
  55. var szInfo = "当前放大的窗口编号:" + iWndIndex;
  56. if (!bFullScreen) {
  57. szInfo = "当前还原的窗口编号:" + iWndIndex;
  58. }
  59. showCBInfo(szInfo);
  60. // 此处可以处理单窗口的码流切换
  61. /*if (bFullScreen) {
  62. clickStartRealPlay(1);
  63. } else {
  64. clickStartRealPlay(2);
  65. }*/
  66. },
  67. //插件事件回调函数,有三个参数,第一个参数是事件类型,第二
  68. // 参数是窗口号
  69. cbEvent: function (iEventType, iParam1, iParam2) {
  70. if (2 == iEventType) {// 回放正常结束
  71. showCBInfo("窗口" + iParam1 + "回放结束!");
  72. } else if (-1 == iEventType) {
  73. showCBInfo("设备" + iParam1 + "网络错误!");
  74. } else if (3001 == iEventType) {
  75. clickStopRecord(g_szRecordType, iParam1);
  76. }
  77. },
  78. //远程配置库关闭回调
  79. cbRemoteConfig: function () {
  80. showCBInfo("关闭远程配置库!");
  81. },
  82. //插件初始化完成回调,必须要定义
  83. cbInitPluginComplete: function () {
  84. WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
  85. // 检查插件是否最新
  86. if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
  87. alert("检测到新的插件版本,双击开发包目录里的WebComponentsKit.exe升级!");
  88. return;
  89. }
  90. clickLogin();
  91. }
  92. });
  93. // 窗口事件绑定
  94. $(window).bind({
  95. resize: function () {
  96. var $Restart = $("#restartDiv");
  97. if ($Restart.length > 0) {
  98. var oSize = getWindowSize();
  99. $Restart.css({
  100. width: oSize.width + "px",
  101. height: oSize.height + "px"
  102. });
  103. }
  104. }
  105. });
  106. //初始化日期时间
  107. var szCurTime = dateFormat(new Date(), "yyyy-MM-dd");
  108. $("#starttime").val(szCurTime + " 00:00:00");
  109. $("#endtime").val(szCurTime + " 23:59:59");
  110. });
  111. // 显示操作信息
  112. function showOPInfo(szInfo, status, xmlDoc) {
  113. var szTip = "<div>" + dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss") + " " + szInfo;
  114. if (typeof status != "undefined" && status != 200) {
  115. var szStatusString = $(xmlDoc).find("statusString").eq(0).text();
  116. var szSubStatusCode = $(xmlDoc).find("subStatusCode").eq(0).text();
  117. if ("" === szSubStatusCode) {
  118. szTip += "(" + status + ", " + szStatusString + ")";
  119. } else {
  120. szTip += "(" + status + ", " + szSubStatusCode + ")";
  121. }
  122. }
  123. szTip += "</div>";
  124. $("#opinfo").html(szTip + $("#opinfo").html());
  125. }
  126. // 显示回调信息
  127. function showCBInfo(szInfo) {
  128. szInfo = "<div>" + dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss") + " " + szInfo + "</div>";
  129. $("#cbinfo").html(szInfo + $("#cbinfo").html());
  130. }
  131. // 格式化时间
  132. function dateFormat(oDate, fmt) {
  133. var o = {
  134. "M+": oDate.getMonth() + 1, //月份
  135. "d+": oDate.getDate(), //日
  136. "h+": oDate.getHours(), //小时
  137. "m+": oDate.getMinutes(), //分
  138. "s+": oDate.getSeconds(), //秒
  139. "q+": Math.floor((oDate.getMonth() + 3) / 3), //季度
  140. "S": oDate.getMilliseconds()//毫秒
  141. };
  142. if (/(y+)/.test(fmt)) {
  143. fmt = fmt.replace(RegExp.$1, (oDate.getFullYear() + "").substr(4 - RegExp.$1.length));
  144. }
  145. for (var k in o) {
  146. if (new RegExp("(" + k + ")").test(fmt)) {
  147. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  148. }
  149. }
  150. return fmt;
  151. }
  152. // 获取窗口尺寸
  153. function getWindowSize() {
  154. var nWidth = $(this).width() + $(this).scrollLeft(),
  155. nHeight = $(this).height() + $(this).scrollTop();
  156. return {width: nWidth, height: nHeight};
  157. }
  158. // 打开选择框 0:文件夹 1:文件
  159. function clickOpenFileDlg(id, iType) {
  160. var szDirPath = WebVideoCtrl.I_OpenFileDlg(iType);
  161. if (szDirPath != -1 && szDirPath != "" && szDirPath != null) {
  162. $("#" + id).val(szDirPath);
  163. }
  164. }
  165. // 获取本地参数
  166. function clickGetLocalCfg() {
  167. var xmlDoc = WebVideoCtrl.I_GetLocalCfg();
  168. if (xmlDoc != null) {
  169. $("#netsPreach").val($(xmlDoc).find("BuffNumberType").eq(0).text());
  170. $("#wndSize").val($(xmlDoc).find("PlayWndType").eq(0).text());
  171. $("#rulesInfo").val($(xmlDoc).find("IVSMode").eq(0).text());
  172. $("#captureFileFormat").val($(xmlDoc).find("CaptureFileFormat").eq(0).text());
  173. $("#packSize").val($(xmlDoc).find("PackgeSize").eq(0).text());
  174. $("#recordPath").val($(xmlDoc).find("RecordPath").eq(0).text());
  175. $("#downloadPath").val($(xmlDoc).find("DownloadPath").eq(0).text());
  176. $("#previewPicPath").val($(xmlDoc).find("CapturePath").eq(0).text());
  177. $("#playbackPicPath").val($(xmlDoc).find("PlaybackPicPath").eq(0).text());
  178. $("#devicePicPath").val($(xmlDoc).find("DeviceCapturePath").eq(0).text());
  179. $("#playbackFilePath").val($(xmlDoc).find("PlaybackFilePath").eq(0).text());
  180. $("#protocolType").val($(xmlDoc).find("ProtocolType").eq(0).text());
  181. showOPInfo("本地配置获取成功!");
  182. } else {
  183. showOPInfo("本地配置获取失败!");
  184. }
  185. }
  186. // 设置本地参数
  187. function clickSetLocalCfg() {
  188. var arrXml = [],
  189. szInfo = "";
  190. arrXml.push("<LocalConfigInfo>");
  191. arrXml.push("<PackgeSize>" + $("#packSize").val() + "</PackgeSize>");
  192. arrXml.push("<PlayWndType>" + $("#wndSize").val() + "</PlayWndType>");
  193. arrXml.push("<BuffNumberType>" + $("#netsPreach").val() + "</BuffNumberType>");
  194. arrXml.push("<RecordPath>" + $("#recordPath").val() + "</RecordPath>");
  195. arrXml.push("<CapturePath>" + $("#previewPicPath").val() + "</CapturePath>");
  196. arrXml.push("<PlaybackFilePath>" + $("#playbackFilePath").val() + "</PlaybackFilePath>");
  197. arrXml.push("<PlaybackPicPath>" + $("#playbackPicPath").val() + "</PlaybackPicPath>");
  198. arrXml.push("<DeviceCapturePath>" + $("#devicePicPath").val() + "</DeviceCapturePath>");
  199. arrXml.push("<DownloadPath>" + $("#downloadPath").val() + "</DownloadPath>");
  200. arrXml.push("<IVSMode>" + $("#rulesInfo").val() + "</IVSMode>");
  201. arrXml.push("<CaptureFileFormat>" + $("#captureFileFormat").val() + "</CaptureFileFormat>");
  202. arrXml.push("<ProtocolType>" + $("#protocolType").val() + "</ProtocolType>");
  203. arrXml.push("</LocalConfigInfo>");
  204. var iRet = WebVideoCtrl.I_SetLocalCfg(arrXml.join(""));
  205. if (0 == iRet) {
  206. szInfo = "本地配置设置成功!";
  207. } else {
  208. szInfo = "本地配置设置失败!";
  209. }
  210. showOPInfo(szInfo);
  211. }
  212. // 窗口分割数
  213. function changeWndNum(iType) {
  214. iType = parseInt(iType, 10);
  215. WebVideoCtrl.I_ChangeWndNum(iType);
  216. }
  217. // 登录
  218. function clickLogin() {
  219. console.log('1111');
  220. var szIP = $("#loginip").val(),
  221. szPort = $("#port").val(),
  222. szUsername = $("#username").val(),
  223. szPassword = $("#password").val();
  224. if ("" == szIP || "" == szPort) {
  225. return;
  226. }
  227. var szDeviceIdentify = szIP + "_" + szPort;
  228. var iRet = WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, {
  229. success: function (xmlDoc) {
  230. showOPInfo(szDeviceIdentify + " 登录成功!");
  231. $("#ip").prepend("<option value='" + szDeviceIdentify + "'>" + szDeviceIdentify + "</option>");
  232. setTimeout(function () {
  233. $("#ip").val(szDeviceIdentify);
  234. getChannelInfo();
  235. getDevicePort();
  236. }, 10);
  237. },
  238. error: function (status, xmlDoc) {
  239. showOPInfo(szDeviceIdentify + " 登录失败!", status, xmlDoc);
  240. }
  241. });
  242. if (-1 == iRet) {
  243. showOPInfo(szDeviceIdentify + " 已登录过!");
  244. }
  245. }
  246. // 退出
  247. function clickLogout() {
  248. var szDeviceIdentify = $("#ip").val(),
  249. szInfo = "";
  250. if (null == szDeviceIdentify) {
  251. return;
  252. }
  253. var iRet = WebVideoCtrl.I_Logout(szDeviceIdentify);
  254. if (0 == iRet) {
  255. szInfo = "退出成功!";
  256. $("#ip option[value='" + szDeviceIdentify + "']").remove();
  257. getChannelInfo();
  258. getDevicePort();
  259. } else {
  260. szInfo = "退出失败!";
  261. }
  262. showOPInfo(szDeviceIdentify + " " + szInfo);
  263. }
  264. // 获取设备信息
  265. function clickGetDeviceInfo() {
  266. var szDeviceIdentify = $("#ip").val();
  267. if (null == szDeviceIdentify) {
  268. return;
  269. }
  270. WebVideoCtrl.I_GetDeviceInfo(szDeviceIdentify, {
  271. success: function (xmlDoc) {
  272. var arrStr = [];
  273. arrStr.push("设备名称:" + $(xmlDoc).find("deviceName").eq(0).text() + "\r\n");
  274. arrStr.push("设备ID:" + $(xmlDoc).find("deviceID").eq(0).text() + "\r\n");
  275. arrStr.push("型号:" + $(xmlDoc).find("model").eq(0).text() + "\r\n");
  276. arrStr.push("设备序列号:" + $(xmlDoc).find("serialNumber").eq(0).text() + "\r\n");
  277. arrStr.push("MAC地址:" + $(xmlDoc).find("macAddress").eq(0).text() + "\r\n");
  278. arrStr.push("主控版本:" + $(xmlDoc).find("firmwareVersion").eq(0).text() + " " + $(xmlDoc).find("firmwareReleasedDate").eq(0).text() + "\r\n");
  279. arrStr.push("编码版本:" + $(xmlDoc).find("encoderVersion").eq(0).text() + " " + $(xmlDoc).find("encoderReleasedDate").eq(0).text() + "\r\n");
  280. showOPInfo(szDeviceIdentify + " 获取设备信息成功!");
  281. alert(arrStr.join(""));
  282. },
  283. error: function (status, xmlDoc) {
  284. showOPInfo(szDeviceIdentify + " 获取设备信息失败!", status, xmlDoc);
  285. }
  286. });
  287. }
  288. // 获取通道
  289. function getChannelInfo() {
  290. var szDeviceIdentify = $("#ip").val(),
  291. oSel = $("#channels").empty();
  292. if (null == szDeviceIdentify) {
  293. return;
  294. }
  295. // 模拟通道
  296. WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {
  297. async: true,
  298. success: function (xmlDoc) {
  299. var oChannels = $(xmlDoc).find("VideoInputChannel");
  300. $.each(oChannels, function (i) {
  301. var id = $(this).find("id").eq(0).text(),
  302. name = $(this).find("name").eq(0).text();
  303. if ("" == name) {
  304. name = "Camera " + (i < 9 ? "0" + (i + 1) : (i + 1));
  305. }
  306. oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
  307. });
  308. showOPInfo(szDeviceIdentify + " 获取模拟通道成功!");
  309. console.log("获取模拟通道成功");
  310. clickStartRealPlay();
  311. },
  312. error: function (status, xmlDoc) {
  313. showOPInfo(szDeviceIdentify + " 获取模拟通道失败!", status, xmlDoc);
  314. }
  315. });
  316. // 数字通道
  317. WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
  318. async: false,
  319. success: function (xmlDoc) {
  320. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  321. $.each(oChannels, function (i) {
  322. var id = $(this).find("id").eq(0).text(),
  323. name = $(this).find("name").eq(0).text(),
  324. online = $(this).find("online").eq(0).text();
  325. if ("false" == online) {// 过滤禁用的数字通道
  326. return true;
  327. }
  328. if ("" == name) {
  329. name = "IPCamera " + (i < 9 ? "0" + (i + 1) : (i + 1));
  330. }
  331. oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
  332. });
  333. console.log("获取数字通道成功");
  334. showOPInfo(szDeviceIdentify + " 获取数字通道成功!");
  335. },
  336. error: function (status, xmlDoc) {
  337. showOPInfo(szDeviceIdentify + " 获取数字通道失败!", status, xmlDoc);
  338. }
  339. });
  340. // 零通道
  341. WebVideoCtrl.I_GetZeroChannelInfo(szDeviceIdentify, {
  342. async: false,
  343. success: function (xmlDoc) {
  344. var oChannels = $(xmlDoc).find("ZeroVideoChannel");
  345. $.each(oChannels, function (i) {
  346. var id = $(this).find("id").eq(0).text(),
  347. name = $(this).find("name").eq(0).text();
  348. if ("" == name) {
  349. name = "Zero Channel " + (i < 9 ? "0" + (i + 1) : (i + 1));
  350. }
  351. if ("true" == $(this).find("enabled").eq(0).text()) {// 过滤禁用的零通道
  352. oSel.append("<option value='" + id + "' bZero='true'>" + name + "</option>");
  353. }
  354. });
  355. console.log("获取零通道成功");
  356. showOPInfo(szDeviceIdentify + " 获取零通道成功!");
  357. },
  358. error: function (status, xmlDoc) {
  359. showOPInfo(szDeviceIdentify + " 获取零通道失败!", status, xmlDoc);
  360. }
  361. });
  362. }
  363. // 获取端口
  364. function getDevicePort() {
  365. var szDeviceIdentify = $("#ip").val();
  366. if (null == szDeviceIdentify) {
  367. return;
  368. }
  369. var oPort = WebVideoCtrl.I_GetDevicePort(szDeviceIdentify);
  370. if (oPort != null) {
  371. $("#deviceport").val(oPort.iDevicePort);
  372. $("#rtspport").val(oPort.iRtspPort);
  373. showOPInfo(szDeviceIdentify + " 获取端口成功!");
  374. } else {
  375. showOPInfo(szDeviceIdentify + " 获取端口失败!");
  376. }
  377. }
  378. // 获取数字通道
  379. function clickGetDigitalChannelInfo() {
  380. var szDeviceIdentify = $("#ip").val(),
  381. iAnalogChannelNum = 0;
  382. $("#digitalchannellist").empty();
  383. if (null == szDeviceIdentify) {
  384. return;
  385. }
  386. // 模拟通道
  387. WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {
  388. async: false,
  389. success: function (xmlDoc) {
  390. iAnalogChannelNum = $(xmlDoc).find("VideoInputChannel").length;
  391. },
  392. error: function () {
  393. }
  394. });
  395. // 数字通道
  396. WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
  397. async: false,
  398. success: function (xmlDoc) {
  399. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  400. $.each(oChannels, function () {
  401. var id = parseInt($(this).find("id").eq(0).text(), 10),
  402. ipAddress = $(this).find("ipAddress").eq(0).text(),
  403. srcInputPort = $(this).find("srcInputPort").eq(0).text(),
  404. managePortNo = $(this).find("managePortNo").eq(0).text(),
  405. online = $(this).find("online").eq(0).text(),
  406. proxyProtocol = $(this).find("proxyProtocol").eq(0).text();
  407. var objTr = $("#digitalchannellist").get(0).insertRow(-1);
  408. var objTd = objTr.insertCell(0);
  409. objTd.innerHTML = (id - iAnalogChannelNum) < 10 ? "D0" + (id - iAnalogChannelNum) : "D" + (id - iAnalogChannelNum);
  410. objTd = objTr.insertCell(1);
  411. objTd.width = "25%";
  412. objTd.innerHTML = ipAddress;
  413. objTd = objTr.insertCell(2);
  414. objTd.width = "15%";
  415. objTd.innerHTML = srcInputPort;
  416. objTd = objTr.insertCell(3);
  417. objTd.width = "20%";
  418. objTd.innerHTML = managePortNo;
  419. objTd = objTr.insertCell(4);
  420. objTd.width = "15%";
  421. objTd.innerHTML = "true" == online ? "在线" : "离线";
  422. objTd = objTr.insertCell(5);
  423. objTd.width = "25%";
  424. objTd.innerHTML = proxyProtocol;
  425. });
  426. showOPInfo(szDeviceIdentify + " 获取数字通道成功!");
  427. },
  428. error: function (status, xmlDoc) {
  429. showOPInfo(szDeviceIdentify + " 没有数字通道!", status, xmlDoc);
  430. }
  431. });
  432. }
  433. // 开始预览
  434. function clickStartRealPlay(iStreamType) {
  435. console.log('开始预览')
  436. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  437. szDeviceIdentify = $("#ip").val(),
  438. iRtspPort = parseInt($("#rtspport").val(), 10),
  439. iChannelID = parseInt($("#channels").val(), 10),
  440. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  441. szInfo = "";
  442. if ("undefined" === typeof iStreamType) {
  443. iStreamType = parseInt($("#streamtype").val(), 10);
  444. }
  445. if (null == szDeviceIdentify) {
  446. return;
  447. }
  448. var startRealPlay = function () {
  449. WebVideoCtrl.I_StartRealPlay(szDeviceIdentify, {
  450. iRtspPort: iRtspPort,
  451. iStreamType: iStreamType,
  452. iChannelID: iChannelID,
  453. bZeroChannel: bZeroChannel,
  454. success: function () {
  455. szInfo = "开始预览成功!";
  456. showOPInfo(szDeviceIdentify + " " + szInfo);
  457. },
  458. error: function (status, xmlDoc) {
  459. if (403 === status) {
  460. szInfo = "设备不支持Websocket取流!";
  461. } else {
  462. szInfo = "开始预览失败!";
  463. }
  464. showOPInfo(szDeviceIdentify + " " + szInfo);
  465. }
  466. });
  467. };
  468. if (oWndInfo != null) {// 已经在播放了,先停止
  469. WebVideoCtrl.I_Stop({
  470. success: function () {
  471. startRealPlay();
  472. }
  473. });
  474. } else {
  475. startRealPlay();
  476. }
  477. }
  478. // 停止预览
  479. function clickStopRealPlay() {
  480. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  481. szInfo = "";
  482. if (oWndInfo != null) {
  483. WebVideoCtrl.I_Stop({
  484. success: function () {
  485. szInfo = "停止预览成功!";
  486. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  487. },
  488. error: function () {
  489. szInfo = "停止预览失败!";
  490. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  491. }
  492. });
  493. }
  494. }
  495. // 打开声音
  496. function clickOpenSound() {
  497. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  498. szInfo = "";
  499. if (oWndInfo != null) {
  500. var allWndInfo = WebVideoCtrl.I_GetWindowStatus();
  501. // 循环遍历所有窗口,如果有窗口打开了声音,先关闭
  502. for (var i = 0, iLen = allWndInfo.length; i < iLen; i++) {
  503. oWndInfo = allWndInfo[i];
  504. if (oWndInfo.bSound) {
  505. WebVideoCtrl.I_CloseSound(oWndInfo.iIndex);
  506. break;
  507. }
  508. }
  509. var iRet = WebVideoCtrl.I_OpenSound();
  510. if (0 == iRet) {
  511. szInfo = "打开声音成功!";
  512. } else {
  513. szInfo = "打开声音失败!";
  514. }
  515. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  516. }
  517. }
  518. // 关闭声音
  519. function clickCloseSound() {
  520. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  521. szInfo = "";
  522. if (oWndInfo != null) {
  523. var iRet = WebVideoCtrl.I_CloseSound();
  524. if (0 == iRet) {
  525. szInfo = "关闭声音成功!";
  526. } else {
  527. szInfo = "关闭声音失败!";
  528. }
  529. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  530. }
  531. }
  532. // 设置音量
  533. function clickSetVolume() {
  534. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  535. iVolume = parseInt($("#volume").val(), 10),
  536. szInfo = "";
  537. if (oWndInfo != null) {
  538. var iRet = WebVideoCtrl.I_SetVolume(iVolume);
  539. if (0 == iRet) {
  540. szInfo = "音量设置成功!";
  541. } else {
  542. szInfo = "音量设置失败!";
  543. }
  544. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  545. }
  546. }
  547. // 抓图
  548. function clickCapturePic() {
  549. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  550. szInfo = "";
  551. if (oWndInfo != null) {
  552. var xmlDoc = WebVideoCtrl.I_GetLocalCfg();
  553. var szCaptureFileFormat = "0";
  554. if (xmlDoc != null) {
  555. szCaptureFileFormat = $(xmlDoc).find("CaptureFileFormat").eq(0).text();
  556. }
  557. var szChannelID = $("#channels").val();
  558. var szPicName = oWndInfo.szDeviceIdentify + "_" + szChannelID + "_" + new Date().getTime();
  559. szPicName += ("0" === szCaptureFileFormat) ? ".jpg": ".bmp";
  560. var iRet = WebVideoCtrl.I_CapturePic(szPicName, {
  561. bDateDir: true //是否生成日期文件
  562. });
  563. if (0 == iRet) {
  564. szInfo = "抓图成功!";
  565. } else {
  566. szInfo = "抓图失败!";
  567. }
  568. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  569. }
  570. }
  571. // 开始录像
  572. var g_szRecordType = "";
  573. function clickStartRecord(szType) {
  574. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  575. szInfo = "";
  576. g_szRecordType = szType;
  577. if (oWndInfo != null) {
  578. var szChannelID = $("#channels").val(),
  579. szFileName = oWndInfo.szDeviceIdentify + "_" + szChannelID + "_" + new Date().getTime();
  580. WebVideoCtrl.I_StartRecord(szFileName, {
  581. bDateDir: true, //是否生成日期文件
  582. success: function () {
  583. if ('realplay' === szType) {
  584. szInfo = "开始录像成功!";
  585. } else if ('playback' === szType) {
  586. szInfo = "开始剪辑成功!";
  587. }
  588. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  589. },
  590. error: function () {
  591. if ('realplay' === szType) {
  592. szInfo = "开始录像失败!";
  593. } else if ('playback' === szType) {
  594. szInfo = "开始剪辑失败!";
  595. }
  596. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  597. }
  598. });
  599. }
  600. }
  601. // 停止录像
  602. function clickStopRecord(szType, iWndIndex) {
  603. if ("undefined" === typeof iWndIndex) {
  604. iWndIndex = g_iWndIndex;
  605. }
  606. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(iWndIndex),
  607. szInfo = "";
  608. if (oWndInfo != null) {
  609. WebVideoCtrl.I_StopRecord({
  610. success: function () {
  611. if ('realplay' === szType) {
  612. szInfo = "停止录像成功!";
  613. } else if ('playback' === szType) {
  614. szInfo = "停止剪辑成功!";
  615. }
  616. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  617. },
  618. error: function () {
  619. if ('realplay' === szType) {
  620. szInfo = "停止录像失败!";
  621. } else if ('playback' === szType) {
  622. szInfo = "停止剪辑失败!";
  623. }
  624. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  625. }
  626. });
  627. }
  628. }
  629. // 获取对讲通道
  630. function clickGetAudioInfo() {
  631. var szDeviceIdentify = $("#ip").val();
  632. if (null == szDeviceIdentify) {
  633. return;
  634. }
  635. WebVideoCtrl.I_GetAudioInfo(szDeviceIdentify, {
  636. success: function (xmlDoc) {
  637. var oAudioChannels = $(xmlDoc).find("TwoWayAudioChannel"),
  638. oSel = $("#audiochannels").empty();
  639. $.each(oAudioChannels, function () {
  640. var id = $(this).find("id").eq(0).text();
  641. oSel.append("<option value='" + id + "'>" + id + "</option>");
  642. });
  643. showOPInfo(szDeviceIdentify + " 获取对讲通道成功!");
  644. },
  645. error: function (status, xmlDoc) {
  646. showOPInfo(szDeviceIdentify + " 获取对讲通道失败!", status, xmlDoc);
  647. }
  648. });
  649. }
  650. // 开始对讲
  651. function clickStartVoiceTalk() {
  652. var szDeviceIdentify = $("#ip").val(),
  653. iAudioChannel = parseInt($("#audiochannels").val(), 10),
  654. szInfo = "";
  655. if (null == szDeviceIdentify) {
  656. return;
  657. }
  658. if (isNaN(iAudioChannel)) {
  659. alert("请选择对讲通道!");
  660. return;
  661. }
  662. var iRet = WebVideoCtrl.I_StartVoiceTalk(szDeviceIdentify, iAudioChannel);
  663. if (0 == iRet) {
  664. szInfo = "开始对讲成功!";
  665. } else {
  666. szInfo = "开始对讲失败!";
  667. }
  668. showOPInfo(szDeviceIdentify + " " + szInfo);
  669. }
  670. // 停止对讲
  671. function clickStopVoiceTalk() {
  672. var szDeviceIdentify = $("#ip").val(),
  673. iRet = WebVideoCtrl.I_StopVoiceTalk(),
  674. szInfo = "";
  675. if (null == szDeviceIdentify) {
  676. return;
  677. }
  678. if (0 == iRet) {
  679. szInfo = "停止对讲成功!";
  680. } else {
  681. szInfo = "停止对讲失败!";
  682. }
  683. showOPInfo(szDeviceIdentify + " " + szInfo);
  684. }
  685. // 启用电子放大
  686. function clickEnableEZoom() {
  687. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  688. szInfo = "";
  689. if (oWndInfo != null) {
  690. var iRet = WebVideoCtrl.I_EnableEZoom();
  691. if (0 == iRet) {
  692. szInfo = "启用电子放大成功!";
  693. } else {
  694. szInfo = "启用电子放大失败!";
  695. }
  696. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  697. }
  698. }
  699. // 禁用电子放大
  700. function clickDisableEZoom() {
  701. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  702. szInfo = "";
  703. if (oWndInfo != null) {
  704. var iRet = WebVideoCtrl.I_DisableEZoom();
  705. if (0 == iRet) {
  706. szInfo = "禁用电子放大成功!";
  707. } else {
  708. szInfo = "禁用电子放大失败!";
  709. }
  710. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  711. }
  712. }
  713. // 启用3D放大
  714. function clickEnable3DZoom() {
  715. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  716. szInfo = "";
  717. if (oWndInfo != null) {
  718. var iRet = WebVideoCtrl.I_Enable3DZoom();
  719. if (0 == iRet) {
  720. szInfo = "启用3D放大成功!";
  721. } else {
  722. szInfo = "启用3D放大失败!";
  723. }
  724. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  725. }
  726. }
  727. // 禁用3D放大
  728. function clickDisable3DZoom() {
  729. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  730. szInfo = "";
  731. if (oWndInfo != null) {
  732. var iRet = WebVideoCtrl.I_Disable3DZoom();
  733. if (0 == iRet) {
  734. szInfo = "禁用3D放大成功!";
  735. } else {
  736. szInfo = "禁用3D放大失败!";
  737. }
  738. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  739. }
  740. }
  741. // 全屏
  742. function clickFullScreen() {
  743. WebVideoCtrl.I_FullScreen(true);
  744. }
  745. // PTZ控制 9为自动,1,2,3,4,5,6,7,8为方向PTZ
  746. var g_bPTZAuto = false;
  747. function mouseDownPTZControl(iPTZIndex) {
  748. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  749. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  750. iPTZSpeed = $("#ptzspeed").val();
  751. if (bZeroChannel) {// 零通道不支持云台
  752. return;
  753. }
  754. if (oWndInfo != null) {
  755. if (9 == iPTZIndex && g_bPTZAuto) {
  756. iPTZSpeed = 0;// 自动开启后,速度置为0可以关闭自动
  757. } else {
  758. g_bPTZAuto = false;// 点击其他方向,自动肯定会被关闭
  759. }
  760. WebVideoCtrl.I_PTZControl(iPTZIndex, false, {
  761. iPTZSpeed: iPTZSpeed,
  762. success: function (xmlDoc) {
  763. if (9 == iPTZIndex && g_bPTZAuto) {
  764. showOPInfo(oWndInfo.szDeviceIdentify + " 停止云台成功!");
  765. } else {
  766. showOPInfo(oWndInfo.szDeviceIdentify + " 开启云台成功!");
  767. }
  768. if (9 == iPTZIndex) {
  769. g_bPTZAuto = !g_bPTZAuto;
  770. }
  771. },
  772. error: function (status, xmlDoc) {
  773. showOPInfo(oWndInfo.szDeviceIdentify + " 开启云台失败!", status, xmlDoc);
  774. }
  775. });
  776. }
  777. }
  778. // 方向PTZ停止
  779. function mouseUpPTZControl() {
  780. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  781. if (oWndInfo != null) {
  782. WebVideoCtrl.I_PTZControl(1, true, {
  783. success: function (xmlDoc) {
  784. showOPInfo(oWndInfo.szDeviceIdentify + " 停止云台成功!");
  785. },
  786. error: function (status, xmlDoc) {
  787. showOPInfo(oWndInfo.szDeviceIdentify + " 停止云台失败!", status, xmlDoc);
  788. }
  789. });
  790. }
  791. }
  792. // 设置预置点
  793. function clickSetPreset() {
  794. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  795. iPresetID = parseInt($("#preset").val(), 10);
  796. if (oWndInfo != null) {
  797. WebVideoCtrl.I_SetPreset(iPresetID, {
  798. success: function (xmlDoc) {
  799. showOPInfo(oWndInfo.szDeviceIdentify + " 设置预置点成功!");
  800. },
  801. error: function (status, xmlDoc) {
  802. showOPInfo(oWndInfo.szDeviceIdentify + " 设置预置点失败!", status, xmlDoc);
  803. }
  804. });
  805. }
  806. }
  807. // 调用预置点
  808. function clickGoPreset() {
  809. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  810. iPresetID = parseInt($("#preset").val(), 10);
  811. if (oWndInfo != null) {
  812. WebVideoCtrl.I_GoPreset(iPresetID, {
  813. success: function (xmlDoc) {
  814. showOPInfo(oWndInfo.szDeviceIdentify + " 调用预置点成功!");
  815. },
  816. error: function (status, xmlDoc) {
  817. showOPInfo(oWndInfo.szDeviceIdentify + " 调用预置点失败!", status, xmlDoc);
  818. }
  819. });
  820. }
  821. }
  822. // 搜索录像
  823. var g_iSearchTimes = 0;
  824. function clickRecordSearch(iType) {
  825. var szDeviceIdentify = $("#ip").val(),
  826. iChannelID = parseInt($("#channels").val(), 10),
  827. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  828. iStreamType = parseInt($("#record_streamtype").val(), 10),
  829. szStartTime = $("#starttime").val(),
  830. szEndTime = $("#endtime").val();
  831. if (null == szDeviceIdentify) {
  832. return;
  833. }
  834. if (bZeroChannel) {// 零通道不支持录像搜索
  835. return;
  836. }
  837. if (0 == iType) {// 首次搜索
  838. $("#searchlist").empty();
  839. g_iSearchTimes = 0;
  840. }
  841. WebVideoCtrl.I_RecordSearch(szDeviceIdentify, iChannelID, szStartTime, szEndTime, {
  842. iStreamType: iStreamType,
  843. iSearchPos: g_iSearchTimes * 40,
  844. success: function (xmlDoc) {
  845. if ("MORE" === $(xmlDoc).find("responseStatusStrg").eq(0).text()) {
  846. for(var i = 0, nLen = $(xmlDoc).find("searchMatchItem").length; i < nLen; i++) {
  847. var szPlaybackURI = $(xmlDoc).find("playbackURI").eq(i).text();
  848. if(szPlaybackURI.indexOf("name=") < 0) {
  849. break;
  850. }
  851. var szStartTime = $(xmlDoc).find("startTime").eq(i).text();
  852. var szEndTime = $(xmlDoc).find("endTime").eq(i).text();
  853. var szFileName = szPlaybackURI.substring(szPlaybackURI.indexOf("name=") + 5, szPlaybackURI.indexOf("&size="));
  854. var objTr = $("#searchlist").get(0).insertRow(-1);
  855. var objTd = objTr.insertCell(0);
  856. objTd.id = "downloadTd" + i;
  857. objTd.innerHTML = g_iSearchTimes * 40 + (i + 1);
  858. objTd = objTr.insertCell(1);
  859. objTd.width = "30%";
  860. objTd.innerHTML = szFileName;
  861. objTd = objTr.insertCell(2);
  862. objTd.width = "30%";
  863. objTd.innerHTML = (szStartTime.replace("T", " ")).replace("Z", "");
  864. objTd = objTr.insertCell(3);
  865. objTd.width = "30%";
  866. objTd.innerHTML = (szEndTime.replace("T", " ")).replace("Z", "");
  867. objTd = objTr.insertCell(4);
  868. objTd.width = "10%";
  869. objTd.innerHTML = "<a href='javascript:;' onclick='clickStartDownloadRecord(" + (i + g_iSearchTimes * 40) + ");'>下载</a>";
  870. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("fileName", szFileName);
  871. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("playbackURI", szPlaybackURI);
  872. }
  873. g_iSearchTimes++;
  874. clickRecordSearch(1);// 继续搜索
  875. } else if ("OK" === $(xmlDoc).find("responseStatusStrg").eq(0).text()) {
  876. var iLength = $(xmlDoc).find("searchMatchItem").length;
  877. for(var i = 0; i < iLength; i++) {
  878. var szPlaybackURI = $(xmlDoc).find("playbackURI").eq(i).text();
  879. if(szPlaybackURI.indexOf("name=") < 0) {
  880. break;
  881. }
  882. var szStartTime = $(xmlDoc).find("startTime").eq(i).text();
  883. var szEndTime = $(xmlDoc).find("endTime").eq(i).text();
  884. var szFileName = szPlaybackURI.substring(szPlaybackURI.indexOf("name=") + 5, szPlaybackURI.indexOf("&size="));
  885. var objTr = $("#searchlist").get(0).insertRow(-1);
  886. var objTd = objTr.insertCell(0);
  887. objTd.id = "downloadTd" + i;
  888. objTd.innerHTML = g_iSearchTimes * 40 + (i + 1);
  889. objTd = objTr.insertCell(1);
  890. objTd.width = "30%";
  891. objTd.innerHTML = szFileName;
  892. objTd = objTr.insertCell(2);
  893. objTd.width = "30%";
  894. objTd.innerHTML = (szStartTime.replace("T", " ")).replace("Z", "");
  895. objTd = objTr.insertCell(3);
  896. objTd.width = "30%";
  897. objTd.innerHTML = (szEndTime.replace("T", " ")).replace("Z", "");
  898. objTd = objTr.insertCell(4);
  899. objTd.width = "10%";
  900. objTd.innerHTML = "<a href='javascript:;' onclick='clickStartDownloadRecord(" + (i + g_iSearchTimes * 40) + ");'>下载</a>";
  901. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("fileName", szFileName);
  902. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("playbackURI", szPlaybackURI);
  903. }
  904. showOPInfo(szDeviceIdentify + " 搜索录像文件成功!");
  905. } else if("NO MATCHES" === $(xmlDoc).find("responseStatusStrg").eq(0).text()) {
  906. setTimeout(function() {
  907. showOPInfo(szDeviceIdentify + " 没有录像文件!");
  908. }, 50);
  909. }
  910. },
  911. error: function (status, xmlDoc) {
  912. showOPInfo(szDeviceIdentify + " 搜索录像文件失败!", status, xmlDoc);
  913. }
  914. });
  915. }
  916. // 开始回放
  917. function clickStartPlayback() {
  918. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  919. szDeviceIdentify = $("#ip").val(),
  920. iRtspPort = parseInt($("#rtspport").val(), 10),
  921. iStreamType = parseInt($("#record_streamtype").val(), 10),
  922. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  923. iChannelID = parseInt($("#channels").val(), 10),
  924. szStartTime = $("#starttime").val(),
  925. szEndTime = $("#endtime").val(),
  926. szInfo = "",
  927. bChecked = $("#transstream").prop("checked"),
  928. iRet = -1;
  929. if (null == szDeviceIdentify) {
  930. return;
  931. }
  932. if (bZeroChannel) {// 零通道不支持回放
  933. return;
  934. }
  935. var startPlayback = function () {
  936. if (bChecked) {// 启用转码回放
  937. var oTransCodeParam = {
  938. TransFrameRate: "14",// 0:全帧率,5:1,6:2,7:4,8:6,9:8,10:10,11:12,12:16,14:15,15:18,13:20,16:22
  939. TransResolution: "1",// 255:Auto,3:4CIF,2:QCIF,1:CIF
  940. TransBitrate: "19"// 2:32K,3:48K,4:64K,5:80K,6:96K,7:128K,8:160K,9:192K,10:224K,11:256K,12:320K,13:384K,14:448K,15:512K,16:640K,17:768K,18:896K,19:1024K,20:1280K,21:1536K,22:1792K,23:2048K,24:3072K,25:4096K,26:8192K
  941. };
  942. WebVideoCtrl.I_StartPlayback(szDeviceIdentify, {
  943. iRtspPort: iRtspPort,
  944. iStreamType: iStreamType,
  945. iChannelID: iChannelID,
  946. szStartTime: szStartTime,
  947. szEndTime: szEndTime,
  948. oTransCodeParam: oTransCodeParam,
  949. success: function () {
  950. szInfo = "开始回放成功!";
  951. showOPInfo(szDeviceIdentify + " " + szInfo);
  952. },
  953. error: function (status, xmlDoc) {
  954. if (403 === status) {
  955. szInfo = "设备不支持Websocket取流!";
  956. } else {
  957. szInfo = "开始回放失败!";
  958. }
  959. showOPInfo(szDeviceIdentify + " " + szInfo);
  960. }
  961. });
  962. } else {
  963. WebVideoCtrl.I_StartPlayback(szDeviceIdentify, {
  964. iRtspPort: iRtspPort,
  965. iStreamType: iStreamType,
  966. iChannelID: iChannelID,
  967. szStartTime: szStartTime,
  968. szEndTime: szEndTime,
  969. success: function () {
  970. szInfo = "开始回放成功!";
  971. showOPInfo(szDeviceIdentify + " " + szInfo);
  972. },
  973. error: function (status, xmlDoc) {
  974. if (403 === status) {
  975. szInfo = "设备不支持Websocket取流!";
  976. } else {
  977. szInfo = "开始回放失败!";
  978. }
  979. showOPInfo(szDeviceIdentify + " " + szInfo);
  980. }
  981. });
  982. }
  983. };
  984. if (oWndInfo != null) {// 已经在播放了,先停止
  985. WebVideoCtrl.I_Stop({
  986. success: function () {
  987. startPlayback();
  988. }
  989. });
  990. } else {
  991. startPlayback();
  992. }
  993. }
  994. // 停止回放
  995. function clickStopPlayback() {
  996. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  997. szInfo = "";
  998. if (oWndInfo != null) {
  999. WebVideoCtrl.I_Stop({
  1000. success: function () {
  1001. szInfo = "停止回放成功!";
  1002. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1003. },
  1004. error: function () {
  1005. szInfo = "停止回放失败!";
  1006. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1007. }
  1008. });
  1009. }
  1010. }
  1011. // 开始倒放
  1012. function clickReversePlayback() {
  1013. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1014. szDeviceIdentify = $("#ip").val(),
  1015. iRtspPort = parseInt($("#rtspport").val(), 10),
  1016. iStreamType = parseInt($("#record_streamtype").val(), 10),
  1017. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  1018. iChannelID = parseInt($("#channels").val(), 10),
  1019. szStartTime = $("#starttime").val(),
  1020. szEndTime = $("#endtime").val(),
  1021. szInfo = "";
  1022. if (null == szDeviceIdentify) {
  1023. return;
  1024. }
  1025. if (bZeroChannel) {// 零通道不支持倒放
  1026. return;
  1027. }
  1028. var reversePlayback = function () {
  1029. var iRet = WebVideoCtrl.I_ReversePlayback(szDeviceIdentify, {
  1030. iRtspPort: iRtspPort,
  1031. iStreamType: iStreamType,
  1032. iChannelID: iChannelID,
  1033. szStartTime: szStartTime,
  1034. szEndTime: szEndTime
  1035. });
  1036. if (0 == iRet) {
  1037. szInfo = "开始倒放成功!";
  1038. } else {
  1039. szInfo = "开始倒放失败!";
  1040. }
  1041. showOPInfo(szDeviceIdentify + " " + szInfo);
  1042. };
  1043. if (oWndInfo != null) {// 已经在播放了,先停止
  1044. WebVideoCtrl.I_Stop({
  1045. success: function () {
  1046. reversePlayback();
  1047. }
  1048. });
  1049. } else {
  1050. reversePlayback();
  1051. }
  1052. }
  1053. // 单帧
  1054. function clickFrame() {
  1055. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1056. szInfo = "";
  1057. if (oWndInfo != null) {
  1058. WebVideoCtrl.I_Frame({
  1059. success: function () {
  1060. szInfo = "单帧播放成功!";
  1061. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1062. },
  1063. error: function () {
  1064. szInfo = "单帧播放失败!";
  1065. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1066. }
  1067. });
  1068. }
  1069. }
  1070. // 暂停
  1071. function clickPause() {
  1072. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1073. szInfo = "";
  1074. if (oWndInfo != null) {
  1075. WebVideoCtrl.I_Pause({
  1076. success: function () {
  1077. szInfo = "暂停成功!";
  1078. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1079. },
  1080. error: function () {
  1081. szInfo = "暂停失败!";
  1082. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1083. }
  1084. });
  1085. }
  1086. }
  1087. // 恢复
  1088. function clickResume() {
  1089. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1090. szInfo = "";
  1091. if (oWndInfo != null) {
  1092. WebVideoCtrl.I_Resume({
  1093. success: function () {
  1094. szInfo = "恢复成功!";
  1095. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1096. },
  1097. error: function () {
  1098. szInfo = "恢复失败!";
  1099. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1100. }
  1101. });
  1102. }
  1103. }
  1104. // 慢放
  1105. function clickPlaySlow() {
  1106. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1107. szInfo = "";
  1108. if (oWndInfo != null) {
  1109. WebVideoCtrl.I_PlaySlow({
  1110. success: function () {
  1111. szInfo = "慢放成功!";
  1112. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1113. },
  1114. error: function () {
  1115. szInfo = "慢放失败!";
  1116. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1117. }
  1118. });
  1119. }
  1120. }
  1121. // 快放
  1122. function clickPlayFast() {
  1123. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1124. szInfo = "";
  1125. if (oWndInfo != null) {
  1126. WebVideoCtrl.I_PlayFast({
  1127. success: function () {
  1128. szInfo = "快放成功!";
  1129. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1130. },
  1131. error: function () {
  1132. szInfo = "快放失败!";
  1133. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1134. }
  1135. });
  1136. }
  1137. }
  1138. // OSD时间
  1139. function clickGetOSDTime() {
  1140. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1141. if (oWndInfo != null) {
  1142. var szTime = WebVideoCtrl.I_GetOSDTime({
  1143. success: function (szOSDTime) {
  1144. $("#osdtime").val(szOSDTime);
  1145. showOPInfo(oWndInfo.szDeviceIdentify + " 获取OSD时间成功!");
  1146. },
  1147. error: function () {
  1148. showOPInfo(oWndInfo.szDeviceIdentify + " 获取OSD时间失败!");
  1149. }
  1150. });
  1151. }
  1152. }
  1153. // 下载录像
  1154. var g_iDownloadID = -1;
  1155. var g_tDownloadProcess = 0;
  1156. function clickStartDownloadRecord(i) {
  1157. var szDeviceIdentify = $("#ip").val(),
  1158. szChannelID = $("#channels").val(),
  1159. szFileName = $("#downloadTd" + i).data("fileName"),
  1160. szPlaybackURI = $("#downloadTd" + i).data("playbackURI");
  1161. if (null == szDeviceIdentify) {
  1162. return;
  1163. }
  1164. g_iDownloadID = WebVideoCtrl.I_StartDownloadRecord(szDeviceIdentify, szPlaybackURI, szFileName, {
  1165. bDateDir: true //是否生成日期文件
  1166. });
  1167. if (g_iDownloadID < 0) {
  1168. var iErrorValue = WebVideoCtrl.I_GetLastError();
  1169. if (34 == iErrorValue) {
  1170. showOPInfo(szDeviceIdentify + " 已下载!");
  1171. } else if (33 == iErrorValue) {
  1172. showOPInfo(szDeviceIdentify + " 空间不足!");
  1173. } else {
  1174. showOPInfo(szDeviceIdentify + " 下载失败!");
  1175. }
  1176. } else {
  1177. $("<div id='downProcess' class='freeze'></div>").appendTo("body");
  1178. g_tDownloadProcess = setInterval("downProcess(" + i + ")", 1000);
  1179. }
  1180. }
  1181. // 下载进度
  1182. function downProcess() {
  1183. var iStatus = WebVideoCtrl.I_GetDownloadStatus(g_iDownloadID);
  1184. if (0 == iStatus) {
  1185. $("#downProcess").css({
  1186. width: $("#searchlist").width() + "px",
  1187. height: "100px",
  1188. lineHeight: "100px",
  1189. left: $("#searchdiv").offset().left + "px",
  1190. top: $("#searchdiv").offset().top + "px"
  1191. });
  1192. var iProcess = WebVideoCtrl.I_GetDownloadProgress(g_iDownloadID);
  1193. if (iProcess < 0) {
  1194. clearInterval(g_tDownloadProcess);
  1195. g_tDownloadProcess = 0;
  1196. g_iDownloadID = -1;
  1197. } else if (iProcess < 100) {
  1198. $("#downProcess").text(iProcess + "%");
  1199. } else {
  1200. $("#downProcess").text("100%");
  1201. setTimeout(function () {
  1202. $("#downProcess").remove();
  1203. }, 1000);
  1204. WebVideoCtrl.I_StopDownloadRecord(g_iDownloadID);
  1205. showOPInfo("录像下载完成!");
  1206. clearInterval(g_tDownloadProcess);
  1207. g_tDownloadProcess = 0;
  1208. g_iDownloadID = -1;
  1209. }
  1210. } else {
  1211. WebVideoCtrl.I_StopDownloadRecord(g_iDownloadID);
  1212. clearInterval(g_tDownloadProcess);
  1213. g_tDownloadProcess = 0;
  1214. g_iDownloadID = -1;
  1215. }
  1216. }
  1217. // 导出配置文件
  1218. function clickExportDeviceConfig() {
  1219. var szDeviceIdentify = $("#ip").val(),
  1220. szInfo = "";
  1221. if (null == szDeviceIdentify) {
  1222. return;
  1223. }
  1224. var iRet = WebVideoCtrl.I_ExportDeviceConfig(szDeviceIdentify);
  1225. if (0 == iRet) {
  1226. szInfo = "导出配置文件成功!";
  1227. } else {
  1228. szInfo = "导出配置文件失败!";
  1229. }
  1230. showOPInfo(szDeviceIdentify + " " + szInfo);
  1231. }
  1232. // 导入配置文件
  1233. function clickImportDeviceConfig() {
  1234. var szDeviceIdentify = $("#ip").val(),
  1235. szFileName = $("#configFile").val();
  1236. if (null == szDeviceIdentify) {
  1237. return;
  1238. }
  1239. if ("" == szFileName) {
  1240. alert("请选择配置文件!");
  1241. return;
  1242. }
  1243. var iRet = WebVideoCtrl.I_ImportDeviceConfig(szDeviceIdentify, szFileName);
  1244. if (0 == iRet) {
  1245. WebVideoCtrl.I_Restart(szDeviceIdentify, {
  1246. success: function (xmlDoc) {
  1247. $("<div id='restartDiv' class='freeze'>重启中...</div>").appendTo("body");
  1248. var oSize = getWindowSize();
  1249. $("#restartDiv").css({
  1250. width: oSize.width + "px",
  1251. height: oSize.height + "px",
  1252. lineHeight: oSize.height + "px",
  1253. left: 0,
  1254. top: 0
  1255. });
  1256. setTimeout("reconnect('" + szDeviceIdentify + "')", 20000);
  1257. },
  1258. error: function (status, xmlDoc) {
  1259. showOPInfo(szDeviceIdentify + " 重启失败!", status, xmlDoc);
  1260. }
  1261. });
  1262. } else {
  1263. showOPInfo(szDeviceIdentify + " 导入失败!");
  1264. }
  1265. }
  1266. // 重连
  1267. function reconnect(szDeviceIdentify) {
  1268. WebVideoCtrl.I_Reconnect(szDeviceIdentify, {
  1269. success: function (xmlDoc) {
  1270. $("#restartDiv").remove();
  1271. },
  1272. error: function (status, xmlDoc) {
  1273. if (401 == status) {// 无插件方案,重启后session已失效,程序执行登出,从已登录设备中删除
  1274. $("#restartDiv").remove();
  1275. clickLogout();
  1276. } else {
  1277. setTimeout(function () {reconnect(szDeviceIdentify);}, 5000);
  1278. }
  1279. }
  1280. });
  1281. }
  1282. // 开始升级
  1283. var g_tUpgrade = 0;
  1284. function clickStartUpgrade(szDeviceIdentify) {
  1285. var szDeviceIdentify = $("#ip").val(),
  1286. szFileName = $("#upgradeFile").val();
  1287. if (null == szDeviceIdentify) {
  1288. return;
  1289. }
  1290. if ("" == szFileName) {
  1291. alert("请选择升级文件!");
  1292. return;
  1293. }
  1294. var iRet = WebVideoCtrl.I_StartUpgrade(szDeviceIdentify, szFileName);
  1295. if (0 == iRet) {
  1296. g_tUpgrade = setInterval("getUpgradeStatus('" + szDeviceIdentify + "')", 1000);
  1297. } else {
  1298. showOPInfo(szDeviceIdentify + " 升级失败!");
  1299. }
  1300. }
  1301. // 获取升级状态
  1302. function getUpgradeStatus(szDeviceIdentify) {
  1303. var iStatus = WebVideoCtrl.I_UpgradeStatus();
  1304. if (iStatus == 0) {
  1305. var iProcess = WebVideoCtrl.I_UpgradeProgress();
  1306. if (iProcess < 0) {
  1307. clearInterval(g_tUpgrade);
  1308. g_tUpgrade = 0;
  1309. showOPInfo(szDeviceIdentify + " 获取进度失败!");
  1310. return;
  1311. } else if (iProcess < 100) {
  1312. if (0 == $("#restartDiv").length) {
  1313. $("<div id='restartDiv' class='freeze'></div>").appendTo("body");
  1314. var oSize = getWindowSize();
  1315. $("#restartDiv").css({
  1316. width: oSize.width + "px",
  1317. height: oSize.height + "px",
  1318. lineHeight: oSize.height + "px",
  1319. left: 0,
  1320. top: 0
  1321. });
  1322. }
  1323. $("#restartDiv").text(iProcess + "%");
  1324. } else {
  1325. WebVideoCtrl.I_StopUpgrade();
  1326. clearInterval(g_tUpgrade);
  1327. g_tUpgrade = 0;
  1328. $("#restartDiv").remove();
  1329. WebVideoCtrl.I_Restart(szDeviceIdentify, {
  1330. success: function (xmlDoc) {
  1331. $("<div id='restartDiv' class='freeze'>重启中...</div>").appendTo("body");
  1332. var oSize = getWindowSize();
  1333. $("#restartDiv").css({
  1334. width: oSize.width + "px",
  1335. height: oSize.height + "px",
  1336. lineHeight: oSize.height + "px",
  1337. left: 0,
  1338. top: 0
  1339. });
  1340. setTimeout("reconnect('" + szDeviceIdentify + "')", 20000);
  1341. },
  1342. error: function (status, xmlDoc) {
  1343. showOPInfo(szDeviceIdentify + " 重启失败!", status, xmlDoc);
  1344. }
  1345. });
  1346. }
  1347. } else if (iStatus == 1) {
  1348. WebVideoCtrl.I_StopUpgrade();
  1349. showOPInfo(szDeviceIdentify + " 升级失败!");
  1350. clearInterval(g_tUpgrade);
  1351. g_tUpgrade = 0;
  1352. } else if (iStatus == 2) {
  1353. mWebVideoCtrl.I_StopUpgrade();
  1354. showOPInfo(szDeviceIdentify + " 语言不匹配!");
  1355. clearInterval(g_tUpgrade);
  1356. g_tUpgrade = 0;
  1357. } else {
  1358. mWebVideoCtrl.I_StopUpgrade();
  1359. showOPInfo(szDeviceIdentify + " 获取状态失败!");
  1360. clearInterval(g_tUpgrade);
  1361. g_tUpgrade = 0;
  1362. }
  1363. }
  1364. // 检查插件版本
  1365. function clickCheckPluginVersion() {
  1366. var iRet = WebVideoCtrl.I_CheckPluginVersion();
  1367. if (0 == iRet) {
  1368. alert("您的插件版本已经是最新的!");
  1369. } else {
  1370. alert("检测到新的插件版本!");
  1371. }
  1372. }
  1373. // 远程配置库
  1374. function clickRemoteConfig() {
  1375. var szDeviceIdentify = $("#ip").val(),
  1376. iDevicePort = parseInt($("#deviceport").val(), 10) || "",
  1377. szInfo = "";
  1378. if (null == szDeviceIdentify) {
  1379. return;
  1380. }
  1381. var iRet = WebVideoCtrl.I_RemoteConfig(szDeviceIdentify, {
  1382. iDevicePort: iDevicePort,
  1383. iLan: 1
  1384. });
  1385. if (-1 == iRet) {
  1386. szInfo = "调用远程配置库失败!";
  1387. } else {
  1388. szInfo = "调用远程配置库成功!";
  1389. }
  1390. showOPInfo(szDeviceIdentify + " " + szInfo);
  1391. }
  1392. function clickRestoreDefault() {
  1393. var szDeviceIdentify = $("#ip").val(),
  1394. szMode = "basic";
  1395. WebVideoCtrl.I_RestoreDefault(szDeviceIdentify, szMode, {
  1396. timeout: 30000,
  1397. success: function (xmlDoc) {
  1398. $("#restartDiv").remove();
  1399. showOPInfo(szDeviceIdentify + " 恢复默认参数成功!");
  1400. //恢复完成后需要重启
  1401. WebVideoCtrl.I_Restart(szDeviceIdentify, {
  1402. success: function (xmlDoc) {
  1403. $("<div id='restartDiv' class='freeze'>重启中...</div>").appendTo("body");
  1404. var oSize = getWindowSize();
  1405. $("#restartDiv").css({
  1406. width: oSize.width + "px",
  1407. height: oSize.height + "px",
  1408. lineHeight: oSize.height + "px",
  1409. left: 0,
  1410. top: 0
  1411. });
  1412. setTimeout("reconnect('" + szDeviceIdentify + "')", 20000);
  1413. },
  1414. error: function (status, xmlDoc) {
  1415. showOPInfo(szDeviceIdentify + " 重启失败!", status, xmlDoc);
  1416. }
  1417. });
  1418. },
  1419. error: function (status, xmlDoc) {
  1420. showOPInfo(szDeviceIdentify + " 恢复默认参数失败!", status, xmlDoc);
  1421. }
  1422. });
  1423. }
  1424. function PTZZoomIn() {
  1425. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1426. if (oWndInfo != null) {
  1427. WebVideoCtrl.I_PTZControl(10, false, {
  1428. iWndIndex: g_iWndIndex,
  1429. success: function (xmlDoc) {
  1430. showOPInfo(oWndInfo.szDeviceIdentify + " 调焦+成功!");
  1431. },
  1432. error: function (status, xmlDoc) {
  1433. showOPInfo(oWndInfo.szDeviceIdentify + " 调焦+失败!", status, xmlDoc);
  1434. }
  1435. });
  1436. }
  1437. }
  1438. function PTZZoomout() {
  1439. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1440. if (oWndInfo != null) {
  1441. WebVideoCtrl.I_PTZControl(11, false, {
  1442. iWndIndex: g_iWndIndex,
  1443. success: function (xmlDoc) {
  1444. showOPInfo(oWndInfo.szDeviceIdentify + " 调焦-成功!");
  1445. },
  1446. error: function (status, xmlDoc) {
  1447. showOPInfo(oWndInfo.szDeviceIdentify + " 调焦-失败!", status, xmlDoc);
  1448. }
  1449. });
  1450. }
  1451. }
  1452. function PTZZoomStop() {
  1453. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1454. if (oWndInfo != null) {
  1455. WebVideoCtrl.I_PTZControl(11, true, {
  1456. iWndIndex: g_iWndIndex,
  1457. success: function (xmlDoc) {
  1458. showOPInfo(oWndInfo.szDeviceIdentify + " 调焦停止成功!");
  1459. },
  1460. error: function (status, xmlDoc) {
  1461. showOPInfo(oWndInfo.szDeviceIdentify + " 调焦停止失败!", status, xmlDoc);
  1462. }
  1463. });
  1464. }
  1465. }
  1466. function PTZFocusIn() {
  1467. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1468. if (oWndInfo != null) {
  1469. WebVideoCtrl.I_PTZControl(12, false, {
  1470. iWndIndex: g_iWndIndex,
  1471. success: function (xmlDoc) {
  1472. showOPInfo(oWndInfo.szDeviceIdentify + " 聚焦+成功!");
  1473. },
  1474. error: function (status, xmlDoc) {
  1475. showOPInfo(oWndInfo.szDeviceIdentify + " 聚焦+失败!", status, xmlDoc);
  1476. }
  1477. });
  1478. }
  1479. }
  1480. function PTZFoucusOut() {
  1481. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1482. if (oWndInfo != null) {
  1483. WebVideoCtrl.I_PTZControl(13, false, {
  1484. iWndIndex: g_iWndIndex,
  1485. success: function (xmlDoc) {
  1486. showOPInfo(oWndInfo.szDeviceIdentify + " 聚焦-成功!");
  1487. },
  1488. error: function (status, xmlDoc) {
  1489. showOPInfo(oWndInfo.szDeviceIdentify + " 聚焦-失败!", status, xmlDoc);
  1490. }
  1491. });
  1492. }
  1493. }
  1494. function PTZFoucusStop() {
  1495. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1496. if (oWndInfo != null) {
  1497. WebVideoCtrl.I_PTZControl(12, true, {
  1498. iWndIndex: g_iWndIndex,
  1499. success: function (xmlDoc) {
  1500. showOPInfo(oWndInfo.szDeviceIdentify + " 聚焦停止成功!");
  1501. },
  1502. error: function (status, xmlDoc) {
  1503. showOPInfo(oWndInfo.szDeviceIdentify + " 聚焦停止失败!", status, xmlDoc);
  1504. }
  1505. });
  1506. }
  1507. }
  1508. function PTZIrisIn() {
  1509. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1510. if (oWndInfo != null) {
  1511. WebVideoCtrl.I_PTZControl(14, false, {
  1512. iWndIndex: g_iWndIndex,
  1513. success: function (xmlDoc) {
  1514. showOPInfo(oWndInfo.szDeviceIdentify + " 光圈+成功!");
  1515. },
  1516. error: function (status, xmlDoc) {
  1517. showOPInfo(oWndInfo.szDeviceIdentify + " 光圈+失败!", status, xmlDoc);
  1518. }
  1519. });
  1520. }
  1521. }
  1522. function PTZIrisOut() {
  1523. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1524. if (oWndInfo != null) {
  1525. WebVideoCtrl.I_PTZControl(15, false, {
  1526. iWndIndex: g_iWndIndex,
  1527. success: function (xmlDoc) {
  1528. showOPInfo(oWndInfo.szDeviceIdentify + " 光圈-成功!");
  1529. },
  1530. error: function (status, xmlDoc) {
  1531. showOPInfo(oWndInfo.szDeviceIdentify + " 光圈-失败!", status, xmlDoc);
  1532. }
  1533. });
  1534. }
  1535. }
  1536. function PTZIrisStop() {
  1537. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1538. if (oWndInfo != null) {
  1539. WebVideoCtrl.I_PTZControl(14, true, {
  1540. iWndIndex: g_iWndIndex,
  1541. success: function (xmlDoc) {
  1542. showOPInfo(oWndInfo.szDeviceIdentify + " 光圈停止成功!");
  1543. },
  1544. error: function (status, xmlDoc) {
  1545. showOPInfo(oWndInfo.szDeviceIdentify + " 光圈停止失败!", status, xmlDoc);
  1546. }
  1547. });
  1548. }
  1549. }
  1550. // 切换模式
  1551. function changeIPMode(iType) {
  1552. var arrPort = [0, 7071, 80];
  1553. $("#serverport").val(arrPort[iType]);
  1554. }
  1555. // 获取设备IP
  1556. function clickGetDeviceIP() {
  1557. var iDeviceMode = parseInt($("#devicemode").val(), 10),
  1558. szAddress = $("#serveraddress").val(),
  1559. iPort = parseInt($("#serverport").val(), 10) || 0,
  1560. szDeviceID = $("#deviceid").val(),
  1561. szDeviceInfo = "";
  1562. szDeviceInfo = WebVideoCtrl.I_GetIPInfoByMode(iDeviceMode, szAddress, iPort, szDeviceID);
  1563. if ("" == szDeviceInfo) {
  1564. showOPInfo("设备IP和端口解析失败!");
  1565. } else {
  1566. showOPInfo("设备IP和端口解析成功!");
  1567. var arrTemp = szDeviceInfo.split("-");
  1568. $("#loginip").val(arrTemp[0]);
  1569. $("#deviceport").val(arrTemp[1]);
  1570. }
  1571. }
  1572. // 启用多边形绘制
  1573. var g_bEnableDraw = false;
  1574. function clickEnableDraw() {
  1575. var iRet = WebVideoCtrl.I_SetPlayModeType(6);// 多边形模式
  1576. if (0 === iRet) {
  1577. g_bEnableDraw = true;
  1578. showOPInfo("启用绘制成功!");
  1579. } else {
  1580. showOPInfo("启用绘制失败!");
  1581. }
  1582. }
  1583. // 禁用多边形绘制
  1584. function clickDisableDraw() {
  1585. var iRet = WebVideoCtrl.I_SetPlayModeType(0);// 预览模式
  1586. if (0 === iRet) {
  1587. g_bEnableDraw = false;
  1588. showOPInfo("禁用绘制成功!");
  1589. } else {
  1590. showOPInfo("禁用绘制失败!");
  1591. }
  1592. }
  1593. // 添加图形
  1594. function clickAddSnapPolygon() {
  1595. if (!g_bEnableDraw) {
  1596. return;
  1597. }
  1598. var szId = $("#snapId").val();
  1599. var szName = encodeString($("#snapName").val());
  1600. var szInfo = "<?xml version='1.0' encoding='utf-8'?>";
  1601. szInfo += "<SnapPolygonList>";
  1602. szInfo += "<SnapPolygon>";
  1603. szInfo += "<id>" + szId + "</id>"; // [1, 32]
  1604. szInfo += "<polygonType>1</polygonType>";
  1605. szInfo += "<PointNumMax>17</PointNumMax>"; // [MinClosed, 17]
  1606. szInfo += "<MinClosed>4</MinClosed>"; // [4, 17]
  1607. szInfo += "<tips>#" + szId + "#" + szName + "</tips>";
  1608. szInfo += "<isClosed>false</isClosed>";
  1609. szInfo += "<color><r>0</r><g>255</g><b>0</b></color>";
  1610. szInfo += "<pointList/>";
  1611. szInfo += "</SnapPolygon>";
  1612. szInfo += "</SnapPolygonList>";
  1613. var iRet = WebVideoCtrl.I_SetSnapPolygonInfo(g_iWndIndex, szInfo);
  1614. if (0 === iRet) {
  1615. showOPInfo("窗口" + g_iWndIndex + "添加图形成功!");
  1616. } else if (-1 === iRet) {
  1617. showOPInfo("窗口" + g_iWndIndex + "添加图形失败!");
  1618. } else if (-2 === iRet) {
  1619. alert("参数错误!");
  1620. } else if (-3 === iRet) {
  1621. alert("图形个数达到上限!");
  1622. } else if (-4 === iRet) {
  1623. alert("图形ID已存在!");
  1624. }
  1625. WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, 2);
  1626. }
  1627. // 删除图形
  1628. function clickDelSnapPolygon() {
  1629. if (!g_bEnableDraw) {
  1630. return;
  1631. }
  1632. var szId = $("#snapId").val();
  1633. var iIndex = getSnapPolygon(szId);
  1634. if (iIndex != -1) {
  1635. var oXML = getSnapPolygon();
  1636. $(oXML).find("SnapPolygon").eq(iIndex).remove();
  1637. var szInfo = toXMLStr(oXML);
  1638. WebVideoCtrl.I_ClearSnapInfo(g_iWndIndex);
  1639. WebVideoCtrl.I_SetSnapPolygonInfo(g_iWndIndex, szInfo);
  1640. WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, 3);
  1641. } else {
  1642. alert("图形ID不存在!");
  1643. }
  1644. }
  1645. // 编辑图形
  1646. function clickEditSnapPolygon() {
  1647. if (!g_bEnableDraw) {
  1648. return;
  1649. }
  1650. var iRet = WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, 3);
  1651. if (0 === iRet) {
  1652. showOPInfo("窗口" + g_iWndIndex + "编辑图形成功!");
  1653. } else {
  1654. showOPInfo("窗口" + g_iWndIndex + "编辑图形失败!");
  1655. }
  1656. }
  1657. // 停止编辑
  1658. function clickStopSnapPolygon() {
  1659. if (!g_bEnableDraw) {
  1660. return;
  1661. }
  1662. var iRet = WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, -1);
  1663. if (0 === iRet) {
  1664. showOPInfo("窗口" + g_iWndIndex + "停止编辑成功!");
  1665. } else {
  1666. showOPInfo("窗口" + g_iWndIndex + "停止编辑失败!");
  1667. }
  1668. }
  1669. function getSnapPolygon(szId) {
  1670. var szInfo = WebVideoCtrl.I_GetSnapPolygonInfo(g_iWndIndex);
  1671. var oXML = loadXML(szInfo);
  1672. if (typeof szId === "undefined") {
  1673. return oXML;
  1674. } else {
  1675. var iIndex = -1;
  1676. var aNodeList = $(oXML).find("SnapPolygon");
  1677. if (aNodeList.length > 0) {
  1678. $.each(aNodeList, function (i) {
  1679. if ($(this).find("id").text() === szId) {
  1680. iIndex = i;
  1681. return false;
  1682. }
  1683. });
  1684. }
  1685. return iIndex;
  1686. }
  1687. }
  1688. // 获取图形,保存到自己数据库中
  1689. function clickGetSnapPolygon() {
  1690. if (!g_bEnableDraw) {
  1691. return;
  1692. }
  1693. var szInfo = WebVideoCtrl.I_GetSnapPolygonInfo(g_iWndIndex);
  1694. alert(szInfo);
  1695. }
  1696. // 设置图形,页面打开时可以设置以前设置过的图形
  1697. function clickSetSnapPolygon() {
  1698. if (!g_bEnableDraw) {
  1699. return;
  1700. }
  1701. WebVideoCtrl.I_ClearSnapInfo(g_iWndIndex);
  1702. var szInfo = "<?xml version='1.0' encoding='utf-8'?>";
  1703. szInfo += "<SnapPolygonList>";
  1704. szInfo += "<SnapPolygon>";
  1705. szInfo += "<id>1</id>";
  1706. szInfo += "<polygonType>1</polygonType>";
  1707. szInfo += "<tips>#1#设置1</tips>";
  1708. szInfo += "<isClosed>true</isClosed>";
  1709. szInfo += "<color><r>0</r><g>255</g><b>0</b></color>";
  1710. szInfo += "<pointList>";
  1711. szInfo += "<point><x>0.737903</x><y>0.229730</y></point>";
  1712. szInfo += "<point><x>0.947581</x><y>0.804054</y></point>";
  1713. szInfo += "<point><x>0.362903</x><y>0.777027</y></point>";
  1714. szInfo += "</pointList>";
  1715. szInfo += "</SnapPolygon>";
  1716. szInfo += "<SnapPolygon>";
  1717. szInfo += "<id>2</id>";
  1718. szInfo += "<polygonType>1</polygonType>";
  1719. szInfo += "<tips>#2#设置2</tips>";
  1720. szInfo += "<isClosed>true</isClosed>";
  1721. szInfo += "<color><r>0</r><g>255</g><b>0</b></color>";
  1722. szInfo += "<pointList>";
  1723. szInfo += "<point><x>0.451613</x><y>0.216216</y></point>";
  1724. szInfo += "<point><x>0.447581</x><y>0.729730</y></point>";
  1725. szInfo += "<point><x>0.116935</x><y>0.554054</y></point>";
  1726. szInfo += "</pointList>";
  1727. szInfo += "</SnapPolygon>";
  1728. szInfo += "</SnapPolygonList>";
  1729. var iRet = WebVideoCtrl.I_SetSnapPolygonInfo(g_iWndIndex, szInfo);
  1730. if (0 === iRet) {
  1731. showOPInfo("窗口" + g_iWndIndex + "设置图形成功!");
  1732. } else if (-1 === iRet) {
  1733. showOPInfo("窗口" + g_iWndIndex + "设置图形失败!");
  1734. } else if (-2 === iRet) {
  1735. alert("参数错误!");
  1736. } else if (-3 === iRet) {
  1737. alert("图形个数达到上限!");
  1738. } else if (-4 === iRet) {
  1739. alert("图形ID已存在!");
  1740. }
  1741. }
  1742. // 清空图形
  1743. function clickDelAllSnapPolygon() {
  1744. if (!g_bEnableDraw) {
  1745. return;
  1746. }
  1747. var iRet = WebVideoCtrl.I_ClearSnapInfo(g_iWndIndex);
  1748. if (0 === iRet) {
  1749. showOPInfo("窗口" + g_iWndIndex + "清空图形成功!");
  1750. } else {
  1751. showOPInfo("窗口" + g_iWndIndex + "清空图形失败!");
  1752. }
  1753. }
  1754. // 设备抓图
  1755. function clickDeviceCapturePic() {
  1756. var szInfo = "";
  1757. var szDeviceIdentify = $("#ip").val();
  1758. var bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false;
  1759. var iChannelID = parseInt($("#channels").val(), 10);
  1760. var iResolutionWidth = parseInt($("#resolutionWidth").val(), 10);
  1761. var iResolutionHeight = parseInt($("#resolutionHeight").val(), 10);
  1762. if (null == szDeviceIdentify) {
  1763. return;
  1764. }
  1765. if (bZeroChannel) {// 零通道不支持设备抓图
  1766. return;
  1767. }
  1768. var szPicName = szDeviceIdentify + "_" + iChannelID + "_" + new Date().getTime();
  1769. var iRet = WebVideoCtrl.I_DeviceCapturePic(szDeviceIdentify, iChannelID, szPicName, {
  1770. bDateDir: true, //是否生成日期文件
  1771. iResolutionWidth: iResolutionWidth,
  1772. iResolutionHeight: iResolutionHeight
  1773. });
  1774. if (0 == iRet) {
  1775. szInfo = "设备抓图成功!";
  1776. } else {
  1777. szInfo = "设备抓图失败!";
  1778. }
  1779. showOPInfo(szDeviceIdentify + " " + szInfo);
  1780. }
  1781. function loadXML(szXml) {
  1782. if(null == szXml || "" == szXml) {
  1783. return null;
  1784. }
  1785. var oXmlDoc = null;
  1786. if (window.DOMParser) {
  1787. var oParser = new DOMParser();
  1788. oXmlDoc = oParser.parseFromString(szXml, "text/xml");
  1789. } else {
  1790. oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  1791. oXmlDoc.async = false;
  1792. oXmlDoc.loadXML(szXml);
  1793. }
  1794. return oXmlDoc;
  1795. }
  1796. function toXMLStr(oXmlDoc) {
  1797. var szXmlDoc = "";
  1798. try {
  1799. var oSerializer = new XMLSerializer();
  1800. szXmlDoc = oSerializer.serializeToString(oXmlDoc);
  1801. } catch (e) {
  1802. try {
  1803. szXmlDoc = oXmlDoc.xml;
  1804. } catch (e) {
  1805. return "";
  1806. }
  1807. }
  1808. if (szXmlDoc.indexOf("<?xml") == -1) {
  1809. szXmlDoc = "<?xml version='1.0' encoding='utf-8'?>" + szXmlDoc;
  1810. }
  1811. return szXmlDoc;
  1812. }
  1813. function encodeString(str) {
  1814. if (str) {
  1815. return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1816. } else {
  1817. return "";
  1818. }
  1819. }