# Can't get audio to play when loading

**URL:** <https://discourse.processing.org/t/cant-get-audio-to-play-when-loading/10567>\
**Category:** Libraries\
**Created:** [April 23, 2019, 1:20pm UTC](https://discourse.processing.org/t/cant-get-audio-to-play-when-loading/10567 "2019-04-23T13:20:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indieminor](https://avatars.discourse-cdn.com/v4/letter/i/8797f3/32.png) [@Indieminor](https://discourse.processing.org/u/Indieminor)\
**Post date:** [April 23, 2019, 1:20pm UTC](https://discourse.processing.org/t/cant-get-audio-to-play-when-loading/10567/1 "2019-04-23T13:20:07Z")

</div>

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:

```auto
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](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](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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 23, 2019, 2:01pm UTC](https://discourse.processing.org/t/cant-get-audio-to-play-when-loading/10567/2 "2019-04-23T14:01:08Z")

</div>

> [@Indieminor](#):
>
> getAudioContext().resume()

how about

```auto
song.resume();

```

* * *

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

```auto
sounds\Changing it master.mp3

```

i would use

```auto
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

---

<div class="post-metadata">

**Author:** ![Indieminor](https://avatars.discourse-cdn.com/v4/letter/i/8797f3/32.png) [@Indieminor](https://discourse.processing.org/u/Indieminor)\
**Post date:** [April 23, 2019, 5:04pm UTC](https://discourse.processing.org/t/cant-get-audio-to-play-when-loading/10567/3 "2019-04-23T17:04:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Indieminor](https://avatars.discourse-cdn.com/v4/letter/i/8797f3/32.png) [@Indieminor](https://discourse.processing.org/u/Indieminor)\
**Post date:** [May 6, 2019, 1:19pm UTC](https://discourse.processing.org/t/cant-get-audio-to-play-when-loading/10567/4 "2019-05-06T13:19:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Yash](https://avatars.discourse-cdn.com/v4/letter/y/f17d59/32.png) [@Yash](https://discourse.processing.org/u/Yash)\
**Post date:** [July 22, 2019, 7:27pm UTC](https://discourse.processing.org/t/cant-get-audio-to-play-when-loading/10567/5 "2019-07-22T19:27:21Z")

</div>

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