Skip to content

Commit 3d425cd

Browse files
authored
Update sketch.js
added a play button, was not working without because of iOS autoplay policies
1 parent 2dc80bb commit 3d425cd

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

sketch.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ let fft;
44
let volhistory = [];
55
let w;
66

7-
function toggleSong() {
8-
if (song.isPlaying()) {
9-
song.pause();
10-
} else {
11-
song.play();
12-
}
13-
}
147

158
function preload() {
169
song = loadSound("AlesisLive.mp3");
@@ -19,13 +12,15 @@ function preload() {
1912
function setup() {
2013
createCanvas(windowWidth, windowHeight);
2114
colorMode(HSB);
22-
song.play();
23-
button = createButton("pause");
24-
button.mousePressed(toggleSong);
2515
fft = new p5.FFT(0.9, 128);
2616
w = width/64
2717
}
2818

19+
function loaded() {
20+
button = createButton('play');
21+
button.mousePressed(togglePlaying);
22+
}
23+
2924
function draw() {
3025
background(0);
3126
let spectrum = fft.analyze();
@@ -39,3 +34,14 @@ function draw() {
3934
console.log(spectrum);
4035

4136
}
37+
38+
function togglePlaying() {
39+
if (!song.isPlaying()) {
40+
song.play();
41+
song.setVolume(0.3);
42+
button.html('pause');
43+
} else {
44+
song.stop();
45+
button.html('play');
46+
}
47+
}

0 commit comments

Comments
 (0)