iphoneaudiocaf

Sound working in emulator, not in real iPhone


Have few short sound effect samples, which play just fine in emulator, but not at all in real iPhone 3GS. Here's the code, about as-is from Apple SysSound sample:

CFBundleRef mb = CFBundleGetMainBundle ();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL
    (mb, CFSTR("mySound"), CFSTR ("caf"), NULL);

SystemSoundID sid;
AudioServicesCreateSystemSoundID(soundFileURLRef, &sid);
AudioServicesPlaySystemSound(sid);

When using iPhone, I can hear keyclicks and music from iTunes (not trying to use at same time as playing my sound) - but cannot hear my sound at all. Vibra works ok, so even Framework should be set up correctly.

Tried even the SoundEffect.h/m sample code, no change. Used same sound files, but shouldn't CAF be ok, especially when it plays in emulator?

What can I try next?


Solution

  • Try converting to a different format such as wav or mp3, then play again. If you want to use caf, Make sure you are formatting the caf correctly in Terminal.app:

    afconvert -f caff -d ima4 mysound.wav