繪製視頻我試圖從在畫布上video
元素繪製的視頻。我寫了下面的JS代碼:在畫布上
$(function() {
var video = $("#video");
video.bind("loadedmetadata", function() {
var vw = this.videoWidth;
var vh = this.videoHeight;
var canvas = $('#canvas');
canvas.width(vw).height(vh);
var context = canvas.getContext("2d");
video.addEventListener("play", function() { draw(video, context, vw, vh); }, false);
});
});
function draw(video, context, vw, vh)
{
if (video.paused || video.ended)
{
return false;
}
context.drawImage(video, 0, 0, vw, vh);
setTimeout(draw, 20, video, context, vw, vh);
}
這是我的HTML:
<body>
<video id="video" autoplay controls>
<source src="src1.avi" />
<source src="src2.mov" />
<source src="src3.ogg" />
<source src="src4.avi" />
</video>
<canvas id="canvas">
Please update your browser.
</canvas>
的jsfiddle here
我可以看到視頻播放,但它沒有被重新繪製到帆布。我的錯誤在哪裏?
可能重複:[HTML5:內帆布顯示視頻(http://stackoverflow.com/questions/4429440/html5-display-video-inside-canvas) – Anubhav 2014-11-22 16:36:54