Sound won't work, AudioContext was not allowed to start?

I can’t seem to get the p5.sound.js to work correctly. The console error I keep getting is:
p5.sound.js:819 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
Tone.Context @ p5.sound.js:819
(anonymous) @ p5.sound.js:992
(anonymous) @ p5.sound.js:997
(anonymous) @ p5.sound.js:73
(anonymous) @ p5.sound.js:74
p5.sound.js:1002 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu

1 Like

I think the user needs to interact with the page/canvas first before it is allowed to play audio.
Just so that annoying pages don’t give un-expecting people heart attack by automatically playing audio :slight_smile:

I tried that and got hit with this :frowning:

p5.sound.js:1883 Access to XMLHttpRequest at ‘file:///C:/Users/coled/Documents/Programming/p5js/bubble%20sort/sounds/laser.mp3’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

p5.sound.js:1880 There was no response from the server at sounds/laser.mp3. Check the url and internet connectivity.
The error stack trace includes:
loadSound

I’d suggest running a local server that normally solves some problems. Normally browsers don’t do great loading files directly from the filesystem. http-server through npm is super simple or live-server there too. I think there’s one through python too that I’ve heard a lot of people use.

None the less that still might not fix this particular error you can read more about it on the Mozilla docs. And here is how to disable CORS for testing.

1 Like