demo-easy.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. $(function () {
  2. //初始化IP地址、端口、用户名、密码、宽度高度
  3. var _szIp = queryString("ip");
  4. var _szPort = queryString("port");
  5. var _szUsername = queryString("user");
  6. var _szPassword = queryString("password");
  7. var _iWidth = queryString("width") || "800";
  8. var _iHeight = queryString("height") || "600";
  9. //var _szIp = "192.168.0.10";
  10. //var _szPort = "8000";
  11. //var _szUsername = "admin";
  12. //var _szPassword = "sg85214551";
  13. //var _iWidth = "800";
  14. //var _iHeight = "600";
  15. if(!_szIp) {
  16. document.getElementById('divPlugin').innerHTML = '<img src="./image/nullVideo.png" style="position: absolute;left: 50%;top: 50%;transform: translate(-50%, -50%);"/>'
  17. return
  18. }
  19. // 检查插件是否已经安装过
  20. var iRet = WebVideoCtrl.I_CheckPluginInstall();
  21. //视频无法预览时判断
  22. if (-2 == iRet) {
  23. $("#divPlugin").html("<div style='background-color:black;color:white;width:" + _iWidth + "px;height:" + _iHeight + "px;text-align:center;line-height:" + _iHeight + "px'>请在IE浏览器中进行视频预览!</div>");
  24. return;
  25. } else if (-1 == iRet) {
  26. $("#divPlugin").html("<div style='background-color:black;color:white;width:" + _iWidth + "px;height:" + _iHeight + "px;text-align:center;line-height:" + _iHeight + "px'>您还未安装过插件,双击开发包目录里的WebComponentsKit.exe安装!</div>");
  27. return;
  28. }
  29. var oPlugin = {
  30. iWidth: _iWidth, // plugin width
  31. iHeight: _iHeight // plugin height
  32. };
  33. // 初始化插件参数及插入插件
  34. WebVideoCtrl.I_InitPlugin(oPlugin.iWidth, oPlugin.iHeight, {
  35. bWndFull: true,//是否支持单窗口双击全屏,默认支持 true:支持 false:不支持
  36. iWndowType: 1,
  37. cbSelWnd: function (xmlDoc) {
  38. }
  39. });
  40. WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
  41. // 检查插件是否最新
  42. if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
  43. alert("检测到新的插件版本,双击开发包目录里的WebComponentsKit.exe升级!");
  44. return;
  45. }
  46. var oLiveView = {
  47. iProtocol: 1, // protocol 1:http, 2:https
  48. szIP: _szIp, // protocol ip
  49. szPort: _szPort, // protocol port
  50. szUsername: _szUsername, // device username
  51. szPassword: _szPassword, // device password
  52. iStreamType: 1, // stream 1:main stream 2:sub-stream 3:third stream 4:transcode stream
  53. iChannelID: 1, // channel no
  54. bZeroChannel: false // zero channel
  55. };
  56. // 登录设备
  57. var iRet = WebVideoCtrl.I_Login(oLiveView.szIP, oLiveView.iProtocol, oLiveView.szPort, oLiveView.szUsername, oLiveView.szPassword, {
  58. success: function (xmlDoc) {
  59. // 开始预览
  60. WebVideoCtrl.I_StartRealPlay(oLiveView.szIP, {
  61. iStreamType: oLiveView.iStreamType,
  62. iChannelID: oLiveView.iChannelID,
  63. bZeroChannel: oLiveView.bZeroChannel
  64. });
  65. },
  66. error: function () {
  67. $("#divPlugin").html("<div style='background-color:black;color:white;width:" + _iWidth + "px;height:" + _iHeight + "px;text-align:center;line-height:" + _iHeight+"px'>" + oLiveView.szIP + " 登录失败!</div>");
  68. }
  69. });
  70. // 关闭浏览器
  71. $(window).unload(function () {
  72. WebVideoCtrl.I_Stop();
  73. });
  74. });
  75. function queryString(val) {
  76. var uri = window.location.search;
  77. var re = new RegExp("" + val + "\=([^\&\?]*)", "ig");
  78. return ((uri.match(re)) ? decodeURIComponent((uri.match(re)[0].substr(val.length + 1))) : null);
  79. }