当前位置: 首页 > news >正文

websocket接海康视频监控


index.html
<script src="/js/h5player.min.js"></script>

h5Player.vue
<template><div class="player-container" :id="props.idName"></div>
</template><script setup lang="ts">
import { ref, onMounted, watch, onBeforeUnmount, nextTick } from 'vue'
let resizeObserver: ResizeObserver | null = null
const props = defineProps({playUrl: {// 视频 URL
    type: [String, Array]},split: {type: Number,default: 1},idName: { type: String, required: true, default: 'play_window' },
})const player = ref<any | null>(null)const handleResize = () => {player.value?.JS_Resize()console.log(player.value)
}// 创建播放器实例
const createPlayer = () => {player.value = new window.JSPlugin({szId: props.idName, //需要英文字母开头,唯一性,必填szBasePath: '/js', // 必填,与h5player.min.js的引用目录一致bSupporDoubleClickFull: true, //是否支持双击全屏,默认trueiMaxSplit: 4,iCurrentSplit: props.split})// 事件回调绑定
  player.value.JS_SetWindowControlCallback({windowEventSelect: function (iWndIndex: any) {// 插件选中窗口回调console.log('windowSelect callback: ', iWndIndex)},pluginErrorHandler: function (iWndIndex: any, iErrorCode: any, oError: any) {// 插件错误回调console.log('pluginError callback: ', iWndIndex, iErrorCode, oError)},windowEventOver: function (iWndIndex: any) {// 鼠标移过回调// console.log(iWndIndex);
    },windowEventOut: function (iWndIndex: any) {// 鼠标移出回调// console.log(iWndIndex);
    },windowEventUp: function (iWndIndex: any) {// 鼠标mouseup事件回调// console.log(iWndIndex);
    },windowFullCreenChange: function (bFull: any) {// 全屏切换回调console.log('fullScreen callback: ', bFull)},firstFrameDisplay: function (iWndIndex: any, iWidth: any, iHeight: any) {// 首帧显示回调console.log('firstFrame loaded callback: ', iWndIndex, iWidth, iHeight)},performanceLack: function () {// 性能不足回调console.log('performanceLack callback: ')}})realplay(props.playUrl)
}// 视频播放
const realplay = (url: string | string[]) => {if (!url) returnif (Array.isArray(url)) {url.forEach((item, i) => {player.value.JS_Play(item,{playURL: item,mode: 0},i // 播放到第 i 个窗口
        ).then(() => console.info(`JS_Play success for window ${i}`),(err: any) => console.error(`JS_Play failed for window ${i}:`, err))})} else {const index = player.value.currentWindowIndexplayer.value.JS_Play(url,{playURL: url,mode: 0},index).then(() => console.info('JS_Play success'),(err: any) => console.error('JS_Play failed:', err))}
}const changePlayUrlForWindow = (url: string, index: number) => {player.value?.JS_Stop(index).then(() => {player.value?.JS_Play(url,{playURL: url,mode: 0},index).then(() => console.info(`Changed stream for window ${index}`),(err: any) => console.error(`Failed to change stream for window ${index}:`, err))})
}// 停止所有播放
const stopAllPlay = () => {player.value?.JS_StopRealPlayAll().then(() => {console.log('stopAllPlay success')},(e: any) => {console.error(e)})
}// 停止单个播放
const stopPlay = () => {player.value?.JS_Stop().then(() => {console.log('stop realplay success')},(e: any) => {console.error(e)})
}
watch(() => props.playUrl,(newUrl) => {if (newUrl) {realplay(newUrl)} else {stopAllPlay() // 先清空
    }}
)
defineExpose({changePlayUrlForWindow,
})
onMounted(() => {nextTick(() => {createPlayer()handleResize()const el = document.getElementById(`${props.idName}`)if (el) {resizeObserver = new ResizeObserver(() => {handleResize()})resizeObserver.observe(el)}})window.addEventListener('resize', handleResize)
})
onBeforeUnmount(() => {window.removeEventListener('resize', handleResize)resizeObserver?.disconnect()
})
</script><style scoped>
.player-container {width: 100%;height: 100%;
}
</style>
引入使用
import H5Player from '@/components/hikPlayer/h5Player.vue'
<div class="videoBox"><H5Player :playUrl="monitorList.url" />
</div>
let monitorList = ref({}) //可播放的视频对象
//start模拟
let vvdata = [{ cameraName: '东中转堆场中(北向)(热成像)', stayTime: 10, url: 'ws://10.10.160.180:559/openUrl/sv73qpi', cameraIndexCode: 'a7a3f0b8f1884fa18a47bfe5a47cc664' },{ cameraName: '西三区1号堆场北侧(云台)', stayTime: 12, url: 'ws://10.10.160.180:559/openUrl/tKA7WmY', cameraIndexCode: '7a62becad6744a5986c5ede26df7d944' },{ cameraName: '东中转堆场中(北向)(云台)', stayTime: 28, url: 'ws://10.10.160.180:559/openUrl/vaKhqbm', cameraIndexCode: '48cd7e38e9b74fbd83979fa54c772a6c' },{ cameraName: '西三区1号堆场北侧(热成像)', stayTime: 20, url: 'ws://10.10.160.180:559/openUrl/wLBNsYw', cameraIndexCode: '11720ccb5f9a4c569a856facb0fbd481' }
]
let getVideo = (code) => {for (let i = 0; i < vvdata.length; i++) {if (vvdata[i].cameraIndexCode == code) {return vvdata[i]}}
}
const res = await getVideo(currentItem.cameraIndexCode);
monitorList.value = {cameraName: currentItem.cameraName,cameraIndexCode: currentItem.cameraIndexCode,stayTime: currentItem.stayTime,url: res.url
};
//end模拟

.videoBox {width: 100%;height: 600px;border: 1px solid #a38a69;border-radius: 10px;overflow: hidden;
}

 

http://www.jsqmd.com/news/303927/

相关文章:

  • 从沟通到落地:2026年选择展厅装修公司的完整流程,展台搭建/展览设计/展览搭建/会展服务,展厅装修公司联系方式
  • 2026年市面上热门的空气处理单元工厂排行,换热器/蒸汽暖风机/柜式空调机组/工业暖风机,空气处理单元供应商哪家强
  • 2026年1月双轴撕碎机厂家权威推荐:聚焦环保装备智造新力量
  • 2026年双轴撕碎机厂家新分析报告:东宏机械聚焦环保装备智造新力量
  • 2026年烟道系统优质产品推荐榜
  • 2026最新益气健脾口服液产品top5推荐!优质企业及品牌权威榜单,贫血/气虚/女性/产后/儿童/脾虚人群专属调理方案
  • 测试镜像让Linux自启配置不再复杂
  • 高通 Wi-Fi 驱动实录:揭秘高通 QRTR 协议栈的“幕后黑手”
  • Spring中的AOP和IOC(八股文)
  • 重庆地区有哪些研究生留学中介?top10推荐,录取率高
  • 污水处理设备怎么挑?2026年这些厂家不容错过,科研院所污水处理设备/RO膜滤芯,污水处理设备实力厂家哪家好
  • 2026年休闲裤品牌推荐:多场景穿着评测,解决舒适与耐用痛点并附购买排名
  • 邦芒宝典:职场新人必备的10个高效法则
  • 一文搞懂RPC、gRPC与Protobuf:分布式通信的核心技术栈
  • MybatisPlus工具(详细教程)
  • 007 商务 item_search - 根据关键词获取商品列表接口对接全攻略:从入门到精通
  • 污泥浓度水质在线监测仪:实时掌握水体污浊状态
  • 覆盖海内外车型,佑驾创新获13亿智能驾驶大单
  • 医疗系统Vue大文件加密上传DEMO?
  • 手搓1KB深度学习与大模型:极限压缩下的智能本质探索
  • 能源化工Vue大文件插件上传DEMO?
  • 工厂质检如何提高效率减少人工?思看科技自动化3D检测系统+TrackScan解决方案推荐
  • 船舶改造没有原始图纸怎么办?思看科技TrackScan-Sharp快速测绘方案来啦!
  • Active Planning 和 Tools 如何对接业务需求
  • 2026年化妆品包材工厂推荐:针对初创与成熟品牌痛点,提供全流程服务深度评价
  • 2026成都优质铝单板厂家推荐榜
  • 2026年1月看过来,防爆箱口碑好的品牌哪家好揭晓,软启动配电柜/馈电防爆箱/固定式配电箱/昆明配电柜,防爆箱厂商找哪家
  • 学长亲荐8个AI论文写作软件,专科生搞定毕业论文不求人!
  • YOLO26优化:注意力魔改 | 通道优先卷积注意力(Channel Prior Convolutional Attention,CPCA)| 中科院 发布
  • YOLO26优化:卷积魔改 | DCNv4更快收敛、更高速度、更高性能,效果秒杀DCNv3、DCNv2等 ,助力检测