Jump to content

Hey guys, 

 

I have been working on a project on my own to make a webpage where every alphabet button of the keyboard, when pressed makes a drum sound. All is going good and quite happy with what I have cane up with. 

 

My problem is, after some time, my browser (Chrome) crashes and obviously, the program stops execution. 

 

My first guess was that the RAM got filled up. I checked both the RAM and CPU usage and everything is good. 

 

Any ideas on how to fix this? 

 

--Code--

 

<html>
<head>
<script>
document.onkeypress = function(e) {
 
var kick = new Audio('biab_electro_kick_6.wav');
var clap = new Audio('biab_electro_clap_2.wav');
var snare = new Audio('biab_electro_snare_2.wav');
var hithat = new Audio('cl_hihat.wav');
var tom = new Audio('tom1.wav');
var popclap = new Audio('pop-clap.wav');
var dirsttom = new Audio('dirsttom.wav');
var shortsnare = new Audio('biab_electro_snare_3.wav');
var snapclap = new Audio('snapclap.wav');
var sfx1 = new Audio('harmonic_resonate.wav');
 
{ e = e || window.event; 
var charCode = e.charCode || e.keyCode, character = String.fromCharCode(charCode);
 document.getElementById('here').innerHTML=(charCode);
};
 
if (charCode == '115') {
 kick.play();
}
else if (charCode == '119'){
 clap.play();
}
else if (charCode == '101'){
 snare.play();
}
else if (charCode == '97'){
 hithat.play();
}
else if (charCode == '113'){
 tom.play();
}
else if (charCode == '100'){
 popclap.play();
}
else if (charCode == '122'){
 dirsttom.play();
}
else if (charCode == '120'){
 shortsnare.play();
}
else if (charCode == '99'){
 snapclap.play();
}
else if (charCode == '112'){
 sfx1.play();
}
else if (charCode == '32') {
 pause();
}
else {
return;
}
}
</script>
</head>
<body>
<p style="text-align:center;font-size:40px;" id="here">KeyCode</p>
<p style="text-align:center;font-size:40px;" id="counter"></p>
</body>
</html>
 
--End Code--
Link to comment
https://linustechtips.com/topic/502025-javascript-drumsdubstep-app/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×