Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 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. var stepSize = (initialVolume || audio.volume) / (fadeDuration / 50);
  12. var volume = Math.max(0, audio.volume - stepSize);
  13.  
  14. audio.volume = volume;
  15.  
  16. if(audio.volume > 0) {
  17. // Keep up going until 11
  18. setTimeout(function() {
  19. fadeOut(audio, fadeDuration, initialVolume)
  20. }, 50);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement