Skip to content

Commit

Permalink
Add spacebar play / stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Redven-Biker committed Apr 24, 2020
1 parent 8539f66 commit 5a61f55
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion js/audiovisualisierung.js
Expand Up @@ -10,6 +10,7 @@ var loader;
var filename;
var fileChosen = false;
var hasSetupUserMedia = false;
var play = true;

var AudioContext = AudioContext || webkitAudioContext;
var context = new AudioContext();
Expand All @@ -24,8 +25,8 @@ $(function () {
});

function playSample() {

fileChosen = true;
sourceNode = null;
setupAudioNodes();

var request = new XMLHttpRequest();
Expand All @@ -47,6 +48,28 @@ function playSample() {
context.decodeAudioData(request.response, function(buffer) {
sourceNode.buffer = buffer;
sourceNode.start(0);

window.addEventListener("keydown", function(){
console.log(play);
switch (event.keyCode) {
case 32: //SpaceBar
if (play) {
setTimeout(()=> {
sourceNode.stop(0)
play = false;

},100)
} else {
setTimeout(()=> {
playSample()
play = true;
},100)
}
break;
}
return false;

}, false);
$("#freq, body").addClass("animateHue");
}, function(e) {
console.log(e);
Expand Down

0 comments on commit 5a61f55

Please sign in to comment.