Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. audio.addEventListener('playing', playingEventHandler);
  2.  
  3. function playingEventHandler() {
  4. audio.removeEventListener("playing", playingEventHandler);
  5. setTimeout(function() {
  6. fadeOut(audio, 3000);
  7. }, 10 * 1000);
  8. }
  9.  
  10. function fadeOut(audio, fadeDuration, initialVolume) {
  11. initialVolume = initialVolume || audio.volume;
  12. var stepSize = initialVolume / (fadeDuration / 50);
  13. var volume = Math.max(0, audio.volume - stepSize);
  14.  
  15. audio.volume = volume;
  16.  
  17. if(audio.volume > 0) {
  18. // Keep up going until 11
  19. setTimeout(function() {
  20. fadeOut(audio, fadeDuration, initialVolume)
  21. }, 50);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement