JSFiddle - React, Tailwind, and code Playground

by moku23

HTML

<script  src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

  <div id="theater">
    <video id="video" src="https://file-examples.com/storage/fe7d3a0d44631509da1f416/2017/04/file_example_MP4_480_1_5MG.mp4" controls="false"></video>
   <video id="video2" src="https://media.istockphoto.com/videos/footballer-juggling-the-ball-video-id473394223" controls="false" ></video>
    <canvas id="canvas" style="width:1080px"></canvas>
    <label>
      <br />Try to play me :)</label>
    <br />
  </div>

JavaScript

$(function() {
  var canvas = document.getElementById('canvas');
  var ctx = canvas.getContext('2d');
  var video = document.getElementById('video');
    var video2 = document.getElementById('video2');

  video.addEventListener('play', function() {
    var $this = this; //cache
    (function loop() {
      if (!$this.paused && !$this.ended) {
        ctx.drawImage($this, 0, 0);
        ctx.drawImage(video2, 0, 0);
        setTimeout(loop, 1000 / 30); // drawing at 30fps
      }
    })();
  }, 0);
});