<template>
  <LivePlayer v-show="visible" :show-custom-button="false" ref="player" @snapOutside="onSnap" aspect='fullscreen' :videoUrl="videoUrl" :live="true" :alt="' '" :hide-fluent-button="true" :hide-big-play-button="true" @pause="onpause" @ended="onended" @timeupdate="ontimeupdate" />
</template>
<script>
import LivePlayer from '@liveqing/liveplayer'
export default {
  data () {
    return {
      visible: false,
      videoUrl: '',
    }
  },
  components: {
    LivePlayer
  },
  methods: {
    onpause () {
      this.$emit('pause')
    },
    ontimeupdate (t) {
      this.$emit('timeupdate', t)
    },
    onended () {
      this.$emit('ended')
    },
    onSnap (str) {
      this.$emit('snap', str)
    },
    show () {
      this.visible = true
    },
    hide () {
      this.visible = false;
    },
    play (url, time) {
      if (url) {
        this.videoUrl = url
      }
      this.$refs.player.play()
      if (time) {
        this.$refs.player.setCurrentTime(time);
      }
    },
    replay () {
      this.$refs.player.play()
    },
    destroy () {
      this.videoUrl = ''
    },
    setFullscreen () {
      this.$refs.player.toggleFullscreen()
    },
    setMuted (open) {
      this.$refs.player.setMuted(open ? 0 : 1)
    },
    snap () {
      this.$refs.player.snap()
    },
    pause () {
      this.$refs.player.pause()
    }
  }
}
</script>
<style lang="scss">
.video-wrapper .alt {
  display: none;
}
</style>