javascript - captureStream() on dynamically created video element -


i trying capture stream dynamically created video element. when video element , try videoelement.capturestream() firefox returns videoelement.capturestream not function same code works on chrome. problem seems firefox has issue dynamically created video element. tried mutation observer detect newly added video element , access capturestream method no luck posting code sample below (i using adapter.js webrtc https://webrtc.github.io/adapter/adapter-latest.js)

(function (win) {      var listeners = [],         doc = win.document,         mutationobserver = win.mutationobserver || win.webkitmutationobserver,         observer;      function ready(selector, fn) {         listeners.push({         selector: selector,         fn: fn         });         if (!observer) {         observer = new mutationobserver(check);         observer.observe(doc.documentelement, {             childlist: true,             subtree: true         });         }         check();     }      function check() {         (var = 0, len = listeners.length, listener, elements; < len; i++) {         listener = listeners[i];         elements = doc.queryselectorall(listener.selector);         (var j = 0, jlen = elements.length, element; j < jlen; j++) {             element = elements[j];             if (!element.ready) {             element.ready = true;             listener.fn.call(element, element);             }         }         }     }      win.ready = ready;  })(this);    ready('.jw-video',function(element){     var stream = null;     element.addeventlistener('play',function(e){     //with firefox here e.target.capturestream or element.capturestream returns error     stream = e.target.capturestream();      var mediarecorder = new mediarecorder(stream);     mediarecorder.onerror = function(error){         console.log("media recorder error:",error);     }     mediarecorder.start();     mediarecorder.ondataavailable = function(evt){         console.log("mediarecorderdata");         var blob = evt.data;          var filereader = new filereader();         var arraybuffer;         filereader.onload = function(){             arraybuffer = filereader.result;             console.log("arraybuffer");             console.log(arraybuffer);             chunks.push(arraybuffer);             sendchunks(chunks);         };         filereader.readasarraybuffer(blob);     }     window.setinterval(function(){         mediarecorder.requestdata();                                 },3000);      }); }); 

does know how access capturestream method of newly added video element both works on chrome , firefox or approach capture stream , convert arraybuffer jwplayer?

no, problem firefox still prefixes htmlmediaelement#capturestream.

so need call video.mozcapturestream(), , inlined video elements.

console.log(`in document :   capturestream : ${indoc.capturestream}  mozcapturestream : ${indoc.mozcapturestream}  `)    var dyn = document.createelement('video');  console.log(`dynamic :   capturestream : ${dyn.capturestream}  mozcapturestream : ${dyn.mozcapturestream}  `)
<video id="indoc">

so in order support both chrome , ff :

let stream = video.mozcapturestream ? video.mozcapturestream() : video.capturestream(); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -