MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / createMedia

Function createMedia

libraries/p5.dom.js:834–868  ·  view source on GitHub ↗

VIDEO STUFF

(pInst, type, src, callback)

Source from the content-addressed store, hash-verified

832 /** VIDEO STUFF **/
833
834 function createMedia(pInst, type, src, callback) {
835 var elt = document.createElement(type);
836
837 // allow src to be empty
838 var src = src || '';
839 if (typeof src === 'string') {
840 src = [src];
841 }
842 for (var i=0; i<src.length; i++) {
843 var source = document.createElement('source');
844 source.src = src[i];
845 elt.appendChild(source);
846 }
847 if (typeof callback !== 'undefined') {
848 var callbackHandler = function() {
849 callback();
850 elt.removeEventListener('canplaythrough', callbackHandler);
851 }
852 elt.addEventListener('canplaythrough', callbackHandler);
853 }
854
855 var c = addElement(elt, pInst, true);
856 c.loadedmetadata = false;
857 // set width and height onload metadata
858 elt.addEventListener('loadedmetadata', function() {
859 c.width = elt.videoWidth;
860 c.height = elt.videoHeight;
861 // set elt width and height if not set
862 if (c.elt.width === 0) c.elt.width = elt.videoWidth;
863 if (c.elt.height === 0) c.elt.height = elt.videoHeight;
864 c.loadedmetadata = true;
865 });
866
867 return c;
868 }
869 /**
870 * Creates an HTML5 &lt;video&gt; element in the DOM for simple playback
871 * of audio/video. Shown by default, can be hidden with .hide()

Callers 1

p5.dom.jsFile · 0.85

Calls 1

addElementFunction · 0.85

Tested by

no test coverage detected