waitUntilBuffered(mediaElement, bufferingGoal) {
    // The name of what we're waiting for.
    const goalName = `${bufferingGoal} seconds buffered`;

    // The conditions for success.
    const bufferedEnough = () => {
      const end = shaka.media.TimeRangesUtils.bufferEnd(mediaElement.buffered);
      if (end == null) {
        return false;
      }
      return end - mediaElement.currentTime >= bufferingGoal;
    };

    if (bufferedEnough()) {
      return Promise.resolve();
    }

    // Cleanup on timeout.
    let timer = null;
    const cleanup = () => {
      if (timer) {
        timer.stop();
      }
      this.eventManager_.unlisten(mediaElement, 'timeupdate');
      this.eventManager_.unlisten(mediaElement, 'ended');
    };

    const p = new Promise((resolve) => {
      const check = () => {
        if (bufferedEnough()) {
          cleanup();
          resolve();
        }
      };

      timer = new shaka.util.Timer(check);
      timer.tickEvery(/* seconds= */ 1);
      this.eventManager_.listen(mediaElement, 'timeupdate', check);
      this.eventManager_.listen(mediaElement, 'ended', check);
    });

    return this.waitUntilGeneric_(goalName, p, cleanup, mediaElement);
  }
Wait until a certain amount of content is buffered.

@param {!HTMLMediaElement} mediaElement
@param {number} bufferingGoal in seconds, after which the Promise succeeds
@return {!Promise}