海康威视视频web demo

点击下载资源

首先要引用js

 <script src="~/js/HIKCamera/Codebase/webVideoCtrl.js" asp-append-version="true"></script>

开发的页面是用c#写的,页面写得比较low,就随便看看
在这里插入图片描述
js脚本(里面是我有些阉割的了,可以根据需求更改对应的参数,还有Ie10以下的获取不到iframe对应的参数,所以自己网上找了个方法获取到类似data-ip这样的方法)

  var g_aIframe = $("iframe");
        $(function () {
            var iRet = WebVideoCtrl.I_CheckPluginInstall();
            if (-1 == iRet) {
                alert("您还未安装过插件,请点击下载控件安装WebComponentsKit.exe!");
                return;
            }
            $(window).on("load", function () {
                $.each(g_aIframe, function (i, oIframe) {
                    getWebVideoCtrl(oIframe).I_Stop();
                });
            });
        });
        function getWebVideoCtrl(oIframe) {
            return oIframe.contentWindow.WebVideoCtrl;
        }
        function iframeLoaded() {
            $.each(g_aIframe, function (i, oIframe) {
                var data = getDataset(oIframe);
                var oWebVideoCtrl = getWebVideoCtrl(oIframe);
                oWebVideoCtrl.I_Login(data.ip, 1, data.port, data.username, data.pwd, {
                    success: function (xmlDoc) {
                        setTimeout(function () {
                            oWebVideoCtrl.I_StartRealPlay(data.ip, {
                                iStreamType: 2,
                                iChannelID: 1,
                                bZeroChannel: false
                            });
                        }, 2000);
                   
                    }
                });
            });
        }
           function getDataset(ele) {
            if (ele.dataset) {
                return ele.dataset;
            } else {
                var attrs = ele.attributes,//元素的属性集合
                    dataset = {}, name, matchStr;
                for (var i = 0; i < attrs.length; i++) { //是否是data- 开头
                    matchStr = attrs[i].name.match(/^data-(.+)/);
                    if (matchStr) { //data-auto-play 转成驼峰写法 autoPlay
                        name = matchStr[1].replace(/-([\da-z])/gi, function (all, letter) {
                            return letter.toUpperCase();
                        });
                        dataset[name] = attrs[i].value;
                    }
                }
                return dataset;
            }
        }

这是嵌入的iframe显示的页面,可以根据需求自己调整大小
在这里插入图片描述

    <script src="~/js/HIKCamera/jquery-1.7.1.min.js" asp-append-version="true"></script>
    <script src="~/js/HIKCamera/Codebase/webVideoCtrl.js" asp-append-version="true"></script>
    <script>
        $(function () {
            var oPlugin = {
                iWidth: 300,            // plugin width
                iHeight: 200            // plugin height
            };
            WebVideoCtrl.I_InitPlugin(oPlugin.iWidth, oPlugin.iHeight, {
                bWndFull: true,
                iWndowType: 1,
                cbInitPluginComplete: function () {
                    WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
                }
            });
        });
    </script>

要注意的几点是:Ip/端口/账号/密码这些要设置好,如果有关联硬盘录像机保存录像的话,通道也要设置好,查看回放的话,关联的是硬盘录像机的Ip账号这些+通道

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值