Skip to content

Commit

Permalink
now Play the Sound File whenever the X key is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehrad Kavian authored and Mehrad Kavian committed May 22, 2015
1 parent 860e87a commit 9303033
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
Binary file modified .DS_Store
Binary file not shown.
28 changes: 0 additions & 28 deletions test4

This file was deleted.

49 changes: 49 additions & 0 deletions test4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!doctype html>
<html lang="en-US" direction="ltr">
<head>
<meta charset="utf-8" />
<title>Web Audio Test 4 | Buffer And Load a Sound File</title>
<script src="jquery.js" ></script>

</head>
<body>
<div>

</div>
<script>
(function () {
var context = new AudioContext();
var electro;

var getAudio = new XMLHttpRequest();
getAudio.open("GET","snare.wav",true);
getAudio.responseType = "arraybuffer";

getAudio.onload = function () {
context.decodeAudioData(getAudio.response,function(buffer){ //decode file and then Store it in variable electro
electro = buffer;
});
}
getAudio.send();

window.addEventListener("keydown",onKeyDown);

function onKeyDown (e){
switch (e.keyCode) {
case 88 :
var playSound = context.createBufferSource();
playSound.buffer = electro;

playSound.connect(context.destination);
playSound.start(0);
break;
}
}

})();



</script>
</body>
</html>

0 comments on commit 9303033

Please sign in to comment.