微信H5视频全屏播放demo

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
<meta name="format-detection"content="telephone=no">
<title>今天是个好日子</title>
<style>
*{  padding: 0;
    margin:0;
}
#frist{
position: absolute;
width: 100%;
height: 100%;
background-image: url(1.png);
background-size: 100% 100%;
background-position: top;
overflow: hidden;
}
#video_box{
position: absolute;
width: 100%;
height: 100%;
background-image: url(1.png);
background-size: 100% 100%;
background-position: top;
overflow: hidden;
display: none;
}
#video_all{
  position: absolute;
  width: 90%;
  top: 0;
  left: 5%;
  object-fit: fill;
  background-size: cover;
  overflow: hidden;
}
#btn,#againbtn{
width: 260px;height: 60px;
position: absolute;
top: 90%;
left:25%;
margin-top: -130px;
margin-left: -30px;
background-size: 100% 100%;
background-image: url(button.png);
background-size: 100% 100%;
}
#video_end{
position: absolute;
background-color: pink;
display: none;
background-size: 100% 100%;
background-image: url(last.jpg);
background-repeat: no-repeat;
background-position: top;
}


</style>
</head>
<body>
<!-- 最开始是暂停界面,手动控制视频的播放 -->
<div id="frist"></div> 
<!-- 视频播放区 -->
<div id="video_box">
   <video 
    id="video_all" 
    src="hello.mp4" 
    poster="1.png"
    autoplay="false" 
    webkit-playsinline="true" 
    playsinline="true" 
    x-webkit-airplay="allow" 
    x5-video-player-type="h5" 
    x5-video-player-fullscreen="true" 
    x5-video-orientation="portraint"
    style="object-fit:fill">
    </video> 
<!--<video 
    id="video_all" 
    src="hello.mp4" 
    poster="1.png" /*视频封面*/
    autoplay="false" 
    webkit-playsinline="true" /*这个属性是ios 10中设置可以让视频在小窗内播放,也就是不是全屏播放*/
    playsinline="true" /*IOS微信浏览器支持小窗内播放*/ 
    x-webkit-airplay="allow" 
    x5-video-player-type="h5" /*启用H5播放器,是wechat安卓版特性*/
    x5-video-player-fullscreen="true" /*全屏设置,设置为 true 是防止横屏*/
    x5-video-orientation="portraint"/*播放器支付的方向,landscape横屏,portraint竖屏,默认值为竖屏*/
    style="object-fit:fill">
    </video> --> 
</div>
<!-- 视频播放按钮 -->
<div id="btn" οnclick="playcontr()"></div>
<!-- 视频播放结束 -->
<div id="video_end"></div>
<script>


var video_all = document.getElementById('video_all'),
      video_box = document.getElementById('video_box'),
      btn = document.getElementById('btn'),
      video_end =  document.getElementById('video_end');
var clientWidth = document.documentElement.clientWidth;
var clientHeight = document.documentElement.clientHeight;
video_all.pause();

document.addEventListener('touchmove', function(e){e.preventDefault()}, false);


function stylediv(divId){
    divId.style.width = clientWidth + 'px';
    divId.style.height = clientHeight + 'px'; 
}
function playcontr(){
    if (isAndroid) {
       video_all.style.width = '100%';
       video_all.style.left = '0';       
    }
    video_box.style.display = "block";
    video_all.play();
    btn.style.display = "none";
    video_end.style.display = "none";
};
// stylediv(video_box);
stylediv(video_end);
// 适配判断
var u = navigator.userAgent; 
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端 
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 


// 暂停播放
video_all.addEventListener('pause',function(){  
    video_all.style.width = clientWidth + 'px';
    btn.style.display = "block";
})  


// 播放结束
video_all.addEventListener("ended",function(){
    video_all.pause();
    video_end.style.display = "block";
    video_box.style.display = "none"; 
});


</script>
</body>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值