SHARE
TWEET

Untitled

a guest Oct 17th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var canvas = document.querySelector("canvas");
  2.  
  3. // Optional frames per second argument.
  4. var stream = canvas.captureStream(25);
  5. var recordedChunks = [];
  6.  
  7. console.log(stream);
  8. var options = { mimeType: "video/webm; codecs=vp9" };
  9. mediaRecorder = new MediaRecorder(stream);
  10.  
  11. mediaRecorder.ondataavailable = handleDataAvailable;
  12. mediaRecorder.start();
  13.  
  14. function handleDataAvailable(event) {
  15.   console.log("data-available");
  16.   if (event.data.size > 0) {
  17.     recordedChunks.push(event.data);
  18.     console.log(recordedChunks);
  19.     download();
  20.  
  21.   } else {
  22.     // ...
  23.   }
  24. }
  25. function download() {
  26.     var blob = new Blob(recordedChunks, {
  27.       type: 'video/webm'
  28.     });
  29.     var url = URL.createObjectURL(blob);
  30.     var a = document.createElement('a');
  31.     document.body.appendChild(a);
  32.     a.style = 'display: none';
  33.     a.href = url;
  34.     a.download = 'test.webm';
  35.     a.click();
  36.     window.URL.revokeObjectURL(url);
  37.   }
  38.  
  39. //for logging status
  40. setInterval( (event) => {
  41.    
  42.     console.log(mediaRecorder);
  43.  
  44. },1500);
  45.  
  46. // demo: to download after 9sec
  47. setTimeout( (event) => {
  48.     console.log("stopping");
  49.     mediaRecorder.stop();
  50. }, 9000);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top