亲测: IOS和安卓均有效
<video
x5-playsinline="true"
playsinline="true"
webkit-playsinline="true"
x-webkit-airplay="true"
x5-video-orientation="portraint"
>
<source :src="videoUrl" type="video/mp4">
video>
注意: x5-video-player-type="h5" 这个参数不能用,用了的话安卓就失效了。
video 标签中添加 muted 和 autoplay 属性<video
autoplay
muted
x5-playsinline="true"
playsinline="true"
webkit-playsinline="true"
x-webkit-airplay="true"
x5-video-orientation="portraint"
>
<source :src="videoUrl" type="video/mp4">
video>
注意: 自动播放,会因为 muted 而静音。
微信里面的自动播放只能用于IOS,不能用于安卓(目前来说)
IOS微信自动播放方法: 通过使用 jssdk 的 WeixinJSBridgeReady 播放
下面是VUE代码
HTML部分
<video
ref="videoRef"
:src=""
muted
autoplay
x5-playsinline="true"
playsinline="true"
webkit-playsinline="true"
x-webkit-airplay="true"
x5-video-orientation="portraint"
>video>
JS部分
onMounted(() => {
if (WeixinJSBridge) {
doPlay();
} else {
document.addEventListener(
"WeixinJSBridgeReady",
function () {
doPlay();
},
false
);
}
});
// 通过微信桥接开始播放
function doPlay() {
WeixinJSBridge.invoke("getNetworkType", {}, function (e) {
let videoHtml = videoRef.value;
videoHtml.play();
});
}
安卓微信自动播放方法:
video 标签的 controls,通过做个蒙版,点击诱导的方式Tcplayer 腾讯云点播(未测试)下面是VUE代码
HTML部分
<video
ref="videoRef"
:src=""
muted
autoplay
x5-playsinline="true"
playsinline="true"
webkit-playsinline="true"
x-webkit-airplay="true"
x5-video-orientation="portraint"
id="vdHtml"
>video>
<video
ref="videoRef"
:src=""
muted
autoplay
x5-playsinline="true"
playsinline="true"
webkit-playsinline="true"
x-webkit-airplay="true"
x5-video-orientation="portraint"
>video>
JS部分
onMounted(() => {
let ua = navigator.userAgent;
let isAndroid = ua.indexOf("Android") > -1 || ua.indexOf("Linux") > -1;
let isWeixin = ua.indexOf("MicroMessenger") > 0;
// 安卓触摸屏幕后播放
if (isAndroid && isWeixin) {
document.addEventListener(
"touchstart",
function () {
let video = document.getElementById("vdHtml");
if (video) video.play();
},
false
);
}
});