Can't play sound

Hello,

I’m just learning to work with sound and I can’t get my sketch to work.

Here’s the code:

let mySound;

function preload() {
  soundFormats('mp3');
  mySound = loadSound('doorbell.mp3');
}

function setup() {
  mySound.setVolume(0.1);
  mySound.play();
}

I’m using openprocessing.org as my IDE. I’ve uploaded a file called doorbell.mp3. I get an error that says: “Uncaught ReferenceError: soundFormats is not defined”
How do I define a function that p5 made, and not me?

1 Like

http://p5js.org/reference/#/p5/soundFormats

1 Like

This function requires you include the p5.sound library. Add the following into the head of your index.html file:

<script language="javascript"

type="text/javascript" 

src="path/to/p5.sound.js"></script>

Hm…

Not sure whether we want to have the sound file in the asset folder

2 Likes

Thanks for this!

For those who might read this thread later: if working in openprocessing.org under ‘settings’ you need to turn on the p5.sound library.

2 Likes

you mean

  • openprocessing.org
  • p5.js mode
  • check revision ( now 0.9.0 )
  • enable sound lib
    ( here a photo )
    openprocessing_orp_P5js_p5sound
3 Likes

Yes, exactly. Thanks for adding more detail to my post :slight_smile:

1 Like