videoPlay.vue 4.86 KB
<template>
  <div class="ocx-box" id="ocx-box" v-show="isShow">
    <object
      id="VionVideo"
      classid="clsid:93F960BB-5AF9-402B-A3DF-06112F14DC02"
      codebase="VionPlatformVideo.ocx"
      width="100%"
      height="100%"
    >
      <!-- <param name="_Version" value="65536">
		        <param name="_ExtentX" value="2646">
		        <param name="_ExtentY" value="1323">
		        <param name="_StockProps" value="0"> -->
    </object>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      urlFlag: false,
      isShow: true
    };
  },
  props: ["playurl", "type"],
  methods: {
    videoPlay: function() {
      this.urlFlag = false;
      console.log(this.playurl);
      if (!this.playurl.sip_serv_ip) {
        let url = this.playurl.rtsp_url;
        try {
          let isLoadingOcx =
            typeof document.getElementById("VionVideo").GetVersion() ===
            "string"
              ? true
              : false;
          if (isLoadingOcx) {
            let ocxPlayRes = document
              .getElementById("VionVideo")
              .StartPlay(url, 0);
            console.log("视频流:", url);
            if (ocxPlayRes != 0) {
              alert("播放失败!");
            }
          } else {
            this.installOcxInfo();
          }
        } catch (error) {
          console.log(error);
        }
      } else {
        debugger
        let OcxResponse = document
          .getElementById("VionVideo")
          .StartPlaySip(
            this.playurl.sip_serv_id,
            this.playurl.sip_serv_ip,
            this.playurl.sip_serv_port,
            this.playurl.sip_dev_id,
            this.playurl.sip_password,
            this.playurl.devId,
            0
          );
        console.log("video Ocx播放sip流返回值:", OcxResponse);
        if (OcxResponse != 0 && OcxResponse != 200) {
          alert("播放失败!");
        }
      }
    },
    downOcx: function() {
      if (this.fileUrl !== "" && !this.installOcx) {
        location.href = this.fileUrl;
      }
    },
    installOcxInfo: function() {
      this.$confirm("为了正常使用,是否安装OCX控件?", "友情提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.installOcx = false;
          this.downloadOCx();
        })
        .catch(() => {
          this.installOcxInfo();
        });
    },
    initocx() {
      VionVideo.Init(0, "Null", 4);
    },
    downloadOCx() {
      if (navigator.userAgent.indexOf("Trident") > -1) {
        let params = {
          file_type: "video_ocx"
        };
        this.$api.ops.downloadOcx(params).then(response => {
          if (response.ecode) {
            this.$message({
              type: "error",
              message: response.enode
            });
          } else {
            location.href = response.file_url;
          }
        });
      } else {
        this.$message.error("视频控件加载失败请用IE10及以上版本打开!");
      }
    },
    checkIEversion() {
      var agent = navigator.userAgent.toLowerCase();
      if (
        /(msie\s|trident.*rv:)([\w.]+)/.test(agent) &&
        document.documentMode < 10
      ) {
        this.$message.error("IE 版本过低请升级到IE10级以上版本!");
      }
    },
    /**IE
     * 检查浏览器
     */
    checkIE() {
      var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
      var isIE =
        userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
      var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
      var isIE11 =
        userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;
      if (isIE || isEdge || isIE11) {
        return true;
      } else {
        return false;
      }
    }
  },
  created() {},
  computed: {
    ...mapState(["ocxstate"])
  },
  watch: {
    ocxstate(val) {
      try {
        if (val == 0) {
          this.isShow = false;
          document.getElementById("VionVideo").StartPlay(1);
        } else {
          this.isShow = true;
          document.getElementById("VionVideo").StartPlay(0);
        }
      } catch (error) {
        console.log(error);
      }
    }
  },
  mounted() {
    if (this.checkIE()) {
      try {
        let isLoadingOcx =
          typeof document.getElementById("VionVideo").GetVersion() === "string"
            ? true
            : false;
        if (!isLoadingOcx) {
          this.installOcxInfo();
        }
      } catch (error) {
        this.downloadOCx();
      }
    }
  },
  beforeDestroy: function() {
    // if (this.videoplayer.techName_ == "Flash" && this.videoplayer.pause) {
    //   this.videoplayer.pause();
    // }
  }
};
</script>

<style lang="stylus" scoped>
.ocx-box{
  height 100%
  width 100%
}
</style>