Browse Source

修复微信里背景视频全屏播放、不自动播放的问题;只在移动端且屏幕方向改变时reload,而不是resize时就reload

任一存 2 years ago
parent
commit
a5c7334cc4
4 changed files with 47 additions and 5 deletions
  1. 6 5
      src/main.js
  2. 12 0
      src/views/HistoryNew.vue
  3. 11 0
      src/views/Treasure.vue
  4. 18 0
      src/views/TreasureDetail.vue

+ 6 - 5
src/main.js

@@ -40,14 +40,15 @@ if (uaInfo.device.type === 'mobile') {
   app.config.globalProperties.$isMobile = true
   app.config.globalProperties.$isMobile = true
 }
 }
 
 
-// 处理resize事件
-function onResize() {
+// 处理resize和orientation change事件
+// window.addEventListener('resize', (e) => {
+//   onResize(e)
+// })
+// 安卓端chrome、安卓端微信都是支持的。
+screen.orientation.addEventListener("change", (event) => {
   if (app.config.globalProperties.$isMobile) {
   if (app.config.globalProperties.$isMobile) {
     location.reload()
     location.reload()
   }
   }
-}
-window.addEventListener('resize', () => {
-  onResize()
 })
 })
 
 
 // // 禁用上下文菜单
 // // 禁用上下文菜单

+ 12 - 0
src/views/HistoryNew.vue

@@ -11,10 +11,13 @@
     @touchcancel="onTouchCancel"
     @touchcancel="onTouchCancel"
   >
   >
     <video
     <video
+      ref="bgVideo"
       src="@/assets/videos/bg-history.mp4"
       src="@/assets/videos/bg-history.mp4"
       class="bg"
       class="bg"
       autoplay
       autoplay
       loop
       loop
+      webkit-playsinline="true"
+      playsinline="true"
     />
     />
     <div
     <div
       class="gear-wrap"
       class="gear-wrap"
@@ -120,6 +123,14 @@ export default {
 
 
     const spaceEachPerson = 220
     const spaceEachPerson = 220
 
 
+    /**
+     * 针对微信中背景视频无法自动播放的问题
+     */
+    const bgVideo = ref(null)
+    onMounted(() => {
+      bgVideo.value.play()
+    })
+
     // mask相关
     // mask相关
     const isShowLoadingMask = ref(true)
     const isShowLoadingMask = ref(true)
     onBeforeMount(() => {
     onBeforeMount(() => {
@@ -499,6 +510,7 @@ export default {
 
 
 
 
     return {
     return {
+      bgVideo,
       computeTimeAxisScaleOpacity,
       computeTimeAxisScaleOpacity,
       currentTimeIdx,
       currentTimeIdx,
       gearFrameIdx,
       gearFrameIdx,

+ 11 - 0
src/views/Treasure.vue

@@ -4,10 +4,13 @@
     class="treasure"
     class="treasure"
   >
   >
     <video
     <video
+      ref="bgVideo"
       src="@/assets/videos/bg-history.mp4"
       src="@/assets/videos/bg-history.mp4"
       class="bg"
       class="bg"
       autoplay
       autoplay
       loop
       loop
+      webkit-playsinline="true"
+      playsinline="true"
     />
     />
     <div
     <div
       class="grid"
       class="grid"
@@ -71,6 +74,14 @@ const prefix = process.env.VUE_APP_API_ORIGIN
 
 
 const store = useStore()
 const store = useStore()
 
 
+/**
+ * 针对微信中背景视频无法自动播放的问题
+ */
+const bgVideo = ref(null)
+onMounted(() => {
+  bgVideo.value.play()
+})
+
 // 滑动功能
 // 滑动功能
 let isMouseDown = false
 let isMouseDown = false
 let isDragged = false
 let isDragged = false

+ 18 - 0
src/views/TreasureDetail.vue

@@ -10,10 +10,13 @@
     </Teleport>
     </Teleport>
 
 
     <video
     <video
+      ref="bgVideo"
       src="@/assets/videos/bg-history.mp4"
       src="@/assets/videos/bg-history.mp4"
       class="bg"
       class="bg"
       autoplay
       autoplay
       loop
       loop
+      webkit-playsinline="true"
+      playsinline="true"
     />
     />
     <button
     <button
       class="back"
       class="back"
@@ -86,6 +89,8 @@
               class="bg"
               class="bg"
               autoplay
               autoplay
               loop
               loop
+              webkit-playsinline="true"
+              playsinline="true"
             />
             />
             <iframe
             <iframe
               :src="`${prefix}/web-model/index.html#/relic-detail?model-path=${encodeURIComponent(item.filePath)}`"
               :src="`${prefix}/web-model/index.html#/relic-detail?model-path=${encodeURIComponent(item.filePath)}`"
@@ -119,6 +124,8 @@
               class="bg"
               class="bg"
               autoplay
               autoplay
               loop
               loop
+              webkit-playsinline="true"
+              playsinline="true"
             />
             />
             <video
             <video
               :src="item.filePath"
               :src="item.filePath"
@@ -151,6 +158,8 @@
               class="bg"
               class="bg"
               autoplay
               autoplay
               loop
               loop
+              webkit-playsinline="true"
+              playsinline="true"
             />
             />
             <img
             <img
               draggable="false"
               draggable="false"
@@ -267,6 +276,14 @@ export default {
     const route = useRoute()
     const route = useRoute()
 
 
     /**
     /**
+     * 针对微信中背景视频无法自动播放的问题
+     */
+    const bgVideo = ref(null)
+    onMounted(() => {
+      bgVideo.value.play()
+    })
+
+    /**
      * tab bar
      * tab bar
      */
      */
     const activeTabIndex = ref(0)
     const activeTabIndex = ref(0)
@@ -402,6 +419,7 @@ export default {
     return {
     return {
       activeSwiperItemIndex,
       activeSwiperItemIndex,
       activeTabIndex,
       activeTabIndex,
+      bgVideo,
       bgAudio,
       bgAudio,
       cancelFullScreen,
       cancelFullScreen,
       canRecord,
       canRecord,