class AudioService {
  constructor($log, _, $q, Howl, Howler, $localStorage, audioOn, baseMusic) {
    'ngInject';

    this._ = _;
    this.$q = $q;
    this.$log = $log;
    this.Howl = Howl;
    this.Howler = Howler;
    this.local = $localStorage;
    this.audioOn = audioOn;

    this.sounds = [];
    this.soundFiles = [];
    //this.prepareSound();
  }

  prepareSound() {
    this.sounds = this._.each(this.soundFiles, (soundFile) => {
      var sound = new this.Howl({
        src: [soundFile.url],
        loop: false,
        preload: true,
        html5: true
      });

      sound.name = soundFile.name;
      return sound;
    });
  }

  prepareMusic(url, loop = true) {
    var music = new this.Howl({
      src: [url],
      loop: loop,
      preload: true,
      html5: true
    });

    music.isPlaying = false;

    return music;
  }

  setMusic(music) {
    if (this.music) {
      this.stopMusic();
      this.music = null;
    }

    this.music = music;
  }

  playSound(name) {
    const sound = this._.find(this.sounds, (sound) => sound.name === name)

    if (sound == null) {
      return;
    }

    sound.play();
  }

  playMusic() {
    if (this.music != null) {
      this.music.fade(0, 1, 1000);
      this.music.play();
      this.music.isPlaying = true;
    }
  }

  pauseMusic() {
    if (this.music != null) {
      this.music.pause();
      this.music.isPlaying = false;
    }
  }

  fadeToStop() {
    if (this.music != null) {
      this.music.fade(1, 0, 1000);
      this.music.onfaded = () => {
        this.stopMusic();
      }
    }
  }

  stopMusic() {
    if (this.music != null) {
      this.music.stop();
      this.music.isPlaying = false;
    }
  }
}

export default AudioService;

@@ -1,8 +1,601 @@
+const soundFiles = %5B%0A  %7B%0A    name: 'blup',%0A    url:'https://dl.dropboxusercontent.com/u/13188176/Famous%2520Places/Sound/blub.mp3'%0A  %7D,%0A  %7B%0A    name: 'button',%0A    url:'https://dl.dropboxusercontent.com/u/13188176/Famous%2520Places/Sound/button.mp3'%0A  %7D,%0A  %7B%0A    name: 'ping',%0A    url:'https://dl.dropboxusercontent.com/u/13188176/Famous%2520Places/Sound/ping.mp3'%0A  %7D,%0A  %7B%0A    name: 'tada',%0A    url:'https://dl.dropboxusercontent.com/u/13188176/Famous%2520Places/Sound/tada.mp3'%0A  %7D,%0A  %7B%0A    name: 'tick',%0A    url:'https://dl.dropboxusercontent.com/u/13188176/Famous%2520Places/Sound/tick.mp3'%0A  %7D%0A%5D;%0A%0A
 class Au
@@ -815,21 +815,24 @@
    this.
-local
+$storage
  = $loca
@@ -896,40 +896,13 @@
 %5B%5D;%0A
-    this.soundFiles = %5B%5D;
 %0A    
-//
 this
@@ -971,18 +971,12 @@
 s._.
-each(this.
+map(
 soun
@@ -1006,19 +1006,19 @@
 %7B%0A      
-var
+let
  sound =
@@ -1201,16 +1201,49 @@
 %0A    %7D);
+%0A%0A    this.$log.log(this.sounds);
 %0A  %7D%0A%0A  
@@ -1702,40 +1702,194 @@
     
-return;%0A    %7D%0A%0A    sound.play();
+this.$log.debug('sound is null');%0A      return;%0A    %7D%0A%0A%0A    if(this.$storage.audioStatus === this.audioOn) %7B%0A      sound.play();%0A    %7D else %7B%0A      this.$log.debug('audio not on');%0A    %7D
 %0A  %7D

Prepare for playing sound