All files / src/events progress.js

28.57% Statements 2/7
0% Branches 0/2
50% Functions 1/2
28.57% Lines 2/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                  31x                                                                   31x            
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * Imports the BufferedProgressElements visual handler
 * @module visual/bufferedProgressElements.js
 */
import BufferedProgressElements from "../visual/bufferedProgressElements.js";
 
/**
 * AmplitudeJS Event Handler for progress
 *
 * @module events/Progress
 */
let Progress = (function() {
  /**
   * As the song is buffered, we can display the buffered percentage in
   * a progress bar.
   *
   * HANDLER FOR: progress
   *
   * @access public
   */
  function handle() {
    /*
      Help from: http://jsbin.com/badimipi/1/edit?html,js,output
    */
    if (config.audio.buffered.length - 1 >= 0) {
      let bufferedEnd = config.audio.buffered.end(
        config.audio.buffered.length - 1
      );
      let duration = config.audio.duration;
 
      /*
        Set the computed song buffered value to the config.
      */
      config.buffered = (bufferedEnd / duration) * 100;
    }
 
    /*
      Sync the buffered progress bars.
    */
    BufferedProgressElements.sync();
  }
 
  /**
   * Returns the public facing methods
   */
  return {
    handle: handle
  };
})();
 
export default Progress;