index.vue 3.15 KB
<template>
  <div class="vion-player" ref="container"></div>
</template>

<script>
import { watermarkBase64 } from './data';

export default {
  name: 'VionPlayer',
  props: {
    type: {
      type: String,
      default: 'live', // playback
    },
    playUrl: {
      type: String,
      default: '', // 若配置,则播放器加载后,自动播放
    },
    datetimeRange: {
      type: Array,
      default: null,
    },
    watermarkText: {
      type: String,
      default: '',
    },
    controlAutoHide: {
      type: Boolean,
      default: true,
    },
    showPtz: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      // eslint-disable-next-line
      _jessibuca: null,
    }
  },
  mounted() {
    this.init();
  },
  methods:{
    init(params = {}) {
      const options = Object.assign({
        container: this.$refs.container,
        decoder: '/jessibuca-pro/decoder-pro.js',
        isResize: false,
        text: '', // TODO: 功能暂不清楚
        useMSE: true,
        useWCS: false,
        isNotMute: false,
        timeout: 10,
        keepScreenOn: true, // 屏幕常亮
        debug: false, // 是否开启控制台调试打印

        // 按钮和界面
        loadingText: '加载中...',
        controlAutoHide: this.controlAutoHide,
        supportDblclickFullscreen: false,
        showBandwidth: false, // 显示网速
        watermarkConfig: {
          image: {
            src: watermarkBase64,
            width: 150,
            height: 48
          },
          right: 10,
          top: 30
        },
        operateBtns: {
          fullscreen: true,
          screenshot: false,
          play: true,
          audio: true,
          ptz: true, // 云台
          zoom: true,
          performance: false,
        },
        extendOperateBtns: [],
        // 云台控制
        ptzClickType: 'click', // click mouseDownAndUp
        ptzZoomShow: true,
        ptzMoreArrowShow: true,
        ptzApertureShow: true,
        ptzFocusShow: true,
      });

      this._jessibuca = new window.JessibucaPro(options);

      this.registerEvent(this._jessibuca);

      if (this.playUrl) {
        // 示例上有延迟写法
        setTimeout(this.play(this.playUrl), 150);
      }
    },
    registerEvent(playerIns) {
      playerIns.on("log", msg => {
        console.log("on-log", msg);
      });

      playerIns.on('ptz', (arrow) => {
        // console.log('ptz', arrow);
        this.$emit('ptz-control', arrow);
      });
    },

    // 暴露方法
    play(url) {
      if (url) {
        this._jessibuca.play(url);
      } else {
        console.error('The url is not valid');
      }
    },
    pause() {
      this._jessibuca.pause();
    },
    stop() {
      this._jessibuca.pause(true);
    },
    destroy() {
      if (this._jessibuca) {
        this._jessibuca.destroy().then(() => {
          this._jessibuca = null;
        });
      }
    },

    screenshot(filename = '', format = 'png', quality = 0.92, type = 'base64') {
      return this._jessibuca.screenshot(filename, format, quality, type);
    },
  },
}
</script>

<style lang="scss" scoped>
.vion-player {
  background-color: rgba(13, 14, 27, 0.7);
}
</style>