video-preview.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <div class="video-content">
  3. <video
  4. id="myVideoRef"
  5. ref="myVideoRef"
  6. class="video-js vjs-default-skin"
  7. controls
  8. :style="{ width: resultVideo.width, height: resultVideo.height }"
  9. x5-video-player-fullscreen="true"
  10. x5-video-player-type="h5"
  11. controlslist="nodownload"
  12. @timeupdate="handleTimeUpdate"
  13. >
  14. <source src="" type="video/mp4" />
  15. </video>
  16. </div>
  17. </template>
  18. <script setup lang="ts">
  19. import { ref, reactive, onMounted } from "vue";
  20. import { IProps, IVideoOptions } from "./index.type";
  21. import "video.js/dist/video-js.css";
  22. import useBlobFile from "@/Hooks/useBlob";
  23. const props = defineProps<IProps>();
  24. const myVideoRef = ref<HTMLVideoElement | null>(null);
  25. const resultVideo = reactive<IVideoOptions>({
  26. currentTime: 0,
  27. allTime: 0,
  28. width: "100%",
  29. height: "210px",
  30. });
  31. const handleTimeUpdate = () => {
  32. resultVideo.allTime = myVideoRef.value!.duration
  33. resultVideo.currentTime = myVideoRef.value!.currentTime
  34. }
  35. onMounted(async () => {
  36. console.log('视频链接', props.url)
  37. await useBlobFile(myVideoRef.value!, props.url);
  38. });
  39. </script>
  40. <style lang="scss" scoped>
  41. .video-content {
  42. width: 100%;
  43. max-height: 210px;
  44. }
  45. video::-internal-media-controls-download-button {
  46. display: none;
  47. }
  48. video::-webkit-media-controls-enclosure {
  49. overflow: hidden;
  50. }
  51. video::-webkit-media-controls-panel {
  52. width: calc(100% + 30px);
  53. }
  54. </style>