Display video inside HTML5 canvas

JavascriptWeb DevelopmentFront End Scripts

You can try the following code snippet to display video inside HTML5 canvas.

var canvas1 = document.getElementById('canvas');
var context = canvas1.getContext('2d');
var video = document.getElementById('video');
video.addEventListener('play', function () {
   var $this = this;
   (function loop() {
      if (!$this.paused && !$this.ended) {
         context.drawImage($this, 0, 0);
         setTimeout(loop, 1000 / 30);
      }
   })();
}, 0);
raja
Published on 05-Apr-2018 17:31:08
Advertisements