Upload a media file is to easy to do you just have to create a variable (sound) and a function preload().In the function preload()
we will load the sound, by using sound= loadSound()
. Then when we want to put the sound somewere we will put sound.play()
.
In this example, when you click the sound is played and the background changes his color to red (while is playing).
var sound;
function setup(){
createCanvas(windowWidth, 500);
background(0,255,0);
}
function preload(){
img= loadImage('sound.mp3');
}
function mousePressed(){
sound.play()
}
function draw(){
if (sound.isPlaying()){
background(255,0,0);
}
else{
background(0,255,0);
}
}