<template>
  <div>
    <h3>{{fileName}}</h3>
    <audio :src="realSrc" controls="controls"/>
  </div>
</template>

<script>
import {isExternal} from "@/utils/validate";

export default {
  name: 'VideoPlayer',
  props: {
    src: {
      type: String,
      default: ""
    },
  },
  computed: {
    // 获取文件名称
    fileName() {
      // 如果是url那么取最后的名字 如果不是直接返回
      if (this.src.lastIndexOf("/") > -1) {
        return this.src.slice(this.src.lastIndexOf("/") + 1);
      } else {
        return this.src;
      }
    },
    realSrc() {
      if (!this.src) {
        return;
      }
      let real_src = this.src.split(",")[0];
      if (isExternal(real_src)) {
        return real_src;
      }
      return process.env.VUE_APP_BASE_API + real_src;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
