Play video on canvas and preserve the last frame/image on HTML5 Canvas


You can try to run the following code to play and preserve the video’s last frame:

var c = $('canvas')[0];
var context = canvas.getContext('2d');

c.width = 640;
c.height = 480;

$("#,myPlayer").on('play', function (e) {
   var $this = this;
   (function loop() {
      if (!$this.paused && !$this.ended) {
         context.drawImage($this, 0, 0, 640, 480);
         setTimeout(loop, 1000 / 30);
      }
   })();
});

Updated on: 29-Jan-2020

203 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements