0

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);
}
  • Most I can tell is that I probably need to be doing something with the AVAudioSession class...but I don't know what... –  Jul 21 '19 at 23:07
  • Can you post a [mcve], either a link to a JSFiddle or to the P5 editor? – Kevin Workman Jul 22 '19 at 17:22
  • None of them will let me play external sound files so no? –  Jul 22 '19 at 19:07
  • I'm going crazy trying to figure out how. –  Jul 22 '19 at 19:08
  • Is there no webs server that will allow me to remotely call a sound file...? –  Jul 22 '19 at 19:24
  • Sorry, I'm not really sure what you mean. This is client-side code. I'm pretty sure it should work on JSFiddle or on the P5 web editor? – Kevin Workman Jul 22 '19 at 20:57
  • Thanks. Yes but the thing is I can't find any place hosting an mp3 let will let me play it back from the P5 editor it all says the server isn't responding. And JSFiddle doesn't seem to support P5 but this is the first time I've tried using it. Any ideas? –  Jul 22 '19 at 21:21
  • I would think the P5 editor would work fine, I'm not sure what that error means. And JSFiddle will work with any JavaScript, but you'd have to specify the libraries you're using. – Kevin Workman Jul 22 '19 at 21:35
  • https://jsfiddle.net/yrtvsj7w/3/ nothing works on my end tho –  Jul 23 '19 at 00:26
  • This seems to be a thing with WebAudio for a while now. See this SO article https://stackoverflow.com/questions/21122418/ios-webaudio-only-works-on-headphones/46839941#46839941 – fdcpp Jul 23 '19 at 13:33
  • Thanks that's very interesting, but there's no way that all the other javascript sites I see are following those instructions. Also did you see the thread I linked to above? There's a bunch of these types of threads of people asking how to PREVENT javascript from playing sound while an iPhone is on mute, so they're clearly not using any sort of work around... –  Jul 23 '19 at 20:27

0 Answers0