VideoView.vue 4.08 KB
Newer Older
纪泽龙's avatar
纪泽龙 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<!--
 * @Author: your name
 * @Date: 2022-01-26 22:44:02
 * @LastEditTime: 2022-01-27 10:12:46
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /test/hello-world/src/views/components/videoView.vue
-->
<template>
  <div class="box-wrapper">
    <div class="title">{{ deviceData.videoName }}</div>
    <div class="close" @click="close">
      <img src="@/assets/mapImages/closeBtn.png" alt="" />
    </div>
    <div class="box videoBox">
16
      <div id="player" ></div>
纪泽龙's avatar
纪泽龙 committed
17 18 19 20 21 22 23 24 25 26 27
    </div>
    <span slot="footer" class="dialog-footer">
      <!-- <el-button type="primary" @click="dialogVisible = false"
        >确 定
      </el-button>
      <el-button @click="dialogVisible = false">取 消</el-button> -->
    </span>
  </div>
</template>
<script>
import WasmPlayer from "@easydarwin/easywasmplayer"; //导入WasmPlayer.js
28 29 30 31
import { getPreviewURLs } from "@/api/video/artemis"
//const IS_MOVE_DEVICE = document.body.clientWidth < 992 // 是否移动设备
const IS_MOVE_DEVICE = true;
const MSE_IS_SUPPORT = !!window.MediaSource // 是否支持mse
纪泽龙's avatar
纪泽龙 committed
32 33 34 35 36
export default {
  data() {
    return {
      // dialogVisible: true,
      // AfterClose: true,
37 38 39 40 41 42 43 44
      queryParam: {
        cameraIndexCode: ""
      },
      player: null,
      videoOpenNum: -1,
      queryParam: {
        cameraIndexCode: ""
      },
纪泽龙's avatar
纪泽龙 committed
45 46 47 48
    };
  },
  watch: {},
  mounted() {
49
    this.$nextTick(() => {
50 51 52 53 54 55 56 57 58 59
      if(!window.JSPlugin){
        this.loadScript("/h5player/h5player.min.js").then(() =>{
          this.createPlayer();
        this.init()
      })

      }else{
        this.createPlayer();
        this.init()
      }
60
  });
61 62 63 64 65 66
    // setTimeout(() => {
    //   this.player = new WasmPlayer(null, "video", this.callBack, {
    //     Height: true,
    //   });
    //   this.player.play(this.deviceData.usr, 1);
    // }, 1);
纪泽龙's avatar
纪泽龙 committed
67 68 69 70 71
  },
  methods: {
    show() {
      this.dialogVisible = true;
    },
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    // handleClose() {
    //   console.log("关闭");
    //   this.player.destroy(this.deviceData.usr);
    //   // document.body.removeChild(this.$refs.videoBox.$el);
    // },
    init() {
      // 设置播放容器的宽高并监听窗口大小变化
      window.addEventListener('resize', () => {
        this.player.JS_Resize()
    })
    },
    createPlayer() {
      this.player = new window.JSPlugin({
        szId: 'player',
        szBasePath: "/h5player",
        iMaxSplit: 4,
        iCurrentSplit: IS_MOVE_DEVICE ? 1 : 2,
        openDebug: true,
        oStyle: {
          borderSelect: IS_MOVE_DEVICE ? '#000' : '#FFCC00',
        }
      })
      this.open();
    },
    open(){
      this.queryParam.cameraIndexCode = this.deviceData.resourceId;
      getPreviewURLs(this.queryParam).then(response =>{
          if(response.data.code == '0'){
            this.videoOpenNum++;
            let url = response.data.data.url;
            //let index = this.player.currentWindowIndex;
            this.player.JS_Play(url,{playURL: url, mode:"0" }, this.videoOpenNum%4).then(() => {
                console.log('realplay success')
              },
              e => { console.error(e) }
              )
            }
      });
    },
    loadScript(src){
      return new Promise(reslove =>{
        let scpritE1 = document.createElement("script");
      scpritE1.type = "text/javascript";
      scpritE1.src = src;
      scpritE1.onload = () => {
        reslove();
      }
      document.body.appendChild(scpritE1);
    })
纪泽龙's avatar
纪泽龙 committed
121 122 123
    },
    callBack() {},
    close() {
124
      //this.handleClose();
纪泽龙's avatar
纪泽龙 committed
125 126 127 128 129 130 131
      this.mapClass.infowindowClose();
    },
  },
};
</script>

<style lang="scss">
132 133 134
  .sub-wnd{
    text-align: center !important;
  }
纪泽龙's avatar
纪泽龙 committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
.box-wrapper {
  background-color: rgba(9, 18, 32, 0.6);
  position: relative;
  .title {
    padding-top: 10px;
    padding-left: 10px;
    font-size: 14px;
    line-height: 14px;
    color: #ffffff;
  }
  .close {
    position: absolute;
    right: 10px;
    top: 5px;
    cursor: pointer;
  }
  .box {
    padding: 5px 12px 10px 10px;
    width: 350px;
    height: 200px;
155 156
    #player {
      height: 190px;
纪泽龙's avatar
纪泽龙 committed
157 158 159 160 161
    }
  }
}
</style>