HTML5 video 在IOS上自动播放失效
一、问题
一个在微信中运行的html页面。
在 html 上使用 video 的时候,发现 autoplay 是失效的。
使用 video 如下:
<video id="video" preload="auto" x-webkit-airplay='true' x5-video-player-type='h5' x5-video-player-fullscreen='true' controls width="100%" height="100%" type="video/mp4" src="./img/v0.mp4"></video>
二、探索
之后我在 js 中使用 video.play()
也是存在问题,无法直接使用。
原因在于视频播放需要用户主动触发
因此下面代码也无法使用:
window.onload = function(){
video.play();
}
三、解决
在某个文章里面看到了利用 微信 js 来解决这个问题:
首先使用 jssdk
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"> </script>
配置是无所谓的,因为即使配置失败,也会走 ready 函数
wx.config({
// 配置信息, 即使不正确也能使用 wx.ready
debug: false,
appId: 'gh_1a8c118653f8',
timestamp: 1,
nonceStr: '',
signature: '',
jsApiList: []
});
wx.ready(function() {
$("#video")[0].play();
});
文章版权:Postbird-There I am , in the world more exciting!
本文链接:http://ptbird.cn/html5-video-ios-autoplay.html
转载请注明文章原始出处 !
扫描二维码,在手机阅读!