src/core/a-assets.js
function mediaElementLoaded (el) {
  if (!el.hasAttribute('autoplay') && el.getAttribute('preload') !== 'auto') {
    return;
  }

  // If media specifies autoplay or preload, wait until media is completely buffered.
  return new Promise(function (resolve, reject) {
    if (el.readyState === 4) { return resolve(); }  // Already loaded.
    if (el.error) { return reject(); }  // Error.

    el.addEventListener('loadeddata', checkProgress, false);
    el.addEventListener('progress', checkProgress, false);
    el.addEventListener('error', reject, false);

    function checkProgress () {
      // Add up the seconds buffered.
      var secondsBuffered = 0;
      for (var i = 0; i < el.buffered.length; i++) {
        secondsBuffered += el.buffered.end(i) - el.buffered.start(i);
      }

      // Compare seconds buffered to media duration.
      if (secondsBuffered >= el.duration) {
        // Set in cache because we won't be needing to call three.js loader if we have.
        // a loaded media element.
        // Store video elements only. three.js loader is used for audio elements.
        // See assetParse too.
        if (el.tagName === 'VIDEO') {
          THREE.Cache.files[el.getAttribute('src')] = el;
        }
        resolve();
      }
    }
  });
}
function mediaElementLoaded (el) {
  if (!el.hasAttribute('autoplay') && el.getAttribute('preload') !== 'auto') {
    return;
  }

  // If media specifies autoplay or preload, wait until media is completely buffered.
  return new Promise(function (resolve, reject) {
    if (el.readyState === 4) { return resolve(); }  // Already loaded.
    if (el.error) { return reject(); }  // Error.

    el.addEventListener('loadeddata', checkProgress, false);
    el.addEventListener('progress', checkProgress, false);
    el.addEventListener('error', reject, false);

    function checkProgress () {
      // Add up the seconds buffered.
      var secondsBuffered = 0;
      for (var i = 0; i < el.buffered.length; i++) {
        secondsBuffered += el.buffered.end(i) - el.buffered.start(i);
      }

      // Compare seconds buffered to media duration.
      if (secondsBuffered >= el.duration) {
        // Set in cache because we won't be needing to call three.js loader if we have.
        // a loaded media element.
        // Store video elements only. three.js loader is used for audio elements.
        // See assetParse too.
        if (el.tagName === 'VIDEO') {
          THREE.Cache.files[el.getAttribute('src')] = el;
        }
        resolve();
      }
    }
  });
}
function mediaElementLoaded ( el ) { if ( ! el . hasAttribute ( 'autoplay' ) && el . getAttribute ( 'preload' ) !== 'auto' ) { return ; } // If media specifies autoplay or preload, wait until media is completely buffered. return new Promise ( function ( resolve , reject ) { if ( el . readyState === 4 ) { return resolve ( ) ; } // Already loaded. if ( el . error ) { return reject ( ) ; } // Error. el . addEventListener ( 'loadeddata' , checkProgress , false ) ; el . addEventListener ( 'progress' , checkProgress , false ) ; el . addEventListener ( 'error' , reject , false ) ; function checkProgress ( ) { // Add up the seconds buffered. var secondsBuffered = 0 ; for ( var i = 0 ; i < el . buffered . length ; i ++ ) { secondsBuffered += el . buffered . end ( i ) - el . buffered . start ( i ) ; } // Compare seconds buffered to media duration. if ( secondsBuffered >= el . duration ) { // Set in cache because we won't be needing to call three.js loader if we have. // a loaded media element. // Store video elements only. three.js loader is used for audio elements. // See assetParse too. if ( el . tagName === 'VIDEO' ) { THREE . Cache . files [ el . getAttribute ( 'src' ) ] = el ; } resolve ( ) ; } } } ) ; }
Create a Promise that resolves once the media element has finished buffering.

@param {Element} el - HTMLMediaElement.
@returns {Promise}
Create a Promise that resolves once the media element has finished buffering .