vionPlayerDemo.vue 3.36 KB
<template>
  <div class="j-player-demo">
    <div class="player-content">
      <!-- :play-url="playUrl" -->
      <vion-player v-if="playerVisible"
        ref="vionPlayer"
        :datetime-range="datetimeRange"
        watermarkText="文安智能123"
        @ptz-control="handlePtz"
      />
    </div>
    <div class="footer">
      <div class="play">
        <input type="text" v-model="playUrl">
        <button @click="handlePlay">播放</button>
      </div>
      <!-- <button @click="handleLive">直播</button> -->
      <!-- <button @click="handleShow">展示</button> -->
      <button @click="handlePause">暂停</button>
      <button @click="handleStop">停止</button>
      <button @click="handleDestroy">销毁</button>
      <button @click="handleScreenshot">抓拍</button>
      <div class="record">
        <input type="text" v-model="recordUrl">
        <button @click="handleRecord">录像</button>
      </div>
    </div>

    <el-dialog title="Image" :visible.sync="dialogVisible" width="90%">
      <img v-if="dialogVisible" :src="base64Url" alt="base64" />
    </el-dialog>
  </div>
</template>

<script>
import VionPlayer from '../../components/vionPlayer';

export default {
  name: 'VionPlayerDemo',
  components: {
    VionPlayer,
  },
  data() {
    return {
      datetimeRange: [],

      playerVisible: true,
      dialogVisible: false,
      base64Url: '',

      // 播放器相关
      playUrl: 'https://rtmp01open.ys7.com:9188/v3/openlive/F16423875_1_1.flv?expire=1695279265&id=624619383494283264&t=75ae0260690eedd9d493ab1caf716fe3f10a3e4c9b6df59135e032d437cf187a&ev=100&supportH265=1',
      recordUrl: 'https://rtmp01open.ys7.com:9188/v3/openpb/F16423875_1_1.flv?begin=20230919103030&end=20230919113030&expire=1695289270&id=624661345092866048&rec=local&t=53368acd4fe795901a25cc1f85e212040abd6d816d5d7154fc61cff27285b81a&ev=100&supportH265=1',
    }
  },
  methods: {
    handlePlay() {
      const url = this.playUrl;
      this.$refs.vionPlayer.play(url);
    },
    handleShow() {
      this.playerVisible = true;
    },
    handleRecord() {
      this.$refs.vionPlayer.play(this.recordUrl);
    },
    handleScreenshot() {
      this.$refs.vionPlayer.screenshot().then(data => {
        console.log('handleScreenshot', data);
        this.base64Url = data;
        this.dialogVisible = true;
      }).catch(err => {
        console.error(err);
      })
    },
    handlePause() {
      this.$refs.vionPlayer.pause();
    },
    handleStop() {
      this.$refs.vionPlayer.stop();
    },
    handleDestroy() {
      this.$refs.vionPlayer.destroy();
    },

    handlePtz(arrow) {
      console.log('handlePtz', arrow);
    },
  },
}
</script>

<style lang="scss" scoped>
.j-player-demo {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  outline: 1px solid #ccc;
  padding-top: 10px;
  padding-bottom: 10px;
  > .player-content {
    width: 800px;
    height: 480px;
  }
  > .footer {
    margin-top: 10px;
    > div.play {
      display: inline-block;
      margin-right: 10px;
      > button {
        margin-left: 2px;
      }
    }
    > button {
      margin-right: 10px;
    }

    > div.record {
      margin-top: 10px;
      > button {
        margin-left: 2px;
      }
    }
  }
  ::v-deep(.el-dialog__body) {
    text-align: center;
    background-color: #CCC;
    > img {
      max-width: 100%;
      height: auto;
    }
  }
}
</style>