zhangzengfei
2022-03-23 e19dcbcf017744b1fceb0b29f423aab9c2786e6f
修改wasm player 播放按钮
3个文件已修改
754 ■■■■■ 已修改文件
src/components/wasmPlayer/index.vue 340 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/wasmPlayer/wasm/player.js 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/cameraVideo/index/Video.vue 333 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/wasmPlayer/index.vue
@@ -1,85 +1,50 @@
<template>
  <div class="video-player">
    <canvas
      v-show="showArea"
      id="area-canvas"
      ref="areaCanvas"
      width="960"
      height="540"
    ></canvas>
    <canvas v-show="showArea" id="area-canvas" ref="areaCanvas" width="960" height="540"></canvas>
    <div class="container" id="videoPlayer">
      <div class="canvasDiv">
        <div
          v-loading="videoLoading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
          style="position: unset !important"
        ></div>
          <canvas
          ref="playCanvas"
          id="paly-canvas"
          width="960"
          height="540"
        ></canvas>
        ></div>
        <canvas ref="playCanvas" id="paly-canvas" width="960" height="540"></canvas>
      </div>
       <transition name="fade">
       <div class="popuptext" id="myPopup" v-if="fullScreenNotice">资源下载中,请稍后...</div>
       </transition>
      <transition name="fade">
        <div class="popuptext" id="myPopup" v-if="fullScreenNotice">资源下载中,请稍后...</div>
      </transition>
      <!-- 控制条 -->
      <section
        class="jsmodern-video-panel"
        :style="{ display: isStream ? 'none' : 'block' }"
      >
      <section class="jsmodern-video-panel" :style="{ display: isStream ? 'none' : 'block' }">
        <!-- 播放/暂停 -->
        <b
          :class="
            playerStatus == 0 ? 'jsmodern-video-play' : 'jsmodern-video-pause'
          "
          @click="playVideo"
        ></b>
        <b :class="playerStatus == 0 ? 'jsmodern-video-play' : 'jsmodern-video-pause'" @click="playVideo"></b>
        <!-- 时间 -->
        <span class="jsmodern-video-start" ref="timeLabel"
          >00:00:00/00:00:00</span
        >
        <span class="jsmodern-video-start" ref="timeLabel">00:00:00/00:00:00</span>
        <!-- 进度条 -->
        <div>
          <input
            class="jsmodern-video-linebox"
            ref="timeTrack"
            type="range"
            value="0"
          />
          <input class="jsmodern-video-linebox" ref="timeTrack" type="range" value="0" />
        </div>
        <!-- 声音 -->
        <b class="jsmodern-video-volume"></b>
        <!-- <b class="jsmodern-video-volume"></b> -->
        <!-- <div class="jsmodern-video-volumebox">
          <div class="jsmodern-video-volumeline"></div>
          <b class="jsmodern-video-volumedot"></b>
        </div> -->
        <!-- 全屏 -->
        <b
          class="jsmodern-video-fullin"
          @click="fullScreen"
          :disable="false"
        ></b>
        <b class="jsmodern-video-fullin" @click="fullScreen" :disable="false"></b>
        <!-- 下载 -->
        <i
         class="el-icon-download jsmodern-video-download"
         @click="downLoad"
        ></i>
        <i class="el-icon-download jsmodern-video-download" @click="downLoad" v-show="!isStream"></i>
      </section>
      <!-- 大播放按钮 -->
      <div v-show="!isStream">
        <span class="video-btn" v-show="playerStatus == 0" @click="playVideo"
          ><img src="./wasm/img/bo1.png"
        /></span>
        <span class="video-btn" v-show="playerStatus == 0" @click="playVideo"><img src="./wasm/img/bo1.png"/></span>
        <!-- 上一个 -->
        <span class="video-prve" v-show="showPrev">
