video.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div class="page pg-bg video-pg">
  3. <div class="content">
  4. <div class="title">
  5. <img src="/images/pg4/vid-title.png">
  6. </div>
  7. <video
  8. webkit-playsinline
  9. playsinline
  10. src="/video/和平宣言.mp4"
  11. preload="preload"
  12. autoplay="autoplay"
  13. :controls="controls"
  14. poster="/images/pg4/vid-poster.png"
  15. ref="mediaRef"
  16. @ended="show = true"
  17. @play="pause()"
  18. @pause="play()"
  19. ></video>
  20. <div class="play-action animate__animated animate__fadeIn">
  21. <img src="/images/pg4/重播.png" @click="onReplay" alt="" />
  22. <img src="/images/pg4/播撒种子.png" @click="onNext" alt="" />
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script setup>
  28. import { onMounted, ref } from "vue";
  29. import { useRouter, useRoute } from "vue-router";
  30. import { useModel } from '@zjxpcyc/vue-tiny-store';
  31. const { play, pause } = useModel('audio');
  32. const router = useRouter();
  33. const route = useRoute();
  34. const mediaRef = ref();
  35. const show = ref(true);
  36. const controls = ref();
  37. const onReplay = () => {
  38. mediaRef.value.play();
  39. show.value = false;
  40. };
  41. const onNext = () => {
  42. router.replace("/pg4/next");
  43. };
  44. onMounted(() => {
  45. // 自动播放
  46. try {
  47. const t = setTimeout(() => {
  48. clearTimeout(t);
  49. // 可能抛出异步异常
  50. const p = mediaRef.value.play();
  51. if (p) {
  52. p.then(() => {
  53. mediaRef.value.play();
  54. }).catch(err => {
  55. console.log('--play-err---', err)
  56. controls.value = "controls";
  57. })
  58. }
  59. }, 300);
  60. } catch (err) {
  61. console.log('---err---', err)
  62. controls.value = "controls";
  63. }
  64. // document.addEventListener('WeixinJSBridgeReady', () => {
  65. // mediaRef.value.play();
  66. // });
  67. });
  68. </script>
  69. <style lang="less" scoped>
  70. .video-pg {
  71. position: relative;
  72. background-image: url("/images/pg4/beijing.png");
  73. background-repeat: no-repeat;
  74. background-size: 100% 100%;
  75. display: flex;
  76. align-items: center;
  77. justify-content: center;
  78. .content {
  79. position: relative;
  80. .title {
  81. width: 60vw;
  82. margin: auto;
  83. margin-bottom: 80px;
  84. }
  85. video {
  86. // width: 100%;
  87. width: 100vw;
  88. z-index: 1;
  89. }
  90. .play-action {
  91. width: 100%;
  92. margin-top: 24px;
  93. display: flex;
  94. align-items: center;
  95. justify-content: center;
  96. img {
  97. width: 100px;
  98. width: 30vw;
  99. height: 10vw;
  100. & + img {
  101. margin-left: 40px;
  102. }
  103. }
  104. }
  105. }
  106. }
  107. </style>