案例:html/html5 案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p>要使用的视频:</p>
6
7
<video id="video1" controls width="270" autoplay>
8
  <source src="/example/html5/mov_bbb.mp4" type='video/mp4'>
9
  <source src="/example/html5/mov_bbb.ogg" type='video/ogg'>
10
  <source src="/example/html5/mov_bbb.webm" type='video/webm'>
11
</video>
12
13
<p>画布(每 20 毫秒,代码就会绘制视频的当前帧):</p>
14
15
<canvas id="myCanvas" width="270" height="135" style="border:1px solid #d3d3d3;">
16
Your browser does not support the HTML5 canvas tag.
17
</canvas>
18
19
<script>
20
21
var v=document.getElementById("video1");
22
var c=document.getElementById("myCanvas");
23
ctx=c.getContext('2d');
24
25
v.addEventListener('play', function() {var i=window.setInterval(function() {ctx.drawImage(v,0,0,270,135)},20);},false);
26
v.addEventListener('pause',function() {window.clearInterval(i);},false);
27
v.addEventListener('ended',function() {clearInterval(i);},false);  
28
29
</script>
30
31
</body>
32
</html>
33