I am using p5.js loadSound to load the sound file and loadSound callback to point to function when the file is loaded.
In that function, I am using isLoaded() to check if the sound file is loaded or not, and when it is loaded it plays.
But the thing is that when I first start it, it works fine but then when I reload the page it does not work and gives an error "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page"
What I want to know is how I can let it not resume but start playing when the file is loaded
for(var i = 0; i < rain.rainAry.length; i++){
fill(205);
noStroke();
ellipse(rain.rainAry[i].x,rain.rainAry[i].y,3,10);
rain.rainAry[i].y += rain.rainAry[i].speed;
if(rain.rainAry[i].y > floorPos_y){
rain.rainAry.splice(i,1);
}
}
if(rain.raining){
for(var i = 0 ; i<clouds.length; i++){
rain.rainAry.push(
{
x : random(clouds[i].posX,clouds[i].posX + 100),
y : clouds[i].posY,
speed:random(8,10),
}
)
}
if(rainingSound.isLoaded()){
rainingSound.playMode('untilDone');
rainingSound.loop();
}
}
}```
and one more thing is that I am also calling drawRain() from function draw().[enter image description here][1]
[1]: https://i.stack.imgur.com/STzsu.png
link to another image.
thanks for help