if (this.isWechat) {
if (window['WeixinJSBridge']) {
window['WeixinJSBridge'].invoke('getNetworkType', {}, (e) => {
this.doPlay()
})
} else {
document.addEventListener("WeixinJSBridgeReady", function(){
window['WeixinJSBridge'].invoke('getNetworkType', {}, (e) => {
this.doPlay()
})
}, false);
}
} else {
this.doPlay();
}
doPlay() {
const domList = Array.from(document.querySelectorAll('video'));
if (domList.length) {
domList.forEach(video => {
console.log(video);
video.currentTime = 0;
video.muted = true;
video.autoplay = true;
video.loop = true;
video.setAttribute('webkit-playsinline', 'true');
video.setAttribute('x5-video-player-fullscreen', 'true');
video.setAttribute('x5-playsinline', 'true');
video.setAttribute('playsinline', 'true');
console.log(video.play());
video.play();
});
}
}
微信浏览器自动播放
最新推荐文章于 2024-10-31 17:53:21 发布
这段代码检查是否在微信环境中,如果是,则使用WeixinJSBridge获取网络类型并在准备好后播放视频。视频设置为静音、自动播放、循环,并添加属性以支持在inline模式下播放。若不在微信环境,直接播放视频。
1519

被折叠的 条评论
为什么被折叠?



