video视频转画布,通过getContext(‘2d’).drawImage(v, 0, 0, 270, 135)方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- 说明:属性应用
width="100%"
height="240px" /*如果有封面,请设置高度*/
controls /*这个属性规定浏览器为该视频提供播放控件*/
style="object-fit:fill" /*加这个style会让 Android / web 的视频在微信里的视频全屏,如果是在手机上预览,会让视频的封面同视频一样大小*/
webkit-playsinline="true" /*这个属性是ios 10中设置可以让视频在小窗内播放,也就是不是全屏播放*/
x-webkit-airplay="true" /*这个属性还不知道作用*/
playsinline="true" /*IOS微信浏览器支持小窗内播放*/
x5-video-player-type="h5" /*启用H5播放器,是wechat安卓版特性*/
x5-video-orientation="h5" /*播放器支付的方向,landscape横屏,portraint竖屏,默认值为竖屏*/
x5-video-player-fullscreen="true" /*全屏设置,设置为 true 是防止横屏*/
preload="auto" /*这个属性规定页面加载完成后载入视频*/
-->
<video id="video1" width="270"controls autoplay loop >
<source src="http://www.w3school.com.cn/example/html5/mov_bbb.mp4" type="video/mp4">
<source src="http://www.w3school.com.cn/example/html5/mov_bbb.ogg" type="video/ogg">
<source src="http://www.w3school.com.cn/example/html5/mov_bbb.webm" type="video/webm">
</video>
<canvas id="myCanvas" width="270" height="135"></canvas>
<button class="paly">播放</button>
<button class="pause">暂停</button>
<script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
var v=document.getElementById("video1");
var c=document.getElementById("myCanvas");
var ctx=c.getContext('2d');
var timer;
var drawImage=function(){
ctx.drawImage(v, 0, 0, 270, 135);
}
v.addEventListener('play',function() {
timer= window.setInterval(drawImage,20);
},false);
v.addEventListener('pause',function() {
window.clearInterval(timer);
},false);
v.addEventListener('ended',function() {
clearInterval(timer);
},false);
</script>
<script>
$(function(){
$(".paly").click(function(){
v.play();
});
$(".pause").click(function(){
v.pause();
})
})
</script>
</body>
</html>