Last active
March 25, 2018 14:54
-
-
Save stevygee/e62d2e42bb86a33571223ff3698caa6a to your computer and use it in GitHub Desktop.
Two approaches to draw the current frame from video element on a canvas in regular intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function draw() { // Global function for displaying the game, this is called in a game loop | |
drawVideo(currentVideo); | |
// ... display other elements ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var video1 = $("#video1"); | |
var canvas = $("#myCanvas"); | |
var ctx = canvas[0].getContext("2d"); | |
var timerID; | |
function drawImage(video) { | |
ctx.drawImage(video, 0, 0, 640, 360); | |
} | |
video1.on("play", function () { | |
timerID = window.setInterval(function () { drawImage(video1[0]); }, 30); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment