If I place a sound in the setup function it will play when I hit the play button. However, if I navigate to the page through a link on my openprocessing.org homepage, then the sound won’t play. In that same scenario, if I place the sound in the draw function, though, it does play.
In this thread, someone pointed out that the you need to direct the browser to the canvas. I’m wondering why this particular nuance occurs though, depending on how you navigate to the page. Does anyone have any insight? (Thanks!)
Here’s the code:
let bell;
function preload() {
soundFormats('mp3');
bell = loadSound('doorbell.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
bell.setVolume(0.5);
bell.play();
clickNotice();
}
function clickNotice() {
textSize(12);
textAlign(CENTER);
textFont("Helvetica");
text("If sound doesn't play, click the canvas or hit the refresh button to activate the sketch", width / 2, height / 2);
}
With the Google Chrome thing it a standard for all platforms. I made a HTML game 2 months back and sounds within the game to play had to have the button clicked they would not play by default.