@@ -106,68 +71,65 @@
/*
  2021.09.22 添加多个录像地址的处理, 与录像模块约定, 用 || 分割多个视频地址, 前端处理播放.
*/
import { Player } from './wasm/player'
import VideoRuleData from '@/Pool/VideoRuleData'
import { getAllPolygon } from '@/api/polygon'
import { Player } from "./wasm/player"
import VideoRuleData from "@/Pool/VideoRuleData"
import { getAllPolygon } from "@/api/polygon"
export default {
  name: 'CameraPlayer',
  name: "CameraPlayer",
  props: {
    videoUrl: {
      type: String,
      // default: "ws://192.168.1.182:10101/ws"
      default: `${location.protocol === 'https' ? 'wss' : 'ws'}://${
        location.host
      }/ws`,
      default: `${location.protocol === "https" ? "wss" : "ws"}://${location.host}/ws`
    },
    cameraName: {
      type: String,
      default: '',
      default: ""
    },
    cameraID: {
      type: String,
      default: 'C4668FD0-3CAE-C31F-C21E-28B7001243C4',
      default: "C4668FD0-3CAE-C31F-C21E-28B7001243C4"
    },
    rtspUrl: {
      type: String,
      default:
        'rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream',
      default: "rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream"
    },
    isRunning: {
      type: Boolean,
      default: false,
      default: false
    },
    isGb: {
      type: Boolean,
      default: false,
      default: false
    },
    showArea: {
      type: Boolean,
      default: false,
      default: false
    },
    isStream: {
      type: Boolean,
      default: true,
      default: true
    },
    autoPlay: {
      type: Boolean,
      default: false,
      default: false
    },
    preload: {
      type: Boolean,
      default: true,
    },
      default: true
    }
  },
  computed: {
    poster() {
      return '/images/player/player_poster.gif?t=' + Math.random()
      return "/images/player/player_poster.gif?t=" + Math.random()
    },
    showPrev() {
      return this.playerIndex - 1 >= 0
    },
    showNext() {
      return this.playerIndex + 1 < this.videoUrls.length
    },
    }
  },
  data() {
    return {
@@ -179,7 +141,7 @@
        line: [],
        rect: [], // {id:'uuid', name: '矩形1', location: [{ x: 20, y: 30 }, { x: 20, y: 60 }, { x: 100, y: 60 }, { x: 100, y: 30 }] }
        arrow: [],
        polygon: [],
        polygon: []
      },
      //showProportion: 3.2,
      //showProportionY: 3.58,
@@ -197,9 +159,9 @@
      playerIndex: 0,
      isEmptyUrl: false,
      videoLoading: false,
      loadUrl:'',
      isFullScreen:false,
      fullScreenNotice:false
      loadUrl: "",
      isFullScreen: false,
      fullScreenNotice: false
    }
  },
  watch: {
@@ -213,7 +175,7 @@
          this.playVideo()
        })
      }
    },
    }
  },
  mounted() {
    this.player = new Player()
@@ -224,18 +186,18 @@
      this.playVideo()
      this.$nextTick(() => {
        this.canvas = this.$refs.areaCanvas
        this.ctx = this.canvas.getContext('2d')
        this.ctx = this.canvas.getContext("2d")
        this.ctx.lineWidth = 1
        this.initArea()
      })
    } else {
      // 录像URL处理, 可能存在多个录像地址
      if (this.videoUrl === '') {
      if (this.videoUrl === "") {
        this.playerStatus = -1
        return
      }
      this.videoUrls = this.videoUrl.split('||')
      this.videoUrls = this.videoUrl.split("||")
      if (this.autoPlay || this.preload) {
        this.playVideo()
@@ -252,47 +214,26 @@
      this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
      let _this = this // 集合中遍历需要将this转存一下使用
      _this.canvasData.line.forEach(function(v, i) {
        _this.ctx.strokeStyle = 'yellow'
        _this.ctx.strokeStyle = "yellow"
        _this.ctx.beginPath()
        _this.ctx.moveTo(
          v.location[0].x / _this.showProportion,
          v.location[0].y / _this.showProportion
        )
        _this.ctx.lineTo(
          v.location[1].x / _this.showProportion,
          v.location[1].y / _this.showProportion
        )
        _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion)
        _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion)
        _this.ctx.stroke()
        _this.canvas.style.cursor = 'default'
        _this.canvas.style.cursor = "default"
      })
      _this.canvasData.rect.forEach(function(v, i) {
        _this.ctx.strokeStyle = 'yellow'
        _this.ctx.strokeStyle = "yellow"
        _this.ctx.beginPath()
        _this.ctx.moveTo(
          v.location[0].x / _this.showProportion,
          v.location[0].y / _this.showProportion
        )
        _this.ctx.lineTo(
          v.location[1].x / _this.showProportion,
          v.location[1].y / _this.showProportion
        )
        _this.ctx.lineTo(
          v.location[2].x / _this.showProportion,
          v.location[2].y / _this.showProportion
        )
        _this.ctx.lineTo(
          v.location[3].x / _this.showProportion,
          v.location[3].y / _this.showProportion
        )
        _this.ctx.lineTo(
          v.location[0].x / _this.showProportion,
          v.location[0].y / _this.showProportion
        )
        _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion)
        _this.ctx.lineTo(v.location[1].x / _this.showProportion, v.location[1].y / _this.showProportion)
        _this.ctx.lineTo(v.location[2].x / _this.showProportion, v.location[2].y / _this.showProportion)
        _this.ctx.lineTo(v.location[3].x / _this.showProportion, v.location[3].y / _this.showProportion)
        _this.ctx.lineTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportion)
        _this.ctx.stroke()
        _this.canvas.style.cursor = 'default'
        _this.canvas.style.cursor = "default"
      })
      _this.canvasData.arrow.forEach(function(v, i) {
        _this.ctx.strokeStyle = 'yellow'
        _this.ctx.strokeStyle = "yellow"
        _this.drawArrow(
          _this.ctx,
          v.location[0].x / _this.showProportion,
@@ -301,44 +242,28 @@
          v.location[1].y / _this.showProportion,
          20,
          30,
          'yellow'
          "yellow"
        )
        _this.canvas.style.cursor = 'default'
        _this.canvas.style.cursor = "default"
      })
      _this.canvasData.polygon.forEach(function(v, i) {
        if (v.location.length === 0) {
          return
        }
        _this.ctx.strokeStyle = 'yellow'
        _this.ctx.strokeStyle = "yellow"
        _this.ctx.beginPath()
        _this.ctx.moveTo(
          v.location[0].x / _this.showProportion,
          v.location[0].y / _this.showProportionY
        )
        _this.ctx.moveTo(v.location[0].x / _this.showProportion, v.location[0].y / _this.showProportionY)
        for (let i = 1; i < v.location.length; i++) {
          _this.ctx.lineTo(
            v.location[i].x / _this.showProportion,
            v.location[i].y / _this.showProportionY
          )
          _this.ctx.lineTo(v.location[i].x / _this.showProportion, v.location[i].y / _this.showProportionY)
        }
        _this.ctx.closePath()
        _this.ctx.stroke()
        _this.canvas.style.cursor = 'default'
        _this.canvas.style.cursor = "default"
      })
    },
    // 箭头绘制函数
    drawArrow(
      ctx,
      fromX,
      fromY,
      toX,
      toY,
      theta = 30,
      headlen = 10,
      width = 1,
      color = 'yellow'
    ) {
    drawArrow(ctx, fromX, fromY, toX, toY, theta = 30, headlen = 10, width = 1, color = "yellow") {
      // ctx:Canvas绘图环境
      // fromX, fromY:起点坐标(也可以换成p1,只不过它是一个数组)
      // toX, toY:终点坐标 (也可以换成p2,只不过它是一个数组)
@@ -382,10 +307,10 @@
    // 回显图形备注
    showRemarks(x, y, remarks) {
      this.ctx.moveTo(x, y - 10) // 因为放大之后是y-20,所以缩小版的为y-10
      this.ctx.fillStyle = 'green' // 设置填充颜色为绿色
      this.ctx.fillStyle = "green" // 设置填充颜色为绿色
      this.ctx.font = '10px "微软雅黑"' // 设置字体
      this.ctx.textBaseline = 'bottom' // 设置字体底线对齐绘制基线
      this.ctx.textAlign = 'left' // 设置字体对齐的方式
      this.ctx.textBaseline = "bottom" // 设置字体底线对齐绘制基线
      this.ctx.textAlign = "left" // 设置字体对齐的方式
      this.ctx.fillText(remarks, x, y - 10) // 填充文字
    },
    getCanvasData(data) {
@@ -399,7 +324,6 @@
    setWidthHeight() {
      this.canvasWidth = this.$refs.videoPlayer.offsetWidth
      this.canvasHeight = this.$refs.videoPlayer.offsetHeight
      console.log(this.canvasWidth, this.canvasHeight)
    },
    async initArea() {
      if (!this.showCanvas) {
@@ -407,7 +331,7 @@
      }
      const res = await getAllPolygon({
        cameraId: this.TreeDataPool.selectedNode.id,
        cameraId: this.TreeDataPool.selectedNode.id
      })
      this.canvasData.line = res.data.line
      this.canvasData.rect = res.data.rect
@@ -416,15 +340,15 @@
      this.clickSelect(this.canvasData)
    },
    initAlgoDataWebScoket() {
      if (typeof WebSocket === 'undefined') {
        console.log('error,您的浏览器不支持socket')
      if (typeof WebSocket === "undefined") {
        console.log("error,您的浏览器不支持socket")
      } else {
        this.algoDataSocket = new WebSocket()
        this.algoDataSocket.onopen = () => {
          console.log('socket连接成功')
          console.log("socket连接成功")
        }
        this.algoDataSocket.onerror = () => {
          console.log('连接错误')
          console.log("连接错误")
        }
        this.algoDataSocket.onmessage = (msg) => {
          console.log(msg)
@@ -432,14 +356,14 @@
      }
    },
    playVideo() {
      if (this.isStream && this.rtspUrl == '') {
      if (this.isStream && this.rtspUrl == "") {
        return
      }
      let payload = ''
      let url = ''
      let payload = ""
      let url = ""
      if (this.isStream) {
        if (this.cameraID == '') {
        if (this.cameraID == "") {
          this.cameraID = this.getUuid()
        }
@@ -447,12 +371,12 @@
          cameraID: this.cameraID,
          rtspUrl: this.rtspUrl,
          isRunning: this.isRunning,
          isGb28181: this.isGb,
          isGb28181: this.isGb
        })
        url = this.videoUrl
      } else {
        url = '/httpImage/' + this.videoUrls[this.playerIndex]
        url = "/httpImage/" + this.videoUrls[this.playerIndex]
      }
      this.videoLoading = true
@@ -482,7 +406,7 @@
    },
    setPlayerStatus(stat) {
      this.videoLoading = false
      this.playerStatus = stat
      this.playerStatus = 1
    },
    stopVideo() {
      if (this.player.hPlayer == 0) return
@@ -491,54 +415,54 @@
    },
    fullScreen() {
      if(!this.isFullScreen){
       this.player.fullscreen()
      }
      else{
      this.player.exitfullscreen()
      if (!this.isFullScreen) {
        this.player.fullscreen()
      } else {
        this.player.exitfullscreen()
      }
      this.isFullScreen = !this.isFullScreen
    },
    async downLoad() {
      if (!this.loadUrl) {
      this.$notify.info({
          title: '消息',
          message:'下载失败,无效的视频地址'
        });
        this.$notify.info({
          title: "消息",
          message: "下载失败,无效的视频地址"
        })
        return
      }
      if (this.isFullScreen) {
       /* const screen = this.player.webglPlayer.canvas.parentNode
        /* const screen = this.player.webglPlayer.canvas.parentNode
       var p = document.createElement("p");
         var txt = document.createTextNode("资源下载中,请稍后...");
         p.appendChild(txt);
       p.classList.add("downloadNotice");
         screen.appendChild(p); */
       this.fullScreenNotice = true
          setTimeout(()=>{this.fullScreenNotice = false},2000);}
       else {
         this.$notify.info({
          title: '消息',
          message:`资源下载中,请稍后...`
        });
       }
        this.fullScreenNotice = true
        setTimeout(() => {
          this.fullScreenNotice = false
        }, 2000)
      } else {
        this.$notify.info({
          title: "消息",
          message: `资源下载中,请稍后...`
        })
      }
      let url = 'http://'+window.location.host+this.loadUrl
      let url = "http://" + window.location.host + this.loadUrl
     // let url = "http://localhost:8080/httpImage/192.168.20.189:6700/283,2f49bf283ad7?collection=2021-09-28-DSVAD010120190703-video"
      let name = url.substring(url.lastIndexOf("/") + 1)
      // let url = "http://localhost:8080/httpImage/192.168.20.189:6700/283,2f49bf283ad7?collection=2021-09-28-DSVAD010120190703-video"
      let name = url.substring(url.lastIndexOf("/") + 1)
      let responsePromise = await fetch(url)
      let blob = await responsePromise.blob()
      let objectURL = window.URL.createObjectURL(blob)
      let a = document.createElement('a')
      let a = document.createElement("a")
      a.href = objectURL
      a.download = name
      a.click()
      a.remove()
   /*  let url = 'http:/'+this.loadUrl.substring(10)
      /*  let url = 'http:/'+this.loadUrl.substring(10)
    let link = document.createElement("a"); //创建a标签
    let name = url.substring(url.lastIndexOf("/") + 1) 
    link.style.display = "none"; //使其隐藏
@@ -546,7 +470,6 @@
    link.setAttribute("download", name); //设置下载属性 以及文件名
    document.body.appendChild(link); //a标签插至页面中
    link.click(); //强制触发a标签事件 */
    },
    playPrev() {
@@ -559,8 +482,8 @@
      this.playerIndex++
      this.player.stop()
      this.playVideo()
    },
  },
    }
  }
}
</script>
@@ -617,9 +540,9 @@
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
    width: 460px;
    width: -webkit-calc(100% - 260px);
    width: -moz-calc(100% - 260px);
    width: calc(100% - 260px);
    width: -webkit-calc(100% - 215px);
    width: -moz-calc(100% - 215px);
    width: calc(100% - 215px);
    float: left;
    margin: 19px 0 0 65px;
    position: relative;
@@ -771,7 +694,6 @@
    margin-top: 7px;
    margin-left: -12px;
  }
}
.video-player:hover {
@@ -825,34 +747,34 @@
  background-color: pink;
}
 .popuptext {
    /* display:none; */
    height: 50px;
    line-height: 50px;
    font-size: 20px;
    background-color: #555;
    opacity: .8;
    color: #fff;
    text-align: center;
    border-radius: 25px;
    position: relative;
    top: 30px;
    z-index: 1;
.popuptext {
  /* display:none; */
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  background-color: #555;
  opacity: 0.8;
  color: #fff;
  text-align: center;
  border-radius: 25px;
  position: relative;
  top: 30px;
  z-index: 1;
}
    .fade-enter{
            opacity: 0;
        }
        .fade-enter-active{
            transition: opacity .5s;
        }
        .fade-leave-to{
            opacity: 0;
        }
        .fade-leave-active{
            transition: opacity 3s;
    }
 .canvasDiv .el-loading-mask {
   z-index: 1000 !important;
 }
.fade-enter {
  opacity: 0;
}
.fade-enter-active {
  transition: opacity 0.5s;
}
.fade-leave-to {
  opacity: 0;
}
.fade-leave-active {
  transition: opacity 3s;
}
.canvasDiv .el-loading-mask {
  z-index: 1000 !important;
}
</style>
src/components/wasmPlayer/wasm/player.js
@@ -1,5 +1,5 @@
import { PCMPlayer } from './pcm-player'
import { WebGLPlayer } from './webgl'
import { PCMPlayer } from "./pcm-player"
import { WebGLPlayer } from "./webgl"
export function Player() {
  this.hPlayer = 0
@@ -10,7 +10,7 @@
  this.timeLabel = null
  this.timeTrack = null
  this.CurPos = 0
  this.displayDuration = '00:00:00'
  this.displayDuration = "00:00:00"
  this.pcmPlayer = null
  this.webglPlayer = null
@@ -24,14 +24,7 @@
  }
}
Player.prototype.play = function(
  url,
  canvas,
  isStream,
  timeTrack,
  timeLabel,
  payload
) {
Player.prototype.play = function(url, canvas, isStream, timeTrack, timeLabel, payload) {
  if (this.hPlayer != 0) return
  this.MediaName = url
@@ -48,50 +41,48 @@
    This.seek(This.timeTrack.value)
  }
  this.TurboWorker = new Worker('/libs/wasmPlayer/turbo.js')
  this.TurboWorker = new Worker("/libs/wasmPlayer/turbo.js")
  this.hPlayer = 1
  this.PlayOrPause = 1
  this.TurboWorker.onmessage = function(evt) {
    switch (evt.data.command) {
      case 'initialized': {
      case "initialized": {
        This.TurboWorker.postMessage({
          command: 'play',
          command: "play",
          media_name: url,
          other: isStream,
          payload: payload,
          payload: payload
        })
        break
      }
      case 'create_video': {
      case "create_video": {
        This.VideoParam = evt.data.param //{duration:xxx,width:xxx,height:xxx}
        This.webglPlayer = new WebGLPlayer(This.canvas)
        if (This.timeTrack) {
          This.timeTrack.min = 0
          This.timeTrack.max = This.VideoParam.duration
          This.timeTrack.value = 0
          This.displayDuration = This.formatTime(
            This.VideoParam.duration / 1000
          )
          This.displayDuration = This.formatTime(This.VideoParam.duration / 1000)
        }
        This.startTrackTimer()
        This.statusCallback(0)
        break
      }
      case 'create_audio': {
      case "create_audio": {
        This.AudioParam = evt.data.param //{channel:Channel,sample_rate:SampleRate}
        This.pcmPlayer = new PCMPlayer({
          encoding: '16bitInt',
          encoding: "16bitInt",
          channels: This.AudioParam.channel,
          sampleRate: This.AudioParam.sample_rate,
          flushingTime: 5000,
          flushingTime: 5000
        })
        This.statusCallback(1)
        break
      }
      case 'deliver_video': {
      case "deliver_video": {
        if (!This.isStream && This.preload && This.preloadFlag == 0) {
          This.preloadFlag = 1
          This.pause()
@@ -100,24 +91,20 @@
        //sample:{time_stamp:xxx,data:xxx}
        This.CurPos = evt.data.sample.time_stamp
        This.webglPlayer.renderFrame(
          evt.data.sample.buf,
          This.VideoParam.width,
          This.VideoParam.height
        )
        This.webglPlayer.renderFrame(evt.data.sample.buf, This.VideoParam.width, This.VideoParam.height)
        break
      }
      case 'deliver_audio': {
      case "deliver_audio": {
        //sample:{time_stamp:xxx,data:xxx}
        This.pcmPlayer.play(evt.data.sample.buf)
        break
      }
      case 'play_failed': {
      case "play_failed": {
        This.statusCallback(-1)
        This.stop()
        break
      }
      case 'play_end': {
      case "play_end": {
        if (This.loop) {
          This.seek(0)
        }
@@ -133,19 +120,19 @@
Player.prototype.pause = function() {
  if (this.hPlayer == 0 || this.PlayOrPause == 0) return
  this.PlayOrPause = 0
  this.TurboWorker.postMessage({ command: 'pause' })
  this.TurboWorker.postMessage({ command: "pause" })
}
Player.prototype.resume = function() {
  if (this.hPlayer == 0 || this.PlayOrPause == 1) return
  this.PlayOrPause = 1
  this.TurboWorker.postMessage({ command: 'resume' })
  this.TurboWorker.postMessage({ command: "resume" })
}
Player.prototype.stop = function() {
  if (this.hPlayer == 0) return
  this.hPlayer = 0
  this.TurboWorker.postMessage({ command: 'stop' })
  this.TurboWorker.postMessage({ command: "stop" })
  this.stopTrackTimer()
  if (this.pcmPlayer) {
    this.pcmPlayer.destroy()
@@ -156,15 +143,15 @@
Player.prototype.seek = function(ms) {
  if (this.hPlayer == 0) return
  this.TurboWorker.postMessage({ command: 'seek', pos: ms })
  this.TurboWorker.postMessage({ command: "seek", pos: ms })
  if (this.pcmPlayer != null) {
    this.pcmPlayer.destroy()
    this.pcmPlayer = new PCMPlayer({
      encoding: '16bitInt',
      encoding: "16bitInt",
      channels: this.AudioParam.channel,
      sampleRate: this.AudioParam.sample_rate,
      flushingTime: 5000,
      flushingTime: 5000
    })
  }
}
@@ -177,15 +164,12 @@
  if (this.webglPlayer) this.webglPlayer.exitfullscreen()
}
Player.prototype.startTrackTimer = function() {
  var This = this
  this.trackTimer = setInterval(function() {
    if (This.timeTrack) This.timeTrack.value = This.CurPos
    if (This.timeLabel)
      This.timeLabel.innerHTML =
        This.formatTime(This.CurPos / 1000) + '/' + This.displayDuration
    if (This.timeLabel) This.timeLabel.innerHTML = This.formatTime(This.CurPos / 1000) + "/" + This.displayDuration
  }, 500)
}
@@ -197,16 +181,9 @@
}
Player.prototype.formatTime = function(s) {
  var h =
    Math.floor(s / 3600) < 10
      ? '0' + Math.floor(s / 3600)
      : Math.floor(s / 3600)
  var m =
    Math.floor((s / 60) % 60) < 10
      ? '0' + Math.floor((s / 60) % 60)
      : Math.floor((s / 60) % 60)
  var s =
    Math.floor(s % 60) < 10 ? '0' + Math.floor(s % 60) : Math.floor(s % 60)
  var h = Math.floor(s / 3600) < 10 ? "0" + Math.floor(s / 3600) : Math.floor(s / 3600)
  var m = Math.floor((s / 60) % 60) < 10 ? "0" + Math.floor((s / 60) % 60) : Math.floor((s / 60) % 60)
  var s = Math.floor(s % 60) < 10 ? "0" + Math.floor(s % 60) : Math.floor(s % 60)
  return h + ':' + m + ':' + s
  return h + ":" + m + ":" + s
}
src/pages/cameraVideo/index/Video.vue
@@ -5,19 +5,24 @@
        <div class="monitoring-video" ref="monitorVideo">
          <div class="monitoring-video-guid">
            <span
              :class="guid === 1 ? 'iconfont icongongge1 activegongge':'iconfont icongongge1'"
              :class="guid === 1 ? 'iconfont icongongge1 activegongge' : 'iconfont icongongge1'"
              @click="setGuid(1)"
            ></span>
            <span
              :class="guid === 2 ? 'iconfont icongongge activegongge':'iconfont icongongge'"
              :class="guid === 2 ? 'iconfont icongongge activegongge' : 'iconfont icongongge'"
              @click="setGuid(2)"
            ></span>
            <span
              :class="guid === 3 ? 'iconfont icongongge2 activegongge':'iconfont icongongge2'"
              :class="guid === 3 ? 'iconfont icongongge2 activegongge' : 'iconfont icongongge2'"
              @click="setGuid(3)"
            ></span>
            <el-tooltip v-if="TreeDataPool.selectedNode.id" :content="`${showArea?'隐藏区域':'查看区域'}`" placement="bottom" popper-class="atooltip">
              <span :class="showArea?'activegongge':''" class="iconfont iconquyu" @click="toggleShowArea"></span>
            <el-tooltip
              v-if="TreeDataPool.selectedNode.id"
              :content="`${showArea ? '隐藏区域' : '查看区域'}`"
              placement="bottom"
              popper-class="atooltip"
            >
              <span :class="showArea ? 'activegongge' : ''" class="iconfont iconquyu" @click="toggleShowArea"></span>
            </el-tooltip>
            <!-- <span
              v-if="TreeDataPool.selectedNode.id"
@@ -37,10 +42,7 @@
            </el-tooltip>-->
          </div>
          <div class="fixedRatioBox">
            <div
              :class="guid === 1 ? 'video-main-box' : 'video-main-box-side'"
              v-if="visibilityState"
            >
            <div :class="guid === 1 ? 'video-main-box' : 'video-main-box-side'" v-if="visibilityState">
              <VideoItem
                v-for="(item, index) in TreeDataPool.videoArr"
                :key="index"
@@ -65,15 +67,14 @@
        <video-photo ref="photoview" @addToBase="toAdd"></video-photo>
      </div>
    </div>
  </div>
</template>
<script>
import VideoItem from "../components/VideoItem";
import VideoTask from "../components/VideoTask";
import VideoPhoto from "../components/VideoPhoto";
import { getCameraPlayList } from "@/api/trackCamera";
import VideoItem from "../components/VideoItem"
import VideoTask from "../components/VideoTask"
import VideoPhoto from "../components/VideoPhoto"
import { getCameraPlayList } from "@/api/trackCamera"
export default {
  name: "Video",
@@ -82,7 +83,7 @@
    VideoTask,
    VideoPhoto
  },
  data () {
  data() {
    return {
      guid: 1,
      center: "",
@@ -94,74 +95,62 @@
      tracePubUrl: `${location.protocol === "https" ? "wss" : "ws"}://${location.host}/track`,
      websocket: null,
      visibilityState: true,
      showArea: false,
    };
      showArea: false
    }
  },
  created () {
    console.log("befor created")
    // this.TreeDataPool.clean();
    // this.TreeDataPool.fetchTreeData();
    // this.guid = sessionStorage.guid ? Number(sessionStorage.guid) : this.guid;
  created() {
    this.TreeDataPool.activeVideoIndex = sessionStorage.activeIndex
      ? Number(sessionStorage.activeIndex)
      : this.TreeDataPool.activeVideoIndex;
    this.getActiveIndex();
    this.TreeDataPool.readonly = true;
    this.TreeDataPool.gbReadonly = true;
    this.TreeDataPool.multiple = false;
    console.log("created")
      : this.TreeDataPool.activeVideoIndex
    this.getActiveIndex()
    this.TreeDataPool.readonly = true
    this.TreeDataPool.gbReadonly = true
    this.TreeDataPool.multiple = false
  },
  mounted () {
    document.addEventListener("visibilitychange", this.visibilitychange, false);
  mounted() {
    document.addEventListener("visibilitychange", this.visibilitychange, false)
    this.$nextTick(() => {
      window.addEventListener("resize", this.resizeMonitorTask);
      window.addEventListener("resize", this.resizeMonitorTask)
      //this.getRightWidth();
      this.resizeMonitorTask();
      this.resizeMonitorTask()
    })
    this.getCenter();
    this.blackAngWhite();
    this.VideoPhotoData.queryTagList();
    let list = this.TreeDataPool.localVedioList.filter(i => {
      return i.progress == 100;
    })
    // console.log(list, '已完成的本地视频', this.TreeDataPool.localVedioList)
    this.TreeDataPool.localVedioList = list;
    this.getCenter()
    this.blackAngWhite()
    this.VideoPhotoData.queryTagList()
  },
  beforeDestroy () {
    window.removeEventListener("resize", this.getRightWidth);
    this.CardList.details = [];
    window.clearInterval(this.trackTimer);
  beforeDestroy() {
    window.removeEventListener("resize", this.getRightWidth)
    this.CardList.details = []
    window.clearInterval(this.trackTimer)
    if (this.websocket) {
      this.websocket.close();
      this.websocket.close()
    }
  },
  watch: {
    "TreeDataPool.videoArr": function (newArry) {
      console.log('newArry', newArry)
      const cameras = this.filterNodes(newArry);
      this.getActiveIndex();
      this.$refs.taskview.showTasks(cameras);
      this.$refs.photoview.showCapture(cameras);
    "TreeDataPool.videoArr": function(newArry) {
      console.log("newArry", newArry)
      const cameras = this.filterNodes(newArry)
      this.getActiveIndex()
      this.$refs.taskview.showTasks(cameras)
      this.$refs.photoview.showCapture(cameras)
    },
    "VideoPhotoData.selectBlacks": function (value) {
      this.blackAngWhite();
    "VideoPhotoData.selectBlacks": function(value) {
      this.blackAngWhite()
    },
    "VideoPhotoData.selectWhites": function (value) {
      this.blackAngWhite();
    "VideoPhotoData.selectWhites": function(value) {
      this.blackAngWhite()
    },
    "TreeDataPool.showTreeBox" (value) {
      this.getRightWidth();
    "TreeDataPool.showTreeBox"(value) {
      this.getRightWidth()
    }
  },
  methods: {
    handleTrack () {
      this.track = !this.track;
    handleTrack() {
      this.track = !this.track
      if (!this.track) {
        window.clearInterval(this.trackTimer);
        this.websocket.close();
        return;
        window.clearInterval(this.trackTimer)
        this.websocket.close()
        return
      }
      this.$notify({
@@ -175,16 +164,16 @@
      if (!useWebSocket) {
        this.trackTimer = window.setInterval(() => {
          _this.tracking()
        }, 5 * 1000);
        }, 5 * 1000)
      } else {
        this.initTrackWebsocket()
        this.trackTimer = window.setInterval(() => {
          _this.videoItemMonitor()
        }, 1 * 1000);
        }, 1 * 1000)
      }
    },
    videoItemMonitor () {
      this.websocket.send("ping");
    videoItemMonitor() {
      this.websocket.send("ping")
      let cache = this.traceCache
      // 遍历当期播放的摄像机, 按秒递减摄像机人员存在时间,为0时删除,摄像机人员为空时关闭
@@ -196,18 +185,17 @@
          for (var person in cache[camera]) {
            cache[camera][person]--
            if (cache[camera][person] < 0) {
              delete (cache[camera][person])
              delete cache[camera][person]
            }
          }
        } else {
          delete (cache[camera])
          delete cache[camera]
          this.closePlayer(camera)
        }
      }
    },
    initTrackWebsocket () {
      if (typeof (WebSocket) === "undefined") {
    initTrackWebsocket() {
      if (typeof WebSocket === "undefined") {
        alert("您的浏览器不支持socket")
      } else {
        // 实例化socket
@@ -217,21 +205,21 @@
        this.websocket.onmessage = this.recvieTrackMessage
      }
    },
    websocketonopen () { //连接建立之后执行send方法发送数据
    websocketonopen() {
      //连接建立之后执行send方法发送数据
      this.websocket.send("sub")
    },
    tracking () {
      getCameraPlayList().then(data => {
    tracking() {
      getCameraPlayList().then((data) => {
        if (data && data.length) {
          data.forEach(ins => {
          data.forEach((ins) => {
            let newCamera = this.TreeDataPool.getCameraInfoById(ins.NewCameraId)
            if (!newCamera) {
              console.log("未查找到摄像机:", ins.NewCameraId);
              console.log("未查找到摄像机:", ins.NewCameraId)
              return
            }
            if (ins.IsNew) {
              this.newPlayerInViewBox(newCamera)
            } else {
              this.replacePlayer(newCamera, ins.OldCameraId)
            }
@@ -239,7 +227,7 @@
        }
      })
    },
    recvieTrackMessage (e) {
    recvieTrackMessage(e) {
      let dataJson = JSON.parse(e.data)
      let cache = this.traceCache
      let camera = dataJson.camera
@@ -265,12 +253,12 @@
          // 找到上一个摄像机, 判断摄像机里是否还有其他人, 有:新开播放器 没有:切换
          console.log("last camera:", cam, Object.keys(cache[cam]).length)
          if (Object.keys(cache[cam]).length > 2) {
            delete (cache[cam][person])
            delete cache[cam][person]
            this.newPlayerInViewBox(camera)
            return
          } else {
            this.replacePlayer(camera, cam)
            delete (cache[cam])
            delete cache[cam]
            return
          }
        }
@@ -279,19 +267,16 @@
      // 未发现播放记录
      this.newPlayerInViewBox(camera)
    },
    newPlayerInViewBox (id) {
    newPlayerInViewBox(id) {
      // 新增播放窗口
      let camera = this.TreeDataPool.getCameraInfoById(id)
      let emptyIndex = -1;
      let exist = false;
      let emptyIndex = -1
      let exist = false
      for (let i = 0; i < this.TreeDataPool.videoArr.length; i++) {
        // eslint-disable-next-line
        if (
          this.TreeDataPool.videoArr[i] === "" ||
          this.TreeDataPool.videoArr[i] === undefined
        ) {
        if (this.TreeDataPool.videoArr[i] === "" || this.TreeDataPool.videoArr[i] === undefined) {
          if (emptyIndex === -1) {
            emptyIndex = i;
            emptyIndex = i
          }
        } else {
          if (this.TreeDataPool.videoArr[i].id === camera.id) {
@@ -300,10 +285,10 @@
        }
      }
      if (!exist && emptyIndex !== -1) {
        this.TreeDataPool.setVideoArr(emptyIndex, camera, this);
        this.TreeDataPool.setVideoArr(emptyIndex, camera, this)
      }
    },
    replacePlayer (id, oldCameraId) {
    replacePlayer(id, oldCameraId) {
      let camera = this.TreeDataPool.getCameraInfoById(id)
      // console.log("update:", camera.name)
      // 替换播放器
@@ -312,9 +297,10 @@
        if (
          this.TreeDataPool.videoArr[i] &&
          this.TreeDataPool.videoArr[i] !== undefined &&
          this.TreeDataPool.videoArr[i] !== "") {
          this.TreeDataPool.videoArr[i] !== ""
        ) {
          if (this.TreeDataPool.videoArr[i].id === oldCameraId) {
            this.TreeDataPool.setVideoArr(i, camera, this);
            this.TreeDataPool.setVideoArr(i, camera, this)
            return true
          }
        }
@@ -322,102 +308,103 @@
      return false
    },
    closePlayer (id) {
    closePlayer(id) {
      for (let i = 0; i < this.TreeDataPool.videoArr.length; i++) {
        // eslint-disable-next-line
        if (
          this.TreeDataPool.videoArr[i] &&
          this.TreeDataPool.videoArr[i] !== undefined &&
          this.TreeDataPool.videoArr[i] !== "") {
          this.TreeDataPool.videoArr[i] !== ""
        ) {
          if (this.TreeDataPool.videoArr[i].id === id) {
            this.TreeDataPool.setVideoArr(i, undefined, this);
            this.TreeDataPool.setVideoArr(i, undefined, this)
            return true
          }
        }
      }
    },
    visibilitychange () {
    visibilitychange() {
      switch (document.visibilityState) {
        case "hidden":
          this.visibilityState = false;
          break;
          this.visibilityState = false
          break
        case "visible":
          this.visibilityState = true;
          break;
          this.visibilityState = true
          break
      }
    },
    blackAngWhite () {
    blackAngWhite() {
      if (this.VideoPhotoData.selectBlacks.length > 0) {
        for (let i = 0; i < this.VideoPhotoData.whiteList.length; i++) {
          //this.VideoPhotoData.whiteList[i].disabled = true
          this.$set(this.VideoPhotoData.whiteList[i], 'disabled', true)
          this.$set(this.VideoPhotoData.whiteList[i], "disabled", true)
        }
      }
      if (this.VideoPhotoData.selectBlacks.length == 0) {
        for (let i = 0; i < this.VideoPhotoData.whiteList.length; i++) {
          //this.VideoPhotoData.whiteList[i].disabled = false
          this.$set(this.VideoPhotoData.whiteList[i], 'disabled', false)
          this.$set(this.VideoPhotoData.whiteList[i], "disabled", false)
        }
      }
      if (this.VideoPhotoData.selectWhites.length > 0) {
        for (let i = 0; i < this.VideoPhotoData.blackList.length; i++) {
          // this.VideoPhotoData.blackList[i].disabled = true
          this.$set(this.VideoPhotoData.blackList[i], 'disabled', true)
          // this.VideoPhotoData.blackList[i].disabled = true
          this.$set(this.VideoPhotoData.blackList[i], "disabled", true)
        }
      }
      if (this.VideoPhotoData.selectWhites.length == 0) {
        for (let i = 0; i < this.VideoPhotoData.blackList.length; i++) {
          //this.VideoPhotoData.blackList[i].disabled = false
          this.$set(this.VideoPhotoData.blackList[i], 'disabled', false)
          //this.VideoPhotoData.blackList[i].disabled = false
          this.$set(this.VideoPhotoData.blackList[i], "disabled", false)
        }
      }
    },
    closeWindow (index) {
      this.CardList.addBaseList.splice(index, 1);
    closeWindow(index) {
      this.CardList.addBaseList.splice(index, 1)
    },
    getVideoHeight () {
      let h = this.$refs.monitorVideo.offsetHeight;
      this.$refs.monitorTask.style.height = h + 'px';
    getVideoHeight() {
      let h = this.$refs.monitorVideo.offsetHeight
      this.$refs.monitorTask.style.height = h + "px"
    },
    resizeMonitorTask () {
      this.getRightWidth();
      this.getVideoHeight();
    resizeMonitorTask() {
      this.getRightWidth()
      this.getVideoHeight()
    },
    getRightWidth () {
      let w = this.$refs.videoRight.offsetWidth;
    getRightWidth() {
      let w = this.$refs.videoRight.offsetWidth
      // console.log("w是:", w,this.$refs.monitorVideo.offsetWidth);
      this.$refs.monitorTask.style.width = (w - this.$refs.monitorVideo.offsetWidth - 40) + 'px'
      this.$refs.monitorTask.style.width = w - this.$refs.monitorVideo.offsetWidth - 40 + "px"
      // console.log("右侧任务的宽度:", this.$refs.monitorTask.style.width)
    },
    filterNodes (selectArry) {
      let nodes = [];
      selectArry.forEach(i => {
    filterNodes(selectArry) {
      let nodes = []
      selectArry.forEach((i) => {
        if (i && nodes.indexOf(i.id) < 0) {
          nodes.push(i.id);
          nodes.push(i.id)
        }
      });
      return nodes;
      })
      return nodes
    },
    videoItemClick (index) {
      this.TreeDataPool.activeVideoIndex = index;
      this.TreeDataPool.activeForceChoose = true;
    videoItemClick(index) {
      this.TreeDataPool.activeVideoIndex = index
      this.TreeDataPool.activeForceChoose = true
    },
    toAdd (item) {
    toAdd(item) {
      this.CardList.addBaseList.push(item)
    },
    getCenter () {
    getCenter() {
      this.center = {
        x: document.documentElement.clientWidth / 2 - 250,
        y: document.documentElement.clientHeight / 2 - 200
      };
      }
    },
    resizeWidth (w) {
      this.defaultWidth = w;
    resizeWidth(w) {
      this.defaultWidth = w
    },
    resizeHeight (h) {
      this.defaultHeight = h;
    resizeHeight(h) {
      this.defaultHeight = h
    },
    saveAddBase (item, index) {
    saveAddBase(item, index) {
      if (this.VideoPhotoData.selectBlacks.length === 0 && this.VideoPhotoData.selectWhites.length === 0) {
        this.$notify({
          title: "注意",
@@ -427,7 +414,7 @@
        return
      }
      let res = this.VideoPhotoData.addBase(item)
      res.then(data => {
      res.then((data) => {
        console.log("then", data)
        if (data.success) {
          this.$notify({
@@ -442,77 +429,65 @@
            type: "error"
          })
        }
        this.CardList.addBaseList.splice(index, 1);
        this.CardList.addBaseList.splice(index, 1)
        this.VideoPhotoData.selectBlacks = []
        this.VideoPhotoData.selectWhites = []
      })
    },
    getActiveIndex () {
      this.TreeDataPool.videoArr.length = Math.pow(this.guid, 2);
      let nullVideoIndex = "";
    getActiveIndex() {
      this.TreeDataPool.videoArr.length = Math.pow(this.guid, 2)
      let nullVideoIndex = ""
      for (let i = 0; i < this.TreeDataPool.videoArr.length; i++) {
        // eslint-disable-next-line
        if (
          this.TreeDataPool.videoArr[i] === "" ||
          this.TreeDataPool.videoArr[i] === undefined
        ) {
          nullVideoIndex = i;
        if (this.TreeDataPool.videoArr[i] === "" || this.TreeDataPool.videoArr[i] === undefined) {
          nullVideoIndex = i
        } else {
          nullVideoIndex = "";
          nullVideoIndex = ""
        }
      }
      if (
        this.TreeDataPool.activeVideoIndex !== "" &&
        this.TreeDataPool.activeVideoIndex <
        this.TreeDataPool.videoArr.length - 1
        this.TreeDataPool.activeVideoIndex < this.TreeDataPool.videoArr.length - 1
      ) {
        return this.TreeDataPool.activeVideoIndex;
        return this.TreeDataPool.activeVideoIndex
      } else {
        if (nullVideoIndex === "") {
          this.TreeDataPool.activeVideoIndex =
            this.TreeDataPool.videoArr.length - 1;
          this.TreeDataPool.activeVideoIndex = this.TreeDataPool.videoArr.length - 1
        } else {
          this.TreeDataPool.activeVideoIndex = nullVideoIndex;
          this.TreeDataPool.activeVideoIndex = nullVideoIndex
        }
      }
    },
    setGuid (value) {
      clearTimeout(this.trackTimer);
    setGuid(value) {
      clearTimeout(this.trackTimer)
      if (value < this.guid && this.TreeDataPool.activeVideoIndex > value) {
        // eslint-disable-next-line
        for (
          let i = this.TreeDataPool.activeVideoIndex - 1;
          i < this.TreeDataPool.videoArr.length;
          i++
        ) {
        for (let i = this.TreeDataPool.activeVideoIndex - 1; i < this.TreeDataPool.videoArr.length; i++) {
          // eslint-disable-next-line
          if (
            this.TreeDataPool.videoArr[i] &&
            this.TreeDataPool.videoArr[i]["isPlaying"]
          ) {
            this.TreeDataPool.videoArr[i]["isPlaying"] = false;
          if (this.TreeDataPool.videoArr[i] && this.TreeDataPool.videoArr[i]["isPlaying"]) {
            this.TreeDataPool.videoArr[i]["isPlaying"] = false
          }
        }
      }
      this.guid = value;
      sessionStorage.guid = this.guid;
      sessionStorage.activeIndex = this.TreeDataPool.activeVideoIndex;
      this.getActiveIndex();
      this.guid = value
      sessionStorage.guid = this.guid
      sessionStorage.activeIndex = this.TreeDataPool.activeVideoIndex
      this.getActiveIndex()
    },
    toggleShowArea () {
      this.showArea = !this.showArea;
    toggleShowArea() {
      this.showArea = !this.showArea
    }
  },
  destroyed () {
    window.removeEventListener("resize", this.getRightWidth);
    this.CardList.details = [];
    this.CardList.addBaseList = [];
    this.VideoPhotoData.selectBlacks = [];
    this.VideoPhotoData.selectWhites = [];
  destroyed() {
    window.removeEventListener("resize", this.getRightWidth)
    this.CardList.details = []
    this.CardList.addBaseList = []
    this.VideoPhotoData.selectBlacks = []
    this.VideoPhotoData.selectWhites = []
    //this.TreeDataPool.treeActiveName = "camera";
  }
};
}
</script>
<style lang="scss">