I can’t figure out why P5.js won’t play sound on a muted iPhone. I’m new to coding but it seems like a lot of other javascript will play sounds on muted iPhones. Has anyone else wondered about this? I don’t understand why P5 sound won’t play but maybe it was an intentional decision? Is there anyway to override it? Most of what I find is posts from people trying to prevent sounds from playing on muted iPhone. So it seems weird… Here’s a post from stackoverflow trying to figure out how to PREVENT it from happening: Can Javascript detect if a mobile device is muted?
let imageVAR;
let soundVAR;
function windowResized()
{
resizeCanvas(windowWidth, windowHeight);
}
function preload()
{
imageVAR = loadImage('assets/face.png');
soundVAR = loadSound('assets/soundfx.mp3');
}
function setup()
{
var cnv = createCanvas(windowWidth, windowHeight);
cnv.style('display', 'block');
imageMode(CENTER);
frameRate(12);
}
function mousePressed()
{
getAudioContext().resume()
soundVAR.play();
}
function mouseMoved()
{
soundVAR.play();
}
function touchStarted()
{
getAudioContext().resume()
soundVAR.play();
}
function touchMoved()
{
soundVAR.play();
return false;
}
function draw()
{
var mX=mouseX
var mY=mouseY
image(imageVAR, mX, mY, imageVAR.width / 2,
imageVAR.height / 2);
}