vue3结合海康WEB开发包,开发web在线预览视频

news2024/9/23 17:20:49

我们这里选择V3.3版本
在这里插入图片描述
文档地址:https://open.hikvision.com/download/5cda567cf47ae80dd41a54b3?type=20&id=4c945d18fa5f49638ce517ec32e24e24

解压过后,会有三个文件夹
在这里插入图片描述
在docs中,点开Demo使用说明,按照流程先测试下,你的摄像头能不能调通
在这里插入图片描述
能够调通之后,我们再去正式在我们项目中进行开发。

步骤一:项目html文件中引入js依赖

我是将js依赖放到了public中
在这里插入图片描述
html中引入
在这里插入图片描述

步骤二:安装HCWebSDKPlugin.exe程序

在这里插入图片描述

步骤三:新建vue组件,将下面代码放进去,修改IP、用户名和密码

<template>
    <div class="hkv">
        <!-- 选择摄像头 -->
        <div>
            <p>选择摄像头</p>
            <el-select v-model="data.currentChannelID " @change="channelChange"  placeholder="Select" style="width: 240px">
                <el-option v-for="item in channelData" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
        </div>

        <div id="divPlugin" class="plugin"
            :style="[{ width: props.wid ? props.wid + 'px' : '250px' }, { height: props.height ? props.height + 'px' : '100%' }]">
        </div>
        <div v-if="data.img">
            <img :src="data.img" style="width: 300px; height: 250px;" />
        </div>

    </div>
</template>
<script setup lang="ts">
import { ElMessage, MessageParamsWithType } from "element-plus";
import { onMounted,onUnmounted, reactive, ref } from "vue";
let g_iWndIndex = 0;
onMounted(() => {
    init()
});
let props: any = defineProps({// 传值
    wid: Number,
    height: Number
})
const data = reactive({// 摄像头数据
    ip: "192.168.1.114", //你的ip
    port: "80",
    userName: "", //账号
    password: "", //密码
    img: "",
    currentChannelID:1,// 当前播放通道
});
let channelData:any = reactive([// 通道数据
    // {
    //     id:'',
    //     name:'',
    //     online:''
    // }
])

// 初始化插件参数及插入插件
const init = () => {
    WebVideoCtrl.I_InitPlugin({
        bWndFull: true, //是否支持单窗口双击全屏,默认支持 true:支持 false:不支持
        iWndowType: 1,
        cbSelWnd: function (xmlDoc: any) {
            g_iWndIndex = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
        },
        cbDoubleClickWnd: function () { },
        cbEvent: (iEventType: number, iParam1: string) => {
            if (2 == iEventType) {
                // 回放正常结束
                console.log("窗口" + iParam1 + "回放结束!");
            } else if (-1 == iEventType) {
                console.log("设备" + iParam1 + "网络错误!");
            }
        },
        cbInitPluginComplete: function () {
            WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin").then(
                () => {
                    // 检查插件是否最新
                    WebVideoCtrl.I_CheckPluginVersion().then((bFlag: any) => {
                        if (bFlag) {
                            alert(
                                "检测到新的插件版本,双击开发包目录里的HCWebSDKPlugin.exe升级!"
                            );
                        } else {
                            console.log("初始化成功");
                            setTimeout(() => {
                                login()// 登录
                            }, 10)
                        }
                    });
                },
                () => {
                    alert(
                        "插件初始化失败,请确认是否已安装插件;如果未安装,请双击开发包目录里的HCWebSDKPlugin.exe安装!"
                    );
                }
            );
        },
    });
};
// 抓图
const capturePicData = (type: any) => {
    var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
    if (oWndInfo != null) {
        WebVideoCtrl.I_CapturePicData().then(
            (res: string) => {
                data.img = "data:image/jpeg;base64," + res;
                ElMessage.success("抓图成功");
            },
            function () { }
        );
    }
};
// 销毁插件
const destroyPlugin = () => {
    WebVideoCtrl.I_Logout(`${data.ip}_${data.port}`).then(
        () => {
            console.log("退出成功");
            WebVideoCtrl.I_DestroyPlugin();
        },
        () => {
            console.log("退出失败!");
        }
    );
};

//  登录
const login = () => {
    WebVideoCtrl.I_Login(data.ip, 1, data.port, data.userName, data.password, {
        timeout: 3000,
        success: function (xmlDoc: any) {
            getDevicePort(`${data.ip}_${data.port}`); //获取端口
        },
        error: function (error: any) {
            console.log(error);
        },
    });
};

// 获取端口
const getDevicePort = (szDeviceIdentify: string) => {
    if (!szDeviceIdentify) {
        return;
    }
    WebVideoCtrl.I_GetDevicePort(szDeviceIdentify).then(
        (oPort: any) => {
            console.log("登录成功", oPort);
            setTimeout(() => {
                getdigitalChannel()
            }, 10);
        },
        (oError: { errorMsg: MessageParamsWithType }) => {
            ElMessage.error(oError.errorMsg);
        }
    );
};
// 开始预览
const startRealPlay = () => {
    var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
    var startRealPlay = function () {
        WebVideoCtrl.I_StartRealPlay(`${data.ip}_${data.port}`, {
            iStreamType: 1,
            iChannelID: data.currentChannelID, //播放通道
            bZeroChannel: false,
            success: function () {
                console.log(" 开始预览成功!");
            },
            error: function (oError: { errorMsg: any }) {
                console.log(" 开始预览失败!", oError.errorMsg);
            },
        });
    };

    if (oWndInfo != null) {
        // 已经在播放了,先停止
        WebVideoCtrl.I_Stop({
            success: () => {
                startRealPlay();
            },
        });
    } else {
        startRealPlay();
    }
};
//  格式化时间
const dateFormat = (
    oDate: {
        getMonth: () => number;
        getDate: () => any;
        getHours: () => any;
        getMinutes: () => any;
        getSeconds: () => any;
        getMilliseconds: () => any;
        getFullYear: () => string;
    },
    fmt: string
) => {
    var o = {
        "M+": oDate.getMonth() + 1, //月份
        "d+": oDate.getDate(), //日
        "h+": oDate.getHours(), //小时
        "m+": oDate.getMinutes(), //分
        "s+": oDate.getSeconds(), //秒
        "q+": Math.floor((oDate.getMonth() + 3) / 3), //季度
        S: oDate.getMilliseconds(), //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(
            RegExp.$1,
            (oDate.getFullYear() + "").substr(4 - RegExp.$1.length)
        );
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(
                RegExp.$1,
                RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
            );
        }
    }
    return fmt;
};

// 获取数字通道
const getdigitalChannel = () => {
    let szDeviceIdentify = data.ip + "_" + data.port;
    // 数字通道
    WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
        success: function (xmlDoc: any) {
            var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
            let oChannelsdata = []
            $.each(oChannels, function (i: number) {
                var id = $(this).find("id").eq(0).text(),
                    name = $(this).find("name").eq(0).text(),
                    online = $(this).find("online").eq(0).text();
                if ("false" == online) {// 过滤禁用的数字通道
                    return true;
                }
                if ("" == name) {
                    name = "IPCamera " + (i < 9 ? "0" + (i + 1) : (i + 1));
                }
                oChannelsdata.push({
                    id,
                    name,
                    online
                })
                //   oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
            });
            channelData = oChannelsdata
            data.currentChannelID = oChannelsdata[0].id
            startRealPlay();// 开始预览
            //   showOPInfo(szDeviceIdentify + " 获取数字通道成功!");
        },
        error: function (oError: any) {
            console.log("获取数字通道失败", oError);
        },
    });
};

const channelChange = ()=>{
    startRealPlay()// 重新预览
}

onUnmounted(() => {
    destroyPlugin()// 销毁
})

</script>
<style lang="less" scoped>
.hkv {
    display: flex;
    justify-content: center;
}
</style>

