video.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="sgVideo">
  3. <video
  4. v-if="nouseVideo"
  5. :src="props.url"
  6. ref="Propaganda"
  7. x-webkit-airplay="allow"
  8. x5-video-player-type="h5"
  9. x5-video-player-fullscreen="true"
  10. x5-video-orientation="portraint"
  11. x5-playsinline
  12. loop
  13. controls
  14. onContextMenu="return false"
  15. onSelectStart="return false"
  16. @durationchange="durationchange"
  17. ></video>
  18. <iframe v-else :src="props.url" frameborder="0"></iframe>
  19. <div class="mo" v-if="nouseVideo"></div>
  20. <svg
  21. t="1667978418661"
  22. class="play"
  23. viewBox="0 0 1024 1024"
  24. version="1.1"
  25. xmlns="http://www.w3.org/2000/svg"
  26. p-id="2541"
  27. :width="ScreenWidth * 0.1"
  28. :height="ScreenWidth * 0.1"
  29. @click="play"
  30. >
  31. <path
  32. d="M512 74.666667C270.933333 74.666667 74.666667 270.933333 74.666667 512S270.933333 949.333333 512 949.333333 949.333333 753.066667 949.333333 512 753.066667 74.666667 512 74.666667z m0 810.666666c-204.8 0-373.333333-168.533333-373.333333-373.333333S307.2 138.666667 512 138.666667 885.333333 307.2 885.333333 512 716.8 885.333333 512 885.333333z"
  33. p-id="2542"
  34. fill="#e6e6e6"
  35. ></path>
  36. <path
  37. d="M708.266667 465.066667l-234.666667-134.4c-8.533333-4.266667-17.066667-6.4-25.6-6.4-29.866667 0-53.333333 23.466667-53.333333 53.333333v268.8c0 8.533333 2.133333 19.2 6.4 25.6 10.666667 17.066667 27.733333 27.733333 46.933333 27.733333 8.533333 0 17.066667-2.133333 25.6-6.4l234.666667-134.4c8.533333-4.266667 14.933333-10.666667 19.2-19.2 6.4-12.8 8.533333-27.733333 4.266666-40.533333-2.133333-14.933333-10.666667-25.6-23.466666-34.133333z m-249.6 162.133333V396.8L661.333333 512l-202.666666 115.2z"
  38. p-id="2543"
  39. fill="#e6e6e6"
  40. ></path>
  41. </svg>
  42. </div>
  43. </template>
  44. <script setup>
  45. // import { reactive } from "vue";
  46. import { ref, defineProps, onMounted } from "vue";
  47. import { isAndroid, isWechat } from "../utils/isTerminal";
  48. const props = defineProps({
  49. url: {
  50. type: String, //参数类型
  51. default: String, //默认值
  52. required: true, //是否必须传递
  53. },
  54. });
  55. const nouseVideo = ref(!isWechat && isAndroid); // 判断是否在安卓浏览器环境下
  56. /**
  57. * window.$originData.orginParames.title 页面标题
  58. * window.$originData.orginParames.parameters 固定参数值
  59. * window.$originData.urlParames url参数
  60. */
  61. const ScreenWidth = ref(window.$originData.orginParames.availWidth);
  62. const Propaganda = ref(null);
  63. onMounted(() => {});
  64. function durationchange() {
  65. const element = Propaganda.value;
  66. if (element.duration <= 0) return;
  67. element.currentTime = 0.01; // 防止微信浏览器不能加载封面
  68. if (element.value) return;
  69. const h = (element.videoHeight * ScreenWidth.value) / element.videoWidth;
  70. element.style.marginTop = h * 0.3 * -1 + "px";
  71. element.height = h * 1.6;
  72. document.querySelector(".sgVideo").style.height = h + "px";
  73. }
  74. function play() {
  75. console.log(
  76. "-->",
  77. document.getElementsByTagName("iframe")[0].contentWindow.document.body
  78. );
  79. if (nouseVideo.value) return;
  80. Propaganda.value.play();
  81. document.querySelector(".play").style.display = "none";
  82. }
  83. </script>
  84. <style scoped>
  85. .sgVideo > video,
  86. .sgVideo iframe {
  87. pointer-events: none;
  88. width: 100%;
  89. background-color: #000;
  90. }
  91. .sgVideo {
  92. position: relative;
  93. overflow: hidden;
  94. }
  95. .sgVideo .play {
  96. position: absolute;
  97. z-index: 2;
  98. top: 50%;
  99. left: 50%;
  100. transform: translate(-50%, -50%);
  101. }
  102. .sgVideo .mo {
  103. position: absolute;
  104. top: 0;
  105. left: 0;
  106. right: 0;
  107. bottom: 0;
  108. z-index: 1;
  109. }
  110. video::-webkit-media-controls {
  111. display: none !important;
  112. }
  113. </style>