All files / src/events ended.js

20% Statements 2/10
0% Branches 0/8
33.33% Functions 1/3
20% Lines 2/10
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                      31x                                                                                           31x            
/**
 * Imports the config module
 * @module config
 */
import config from "../config.js";
 
/**
 * Imports the Audio Navigation Utility
 * @module utilities/AudioNavigation
 */
import AudioNavigation from "../utilities/audioNavigation.js";
 
/**
 * Imports the Callback Utility
 * @module utilities/callbacks
 */
import Callbacks from "../utilities/callbacks.js";
 
/**
 * Imports the AmplitudeJS Core Methods
 * @module core/Core
 */
import Core from "../core/core.js";
 
/**
 * Imports the AmplitudeJS Play Pause Elements
 * @module visual/PlayPauseElements
 */
import PlayPauseElements from "../visual/playPauseElements.js";
 
/**
 * AmplitudeJS Ended Module. Handles the ended event on the audio.
 *
 * @module events/Ended
 */
let Ended = (function() {
  /**
   * When the song has ended, handles what to do next
   *
   * HANDLER FOR: ended
   *
   * @access public
   */
  function handle() {
    /*
      Sets the time out for song ended. This determines if
      we should go to the next song or delay between songs.
    */
    setTimeout(function() {
      /*
        If we continue next, we should move to the next song in the playlist.
      */
      if (config.continue_next) {
        /*
					If the active playlist is not set, we set the
					next song that's in the songs array.
				*/
        if (config.active_playlist == "" || config.active_playlist == null) {
          AudioNavigation.setNext(true);
        } else {
          AudioNavigation.setNextPlaylist(config.active_playlist, true);
        }
      } else {
        if (!config.is_touch_moving) {
          /*
						Stops the active song.
					*/
          AmplitudeCore.stop();
 
          /*
            Sync the play pause elements.
          */
          PlayPauseElements.sync();
        }
      }
    }, config.delay);
  }
 
  /*
    Returns the public facing methods.
  */
  return {
    handle: handle
  };
})();
 
export default Ended;