最后启动,就可以得到一个最为简单的视频预览

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2038649.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

赋能基层,融合创新:EasyCVR视频汇聚平台构建平安城市视频共享系统

一、雪亮工程建设的意义 雪亮工程的核心在于通过高清视频监控、环境监测和智能预警等先进技术手段&#xff0c;构建一个高效、智能、安全、便捷的社会安全防控体系。这一工程的建设不仅代表了现代化科技手段在城市治安管理中的应用&#xff0c;更是提升社会安全保障能力、推动…

树形结构查找(B树、B+树)

平衡树结构的树高为 O(logn) &#xff0c;平衡树结构包括两种平衡二叉树结构&#xff08;分别为 AVL 树和 RBT&#xff09;以及一种树结构&#xff08;B-Tree&#xff0c;又称 B 树&#xff0c;它的度大于 2 &#xff09;。AVL 树和 RBT 适合内部存储的应用&#xff0c;而 B 树…

CompreFace Study

系列文章目录 第一章 CompreFace Installation 第二章 Face verification POC 文章目录 系列文章目录前言一、What is the ComreFace&#xff1f;二、How to install the CompreFace? 1.On Linux for CompreFace 1.2.02.Troubleshooting总结 前言 此文旨在记录学习CompreF…

萤石取流播放失败自助排障及常见错误码解决方案

一、在使用播放地址播放时遇到播放失败的情况&#xff0c;可使用排障工具排查具体原因&#xff0c;以下具体介绍排障工具的使用方法 1、在浏览器里打开排障工具&#xff0c;地址&#xff1a;萤石开放平台-提供持续稳定的以音视频为主的全场景、多功能综合性服务 2、在第一行输入…

安全无忧!Windows7全补丁旗舰版:集成所有补丁!

今日&#xff0c;系统之家小编给大家分享集成所有补丁的Windows7旗舰版系统&#xff0c;集成至2023.12所有官方补丁&#xff0c;修复了系统高危漏洞&#xff0c;让大家时刻都能舒心地展开操作。系统基于微软 Windows 7 2009 SP1 旗舰版进行离线制作&#xff0c;全新升级的优化方…

本地环境VMware使用代理解决 Docker 镜像拉取问题

引言 本文将分享我在 Windows 10 环境下&#xff0c;通过 VMware 运行的 CentOS 7.8 虚拟机中配置 Docker 代理&#xff0c;成功解决了镜像拉取问题的经验。 问题描述 在尝试启动一个依赖 Docker 的 GitHub 项目时&#xff0c;拉取 Docker 镜像的失败。尝试配置了几个国内源…

(附源码)基于springboot的智慧社区管理系统-计算机毕设 06797

基于springboot的智慧社区管理系统 摘 要 SpringBoot智慧社区管理系统是一款基于SpringBoot框架开发的智能化社区管理软件&#xff0c;致力于提升社区管理效率和服务质量。该系统涵盖了社区入住管理、物业费管理、公共设施预约等功能&#xff0c;支持在线报修、信息发布、社区活…

Java语言程序设计——篇十三(2)

&#x1f33f;&#x1f33f;&#x1f33f;跟随博主脚步&#xff0c;从这里开始→博主主页&#x1f33f;&#x1f33f;&#x1f33f; 欢迎大家&#xff1a;这里是我的学习笔记、总结知识的地方&#xff0c;喜欢的话请三连&#xff0c;有问题可以私信&#x1f333;&#x1f333;&…

【运维】报错Resource averaged_perceptron_tagger_eng not found.

文章目录 报错信息解决报错信息 able of handling various complex tasks. Please report the progress of this project to the team members.> ========================<

回溯算法探索篇Ⅲ

Leetcode93——复原IP地址 题目描述&#xff1a; 有效 IP 地址 正好由四个整数&#xff08;每个整数位于 0 到 255 之间组成&#xff0c;且不能含有前导 0&#xff09;&#xff0c;整数之间用 . 分隔。 例如&#xff1a;"0.1.2.201" 和 "192.168.1.1" 是…

