微信无法自动播放网站手机端浏览器video标签视频失效

[复制链接]
查看2035 | 回复0 | 2022-5-7 15:13 | 显示全部楼层 |阅读模式

微信无法播放网站手机端视频微信浏览器video标签自动播放视频失效解决方法教程附带代码

视频播放html代码如下:
  1. <video id="videoPlay" class="video" autoplay="autoplay" loop="loop" playsinline="true"   preload="auto"  poster="" height="100%" style="text-align: -webkit-center; margin: 0 auto;" controls="">
  2.   <source src="/20220217.mp4" type="video/mp4" />
  3.   <source src="/20220217.mp4" type="video/ogg" />
  4.   <source src="/20220217.mp4" type="video/webm" />
  5. Your browser does not support the video tag.
  6. </video>
复制代码
js代码如下:
  1. (function () {
  2.             //触屏即加载音乐

  3.             // document.addEventListener('touchstart', function() {undefined
  4.             // document.getElementById('media').play()
  5.             // }

  6.              //进入微信页面即加载
  7.             // document.addEventListener('WeixinJSBridgeReady', function() {undefined
  8.             // document.getElementById('videoPlay').play()
  9.             // })     
  10.             
  11.             var voice = document.getElementById('videoPlay');
  12.             if(typeof WeixinJSBrdgeReady=="object" && typeof WeixinJSBridge.invoke == "function"){
  13.                 voice.play()
  14.             }else{
  15.                 if (document.addEventListener) {
  16.                     document.addEventListener("WeixinJSBridgeReady", function () {
  17.                         voice.play();
  18.                     }, false);
  19.                 } else if (document.attachEvent) {
  20.                     document.attachEvent("WeixinJSBridgeReady", function () {
  21.                         voice.play();
  22.                     });
  23.                     document.attachEvent("onWeixinJSBridgeReady", function () {
  24.                         voice.play();
  25.                     });
  26.                 }
  27.             }
  28.     })
复制代码
再刷新,是不是微信就能够播放您网站视频了呢。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-4-16