海康对接摄像头

1.前端 播放用ws 流,后台调用海康后台可以直接返回

2.前端参考vue项目中播放ws(Websocket协议)视频流_ws视频流如何播放-CSDN博客这个地址就行了

3.注意js引用是否正确

一定要是这个目录

4.引用js的地方

5.代码,工具类

复制代码
<template>
  <div id="player" style="width: 100%;height: 100%;"></div>
</template>

<script src="../../../../../public/js/h5player.min.js"></script>


<script>
export default {
  data() {
    return {
      player: null
    }
  },
  mounted() {
    // 例如一屏播放4个视频,写法如下
    this.initPlayer(2);
    let arr = ['ws://58.221.113.46:559/openUrl/CCuqAQ8','ws://58.221.113.46:559/openUrl/Gppck0w','ws://58.221.113.46:559/openUrl/pJXovNm','ws://58.221.113.46:559/openUrl/Kb4L9Nm'];
    arr.forEach((url, index) => {
      this.realplay(url, index);
    })
  },
  methods: {
    // 初始化
    initPlayer(num = 1) { // 设置分屏:1*1、2*2、3*3、4*4
      this.player = new JSPlugin({
        szId: 'player', // 父窗口id,需要英文字母开头 必填
        szBasePath: "js/", // 必填,与h5player.min.js的引用路径一致
        iMaxSplit: 4, // 分屏播放,默认最大分屏4*4
        openDebug: true,
        mseWorkerEnable: false,//是否开启多线程解码,分辨率大于1080P建议开启,否则可能卡顿
        bSupporDoubleClickFull: true,//是否支持双击全屏,true-双击是全屏;false-双击无响应
        oStyle: {
          borderSelect: '#343434', // 选中视频的边框颜色,默认选择第一个,颜色为#fc0
        }
      })
      this.player.JS_ArrangeWindow(num).then(
        () => { console.log(`arrangeWindow to ${num}x${num} success`) },
        e => { console.error(e) }
      )
      // 监听视频连接过程中出现的异常
      this.player.JS_SetWindowControlCallback({
        pluginErrorHandler(iWindIndex, iErrorCode, oError) {
          console.error(`监控窗口${iWindIndex}发生错误,错误码: ${iErrorCode},${oError}`);
        }
      });
    },
    // 预览
    realplay (playURL = '', index = 0) { // 设置第index(从0开始)个窗口的视频地址
      this.player.JS_SetTraceId(index, true);
      this.player.JS_Play(playURL, { playURL, mode: 0, keepDecoder: 0, token: '' }, index).then(
        () => {
          console.log('realplay success');
          this.player.JS_GetTraceId(index).then((id) => { console.log("traceid:", id) })
        },
        e => { console.error(e) }
      )
    },
  }
}
</script>
<style scoped lang="less">
/* 由于我的视频没有撑满整个容器,所以加了下面的样式,如果没遇到这种情况可以忽略。*/
// 设置2*2分屏时
/deep/#player {
  & > div, & > div > div > video {
    width: 100% !important;
    height: 100% !important;
  }
  & > div > div {
    width: 50% !important;
    height: 50% !important;
  }
}
/*
// 设置1*1分屏时
/deep/#player {
    & > div,
    & > div > div,
    & > div > div > video {
        width: 100% !important;
        height: 100% !important;
    }
}
*/
</style>

6.引用的地方

相关推荐
小蒜学长几秒前
基于Spring Boot的火灾报警系统的设计与实现(代码+数据库+LW)
java·数据库·spring boot·后端
武昌库里写JAVA2 分钟前
基于Spring Boot + Vue3的办公用品申领管理系统
java·spring boot·后端
中国lanwp3 分钟前
Spring Boot的配置文件加载顺序和规则
java·spring boot·后端
我命由我123459 分钟前
Android 开发 - 一些画板第三方库(DrawBoard、FingerPaintView、PaletteLib)
android·java·java-ee·android studio·安卓·android-studio·android runtime
知彼解己33 分钟前
深入理解 AbstractQueuedSynchronizer (AQS):Java 并发的排队管家
java·开发语言
百思可瑞教育33 分钟前
ActiveMQ、RocketMQ、RabbitMQ、Kafka 的全面对比分析
vue.js·分布式·rabbitmq·rocketmq·activemq·北京百思可瑞教育·百思可瑞教育
User_芊芊君子1 小时前
【JavaSE】复习总结
java·开发语言·python
我有一颗五叶草2 小时前
线程间通信
java·开发语言
我真的是大笨蛋6 小时前
K8S-Pod(下)
java·笔记·云原生·容器·kubernetes
碳水加碳水6 小时前
Java代码审计实战:XML外部实体注入(XXE)深度解析
java·安全·web安全·代码审计