PyTorch — 初学者教程

一、说明 在本文中,我将编译 PyTorch 的初学者教程。本教程大量使用了官方 PyTorch 教程中的材料。

Java SE--IO流

一.File类型 如果我们想在程序中操作或者描述一个文件夹或文件&#xff0c;可以使用File类型 File类型在java.io包下 File可以新建&#xff0c;删除&#xff0c;移动&#xff0c;修改&#xff0c;重命名文件夹&#xff0c;也可以对文件或者文件夹的属性进行访问&#xff1b;…

嵌入式软件--模电基础 DAY 2

强电和弱电&#xff0c;简单一点是以电死人为标准的&#xff0c;交流电36伏特以下&#xff0c;直流电24V以下&#xff0c;为安全电压&#xff0c;是为弱电&#xff0c;反则强电。 市电进入家庭&#xff0c;连接你的电脑&#xff0c;220V的电压为什么没有让你感到危险&#xff…

【TiDB】09-修改tidb客户端访问密码

目录 1、修改配置文件 2、停止tidb-server 3、以root方式启动脚本 4、修改密码 5、停止脚本重启服务 1、修改配置文件 进入tidb-server默认部署位置 #切换tidb账号 su tidb# 进入tidb-server部署路径 cd /tidb-deploy/tidb-4000# 修改配置 vim ./conf/tidb.toml添加内容…

Nginx之我不会的

安装 windows下安装 这里我们选择windows下的稳定版本 之后就是解压&#xff0c;安装到英文目录下 启动&#xff08;关闭&#xff09;命令 windows命令 启动 nginx.exe 或者 start nginx 关闭 nginx -s quit&#xff08;会有一定程序退出&#xff09; 或 nginx -s stop &…

企业低代码平台那个好用?企业低代码推荐

近些年&#xff0c;很多大型的互联网公司开始了自研低代码开发平台的尝试&#xff0c;包括阿里、腾讯、华为等等国内头部大厂。由此我们可以了解到即使是开发能力富余的互联网大厂&#xff0c;也同样需要低代码的快速响应需求能力来应对数字化时代多变的功能需求。然而&#xf…

本地phpstudy部署算命系统,用户端是H5页面,支持微信支付宝支付,支持微信支付宝登录

算命系统本地部署教程 0. 技术架构1. 启动Apache、MySQL服务2. 创建前台和后台两个网站3. Navicat连接数据库4. 登录后台是长这个样子5. 登录前台登录样子6. 代码结构是 0. 技术架构 前端&#xff1a;HTMLCSSJquery 后端&#xff1a;PHP 数据库&#xff1a;MySQL 1. 启动Ap…

C++简单实现多态案例-制作饮品

代码示例如下&#xff1a; #include<iostream> using namespace std;class AbstractDrinking { public:virtual void Soil() 0;//第一步、煮开水virtual void Brew() 0;//第二步、冲泡virtual void PourInCup() 0;//第三步、倒入杯中virtual void AddSomething() 0;…

Lab 1 实验 MapReduce

&#x1f442; 若月亮没来 (若是月亮还没来)&#xff08;若是月亮还没来&#xff09; - 王宇宙Leto/乔浚丞 - 单曲 - 网易云音乐 目录 &#x1f33c;参考代码 &#x1f419;解析 &#x1f41f;mrsequential.go &#x1f41f;mrapps/wc.go &#x1f4d5;实验--准备 &…

Linux---02---系统目录及文件基本操作命令

课程回顾 操作系统 虚拟机安装 本章重点 Linux系统目录结构 常用命令 熟练区分Linux下各层目录的作用 熟练掌握Linux的常用命令&#xff08;文件命令、时间命令等&#xff09; 一、Linux系统目录结构 1.1 目录结构 /&#xff1a; 根目录&#xff0c;一般根目录下只存放…