Guest User

Untitled

a guest
Jun 23rd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. var audio = {
  2. sounds: {},
  3.  
  4. add : function(file, autoplay) {
  5. if(typeof(file) == 'array') {
  6. for(var i = 0; i < file.length; i++)
  7. this.add(file[i]);
  8. }
  9.  
  10. var sound = document.createElement('audio');
  11.  
  12. if(autoplay)
  13. sound.autoplay = true;
  14.  
  15. sound.setAttribute('src', 'sounds/' + file);
  16. sound.load();
  17.  
  18. this.sounds[file] = sound;
  19. insertBeforeScript(sound);
  20.  
  21. log('Add Sound: ' + file);
  22. },
  23. play : function(file) {
  24. this.sounds[file].play();
  25. log('Play Sound: ' + file);
  26. }
  27. }
Add Comment
Please, Sign In to add comment