index.vue 1.52 KB
<template>
  <div ref="container"></div>
</template>

<script>
export default {
  name: 'VionPlayer',
  data() {
    return {
      // eslint-disable-next-line
      _jessibuca: null,
    }
  },
  mounted() {
    this.init();
  },
  methods:{
    init(params = {}) {
      const options = Object.assign({
        container: this.$refs.container,
        decoder: './jessibuca/decoder.js',
        isResize: false,
        text: '', // TODO: 功能暂不清楚
        useMSE: false,
        useWCS: false,
        isNotMute: false,
        timeout: 10,
        debug: true, // 是否开启控制台调试打印

        // 按钮和界面
        loadingText: '加载中...',
        controlAutoHide: false,
        supportDblclickFullscreen: false,
        showBandwidth: false, // 显示网速
        operateBtns: {
          fullscreen: true,
          screenshot: false,
          play: true,
          audio: true,
        },
      });

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

      this.registerEvent(this._jessibuca);
    },
    registerEvent(playerIns) {
      playerIns.on("log", msg => {
        console.log("on-log", msg);
      });
    },

    // 暴露方法
    play(url) {
      if (url) {
        this._jessibuca.play(url);
      } else {
        console.error('The url is not valid');
      }
    },
    pause() {
      this._jessibuca.pause();
    },
    destroy() {
      if (this._jessibuca) {
        this._jessibuca.destroy();
      }
      this.init();
    },
  },
}
</script>

<style lang="scss" scoped>

</style>