Fade In / Fade Out sounds

With the howler sound bound to the window, this works better across JS functions:
Sound.hype.zip (1.5 MB)

Initialize, play + fade in:

window.sound1 = new Howl({
  src: ['${resourcesFolderName}/city.mp3', '${resourcesFolderName}/city.ogg' ],
  autoplay: false,
  loop: true,
  volume: 1,
  onend: function() {
    console.log('Finished!');
  }
});

window.sound1.play();

// fade in sound 1 from 0 to 1 over 5 seconds. Comment the line below to disable fade. 
window.sound1.fade(0, 1, 2000);

Fade out:

window.sound1.fade(1, 0, 2000);

4 Likes