Can't get audio to play when loading

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.

1 Like

how about

song.resume();

also the file path you use?
what sytem you work on?

sounds\Changing it master.mp3

i would use

data/Changing_it_master.mp3

-a- does that path ‘sounds’ exist?
-b- usually inside a project use ‘data’ or ‘assets/doorbell.mp3’
-c- usually ‘/’ works, ‘\’ ???
-d- i am old style, for me a filename with a blank is a NONO

I tried song.resume(); and it still does nothing. The page is all white and it says “loading” in the top left.

The sound that I am using is a song that I made and it’s in the project folder which sits on my desktop. “sounds” is the directory I’m using to store said sounds. I right clicked in VScode and got the path name from there just in case. Maybe get rid of the spaces in the title? Or maybe move the sounds to Dropbox and link that way?

Ok so I uploaded the song to Dropbox and I am using their servers to hold it. It’s working using the Dropbox link.

Not sure why the music can’t be seen on my computer, so that’s odd.

1 Like

I do have the same problem…i used dropbox but of no use …pls help