Hey all, I would love to use p5.js for my audio/visual project, but I am having a hard time even getting a sound to load on setup. Here is my code:
let song;
function preload() {
song = loadSound('sounds\Changing it master.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
song.play();
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight)
}
function draw() {
background(0);
}
function mousePressed() {
getAudioContext().resume()
}
I was told that my mousePressed function would get rid of the error that is “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
(anonymous) @ p5.sound.js:1002
(anonymous) @ p5.sound.js:1095
(anonymous) @ p5.sound.js:73
(anonymous) @ p5.sound.js:74
p5.sound.js:1883 Access to XMLHttpRequest at ‘file:///C:/Users/Eddie%20Pearson/Desktop/first%20p5/soundsChanging%20it%20master.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.SoundFile.load @ p5.sound.js:1883
p5.SoundFile @ p5.sound.js:1748
p5.loadSound @ p5.sound.js:1803
(anonymous) @ p5.js:49781
preload @ app.js:5
(anonymous) @ p5.js:49748
p5 @ p5.js:50032
_globalInit @ p5.js:49418
p5.sound.js:1916 Uncaught TypeError: this._whileLoading is not a function
at p5.SoundFile._updateProgress (p5.sound.js:1916)
at XMLHttpRequest. (p5.sound.js:1828)
at p5.SoundFile.load (p5.sound.js:1883)
at new p5.SoundFile (p5.sound.js:1748)
at p5.loadSound (p5.sound.js:1803)
at p5. (p5.js:49781)
at preload (app.js:5)
at p5. (p5.js:49748)
at new p5 (p5.js:50032)
at _globalInit (p5.js:49418)
p5.SoundFile._updateProgress @ p5.sound.js:1916
(anonymous) @ p5.sound.js:1828
p5.SoundFile.load @ p5.sound.js:1883
p5.SoundFile @ p5.sound.js:1748
p5.loadSound @ p5.sound.js:1803
(anonymous) @ p5.js:49781
preload @ app.js:5
(anonymous) @ p5.js:49748
p5 @ p5.js:50032
_globalInit @ p5.js:49418
p5.sound.js:1880 There was no response from the server at soundsChanging it master.mp3. Check the url and internet connectivity.
The error stack trace includes:
loadSound”
could someone help please? I am very new to JS and libraries in general. I found some discussion on here about some of these errors, but the solutions did not help me.