uni-app video组件在安卓微信浏览器中全屏界面被卡住

uni-app video组件在安卓微信浏览器中全屏界面被卡住

1 回复

更多关于uni-app video组件在安卓微信浏览器中全屏界面被卡住的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在安卓微信浏览器中,uni-app的video组件全屏时出现界面卡住,通常是由于微信内置浏览器(X5内核)的兼容性问题导致的。以下是几种可行的解决方案:

  1. 启用H5增强模式
    manifest.json"h5"配置中添加以下代码,强制使用原生video控件,避免X5内核的默认全屏行为:

    "h5": {
      "template": "/* 其他配置 */",
      "router": { /* 路由配置 */ },
      "devServer": { /* 开发服务器配置 */ },
      "optimization": {
        "treeShaking": {
          "enable": true
        }
      },
      "video": {
        "enableH5Video": true
      }
    }
    
  2. 使用自定义全屏方案
    通过监听video组件的fullscreenchange事件,结合CSS模拟全屏效果,避免调用系统全屏:

    <template>
      <view>
        <video 
          :src="videoSrc" 
          @fullscreenchange="handleFullscreenChange"
          controls
        ></video>
      </view>
    </template>
    <script>
    export default {
      methods: {
        handleFullscreenChange(e) {
          if (e.detail.fullScreen) {
            // 自定义全屏逻辑,例如修改video样式
            this.isFullscreen = true;
          } else {
            this.isFullscreen = false;
          }
        }
      }
    }
    </script>
    <style scoped>
    .fullscreen-video {
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      z-index: 9999;
    }
    </style>
    
  3. 调整X5内核配置
    在页面头部添加以下meta标签,尝试优化X5内核的视频播放行为:

    <meta name="x5-video-player-type" content="h5">
    <meta name="x5-video-player-fullscreen" content="false">
    
  4. 检查微信版本和基础库
    确保用户微信版本和uni-app基础库为最新版本,旧版本可能存在已知兼容性问题。

  5. 降级为原生video标签
    在条件编译中针对安卓微信浏览器使用原生video标签:

    <template>
      <view>
        <!-- #ifdef H5 -->
        <video v-if="isWeixinAndroid" :src="videoSrc" controls></video>
        <!-- #endif -->
        <!-- #ifndef H5 -->
        <video :src="videoSrc" controls></video>
        <!-- #endif -->
      </view>
    </template>
    <script>
    export default {
      data() {
        return {
          isWeixinAndroid: false
        };
      },
      mounted() {
        // 检测安卓微信环境
        const ua = navigator.userAgent.toLowerCase();
        this.isWeixinAndroid = /micromessenger/.test(ua) && /android/.test(ua);
      }
    };
    </script>
回到顶部