(vue项目)ezuikit-js萤石组件的封装

//html部分
<video
      :id="id"
      ref="fullscreen"
      poster="../../../assets/videoDemo.png"
      style="width: 100%;object-fit: cover;"
      >
/>
//js部分
<script>
import EZUIKit from 'ezuikit-js'
export default {
  name: 'HelloWorld',
  data() {
    return {
      player: null,
      // 弹窗
      Visiable: false,
      // 全屏
      isFullscreen: false,
      // 设置按钮
      themeData: {
        poster:'../../../../src/assets/videoDemo.png',
        header: {
          color: '#fff',
          activeColor: '#FFFFFF',
          backgroundColor: '#000000',
          btnList: [
            {
              iconId: 'deviceID',
              part: 'left',
              defaultActive: 0,
              memo: '顶部设备序列号',
              isrender: 1,
            },
            {
              iconId: 'deviceName',
              part: 'left',
              defaultActive: 0,
              memo: '顶部设备名称',
              isrender: 1,
            },
          ],
        },
        footer: {
          color: '#FFFFFF',
          activeColor: '#1890FF',
          backgroundColor: '#00000021',
          btnList: [
            {
              iconId: 'play',
              part: 'left',
              defaultActive: 1,
              memo: '播放',
              isrender: 1,
            },
            {
              iconId: 'capturePicture',
              part: 'left',
              defaultActive: 0,
              memo: '截屏按钮',
              isrender: 1,
            },
            {
              iconId: 'sound',
              part: 'left',
              defaultActive: 0,
              memo: '声音按钮',
              isrender: 1,
            },
            {
              iconId: "pantile",
              part: "left",
              defaultActive: 0,
              memo: "云台控制按钮",
              isrender: 1
            },
            {
              iconId: 'recordvideo',
              part: 'left',
              defaultActive: 0,
              memo: '录制按钮',
              isrender: 1,
            },
            {
              iconId: 'talk',
              part: 'left',
              defaultActive: 0,
              memo: '对讲按钮',
              isrender: 1,
            },
            {
              iconId: 'zoom',
              part: 'left',
              defaultActive: 0,
              memo: '电子放大',
              isrender: 1,
            },
            {
              iconId: 'hd',
              part: 'right',
              defaultActive: 0,
              memo: '清晰度切换按钮',
              isrender: 1,
            },
          ],
        },
      },
      widthBox: null,
      heightBox: null,
      fullUrl:'',
      token:'',
      //监控页面
      windowHeight:0,
      windowWidth:0,
      id:'',
      tokenv:'',
      channelNO:0,
      deviceSerial:'',
      buttonClick:false
    }
  },
  props: {
    ysData:{
        type: Object,
        default: () => {
        return {
          tokenv:'',
          id: "", 
          channelNO:0,
          deviceSerial:''
        };
      },
      },
    show: {
      type: Boolean,
    },
    autoplay: {
      type: Boolean,
    },
  },
  watch:{
    //获取props数据更新的时候
    ysData:{
      deep: true,
      immediate: true,
      handler(val) {
        console.log('更新ys组件的值',val)
        this.$nextTick(() => {
          let width =document.getElementsByClassName('BoxFourref')[0].offsetWidth
          let height =document.getElementsByClassName('BoxFourref')[0].offsetHeight
          this.widthBox = width
          this.heightBox = height 
          this.id=val.id
          this.tokenv=val.tokenv
          this.channelNO=val.channelNO
          this.deviceSerial=val.deviceSerial
          console.log('2更新ys组件的值',val)
          this.createVideo(val.tokenv,val.id,val.channelNO,val.deviceSerial);
        });
      },
    }, 
  },
  created() {
        console.log('获取父盒子宽高',document.getElementsByClassName('BoxFourref')[0])
        let width =document.getElementsByClassName('BoxFourref')[0].offsetWidth
        let height =document.getElementsByClassName('BoxFourref')[0].offsetHeight
        this.widthBox = width
        this.heightBox = height 
        console.log('萤石当前传的宽高创建时候',this.widthBox,this.heightBox)
        
  },
  mounted() {
    // 监控页面
    window.onresize = () => {
      return (() => {
          this.windowHeight = document.documentElement.clientHeight // 高
          this.windowWidth = document.documentElement.clientWidth // 宽
          console.log('萤石监控当前页面',this.windowHeight,this.windowWidth)
        
      })()
    }
  },
  methods: {
    // 创建视频
    createVideo(tokenv,id,channelNO,deviceSerial){
      console.log('3萤石的值',tokenv,id,channelNO,deviceSerial)
        var accessToken = tokenv
        this.token=tokenv
        var url=''
        if(deviceSerial){
          url = 'ezopen://open.ys7.com/'+deviceSerial+'/'+channelNO+'.hd.live'
          this.fullUrl='ezopen://open.ys7.com/'+deviceSerial+'/'+channelNO+'.hd.live'
        }else{
          url = ''
          this.fullUrl=''
        }
        console.log('当前萤石的创建视频的值',this.id,this.widthBox,this.heightBox)

        this.player = new EZUIKit.EZUIKitPlayer(
          // this.option
          {
            id: this.id, // 视频容器ID
            accessToken: accessToken,
            url: url,
            autoplay: true,
            // simple - 极简版; pcLive-pc直播;pcRec-pc回放;mobileLive-移动端直播;mobileRec-移动端回放;security - 安防版;voice-语音版;
            //template: 'theme',
            // poster:'../../../assets/img/蒙版组 12.png',
            plugin: ['talk'], // 加载插件,talk-对讲
            themeData: this.themeData,
            width: this.widthBox,
            height: this.heightBox,
            landleError:(data) => {
              console.log('视频播放失败',data);
            }
            // footer: ['talk','broadcast','hd',],
          }
        )
        // this.play()
        window.player = this.player
    },
    play() {
      var playPromise = player.play();
      playPromise.then((data) => {
        console.log("promise 获取 数据", data)
      })
    },
  },
  beforeDestroy() {
    if (this.player) {
      this.player.dispose
      this.timer=null
    }
    
  },
}
</script>

注意:在npm之后发现视频无法正常播放,可以将官网demo的ezuikit-js复制到自己的项目里面

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Ezuikit-js是一个基于Vue框架的摄像头调用和录像功能实现的插件。以下是一种可能的实现方式: 首先,我们需要在Vue项目中安装ezuikit-js插件。可以通过npm命令来进行安装: ``` npm install ezuikit-js ``` 然后,在Vue组件中引入和使用ezuikit-js插件: ```javascript import ezuikit from 'ezuikit-js'; export default { data() { return { player: null, isRecording: false, }; }, mounted() { this.initPlayer(); }, methods: { initPlayer() { this.player = new ezuikit.Player({ id: 'video-player', accessToken: 'your_access_token', url: 'rtsp://your_camera_url', }); this.player.initialize(); }, startRecording() { this.isRecording = true; this.player.startRecord(); }, stopRecording() { this.player.stopRecord().then((recordData) => { console.log(recordData); // 可以在控制台输出录像数据(recordData) this.isRecording = false; }); }, }, }; ``` 上述代码中,我们首先在`mounted()`生命周期方法中初始化ezuikit的播放器。然后,我们可以在组件的模板中使用一个`video`标签来显示视频流,并将该标签的`id`设置为"video-player"。接下来,我们通过调用ezuikit的`startRecord()`方法和`stopRecord()`方法来开始和停止录像。在停止录像时,`stopRecord()`方法会返回录像的数据(recordData),可以用于后续的处理和保存。 需要注意的是,上述代码中的`your_access_token`和`your_camera_url`需要被替换为实际的访问令牌和摄像头的URL。 这只是一种实现方式,具体的实现还取决于项目的具体需求和摄像头的接口要求。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值