Skip to content

Commit

Permalink
start audio on user click
Browse files Browse the repository at this point in the history
  • Loading branch information
linahabazi committed Apr 24, 2024
1 parent b4be40c commit dcfc0d2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ var smoothing = 0.9;
var binCount = 1024;
var particles = new Array(binCount);
var qrcode;
let audioStarted = false;

function setup() {
c = createCanvas(window.innerWidth, window.innerHeight);
noStroke();

getAudioContext().suspend();

soundFile = loadSound('./media/dreams.mp3');
mic = new p5.AudioIn();
console.log(mic.getSources())
mic.start();
getAudioContext().resume()
// mic.amp(0.2);
// soundFile.amp(0.2);
fft = new p5.FFT(smoothing, binCount);
Expand Down Expand Up @@ -122,7 +124,12 @@ function onScreen(v) {
}

function mousePressed() {
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
// Start audio on user gesture
if (!audioStarted) {
userStartAudio();
audioStarted = true;
}
if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
let fs = fullscreen();
fullscreen(!fs);
}
Expand Down

0 comments on commit dcfc0d2

Please sign in to comment.