admin 发表于 2022-5-7 15:13

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


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

视频播放html代码如下:
<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="">
<source src="/20220217.mp4" type="video/mp4" />
<source src="/20220217.mp4" type="video/ogg" />
<source src="/20220217.mp4" type="video/webm" />
Your browser does not support the video tag.
</video>js代码如下:
(function () {
            //触屏即加载音乐

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

             //进入微信页面即加载
            // document.addEventListener('WeixinJSBridgeReady', function() {undefined
            // document.getElementById('videoPlay').play()
            // })   
            
            var voice = document.getElementById('videoPlay');
            if(typeof WeixinJSBrdgeReady=="object" && typeof WeixinJSBridge.invoke == "function"){
                voice.play()
            }else{
                if (document.addEventListener) {
                  document.addEventListener("WeixinJSBridgeReady", function () {
                        voice.play();
                  }, false);
                } else if (document.attachEvent) {
                  document.attachEvent("WeixinJSBridgeReady", function () {
                        voice.play();
                  });
                  document.attachEvent("onWeixinJSBridgeReady", function () {
                        voice.play();
                  });
                }
            }
    })再刷新,是不是微信就能够播放您网站视频了呢。
页: [1]
查看完整版本: 微信无法自动播放网站手机端浏览器video标签视频失效