微信无法播放网站手机端视频微信浏览器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();
- });
- }
- }
- })
复制代码 再刷新,是不是微信就能够播放您网站视频了呢。
|
|