Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. $(document).ready(function(){
  2. drumInit(4);
  3. });
  4.  
  5. function drumInit(count){
  6. var samples = [];
  7. for(i = 0; i < count; i++) {
  8. sample = new Audio('sample-' + i + '.wav');
  9. samples.push(sample);
  10. }
  11. samples[2].volume = .3;
  12. samples[3].volume = .4;
  13.  
  14. $(document).keydown(function(e){
  15. switch(e.which) {
  16. case 90:
  17. samples[0].play();
  18. break;
  19.  
  20. case 88:
  21. samples[2].play();
  22. break;
  23.  
  24. case 67:
  25. samples[1].play();
  26. break;
  27.  
  28. case 86:
  29. samples[3].play();
  30. break;
  31.  
  32. default: return;
  33. }
  34. e.preventDefault();
  35. });
  36. }
  37.  
  38. case 90:
  39. samples[0].play();
  40. if(samples[0].playing) {
  41. samples[0].pause();
  42. samples[0].ended;
  43. samples[0].play();
  44. }
  45. break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement