getBlobDuration.js.map 1.83 KB
{"version":3,"sources":["getBlobDuration.js"],"names":["getBlobDuration","_callee","blob","tempVideoEl","durationP","_regenerator","wrap","_context","prev","next","document","createElement","Promise","resolve","addEventListener","duration","Infinity","currentTime","Number","MAX_SAFE_INTEGER","ontimeupdate","src","String","window","URL","createObjectURL","abrupt","stop"],"mappings":"6WAK8BA,8KAAf,SAAAC,EAA+BC,GAA/B,IAAAC,EAAAC,EAAA,OAAAC,aAAA,QAAAC,KAAA,SAAAC,GAAA,OAAA,OAAAA,EAAAC,KAAAD,EAAAE,MAAA,KAAA,EAAA,OACPN,EAAcO,SAASC,cAAc,SAErCP,EAAY,IAAIQ,QAAQ,SAAAC,GAAO,OACnCV,EAAYW,iBAAiB,iBAAkB,WAE1CX,EAAYY,WAAaC,EAAAA,GAC1Bb,EAAYc,YAAcC,OAAOC,iBAZzChB,EAAAiB,aAAA,WAcUjB,EAAYiB,aAAe,KAC3BP,EAAQV,EAAYY,UACpBZ,EAAYc,YAAc,IAK5BJ,EAAQV,EAAYY,cAhBbZ,EAAAkB,IAAA,iBAAAnB,GAAAA,aAAAoB,OAAApB,EAAAqB,OAAAC,IAAAC,gBAAAvB,GAAAK,EAAAmB,OAAA,SACPvB,GADO,KAAA,EAAA,IAAA,MAAA,OAAAI,EAAAoB,SAAA1B","file":"getBlobDuration.js","sourcesContent":["/**\n * @param {Blob|String} blob\n *\n * @returns {Promise<Number>} Blob duration in seconds.\n */\nexport default async function getBlobDuration(blob) {\n  const tempVideoEl = document.createElement('video')\n\n  const durationP = new Promise(resolve =>\n    tempVideoEl.addEventListener('loadedmetadata', () => {\n      // Chrome bug: https://bugs.chromium.org/p/chromium/issues/detail?id=642012\n      if(tempVideoEl.duration === Infinity) {\n        tempVideoEl.currentTime = Number.MAX_SAFE_INTEGER\n        tempVideoEl.ontimeupdate = () => {\n          tempVideoEl.ontimeupdate = null\n          resolve(tempVideoEl.duration)\n          tempVideoEl.currentTime = 0\n        }\n      }\n      // Normal behavior\n      else\n        resolve(tempVideoEl.duration)\n    }),\n  )\n\n  tempVideoEl.src = typeof blob === 'string' || blob instanceof String\n    ? blob\n    : window.URL.createObjectURL(blob)\n\n  return durationP\n}\n"]}