Wait for a video to load
HTML
<!DOCTYPE html>
<html land="en">
<head>
<meta charset="utf-8">
<title>Using video in the canvas tag</title>
</head>
<body onLoad="init();">
<canvas id="canvas1" width="500" height="500"></canvas>
</body>
</html>
JavaScript
var vid, ctx;
function play() {
console.log("play");
vid.play();
setInterval(function() {
ctx.drawImage(vid, 0, 0);
}, 60);
}
function init() {
var can = document.getElementById('canvas1');
ctx = can.getContext('2d');
vid = document.createElement('video');
vid.src = "http://upload.wikimedia.org/wikipedia/commons/8/8c/Anthropoides_paradisea1.ogg";
vid.autoplay = false;
vid.loop = true;
vid.addEventListener("canplaythrough", play, false);
}