3

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?

JOM
  • 8,139
  • 6
  • 78
  • 111
  • Sorry if I'm stating the obvious, but is the hardware switch on your iPhone on silent? – Michael Jan 14 '10 at 13:26
  • When I said "I can hear keyclicks and music from iTunes" that means iPhone is in non-silent mode. Good to check, anyway... – JOM Jan 15 '10 at 07:53

4 Answers4

3

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
coneybeare
  • 33,113
  • 21
  • 131
  • 183
  • Most likely I converted in wrong way... Still can't understand why emulator would play those sounds and real device not. Emulator is supposed to emulate real device, right? That's the purpose of emulator! – JOM Jan 15 '10 at 07:55
  • 1
    wrong. The simulator is not an emulator. It does not limit your network speed, cpu speed ram or anything else. It is merely a visual tool to see how you app would look and interact with touches. It is probably because your computer has many more codecs on it than the select few shipped with the the iphone – coneybeare Jan 15 '10 at 13:02
2

Just as a sidenote - I was having the exact same problem and spent probably close to an hour on converting files to the correct format, etc.. Yet the problem was the "mute" switch on the iPad. So even though the volume was up, and I could hear other sounds on the iPad, because the mute switch was turned on, it wasn't playing system sounds.

To add to the confusion, this app uses text-to-speech and the volume coming from the transcription was perfectly fine, it was only the sounds coming from AudioServicesPlaySystemSound() that I couldn't hear.

TheJerkMan24
  • 272
  • 4
  • 9
0

kind of a long shot, but remember that the phone's file system is case sensitive, while the mac's usually isn't. Double check your file name

justin
  • 868
  • 1
  • 5
  • 11
0

Found an easier solution: use AIF sound files:

  • Click iTunes > Preferences
  • Click on "General" tab
  • Click "Import Settings" button
  • In "Import Using" dropdown, choose "AIFF Encoder"
  • Save your changes
  • Select your sound files and choose "Create AIFF version"

Here's code I'm using, together with SoundEffect.h and SoundEffect.m from Apple sample BubbleLevel:

NSBundle *mainBundle = [NSBundle mainBundle];
buzzerSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"buzzerSound" ofType:@"aif"]];
[buzzerSound play];

Now same code - and sound effects - work in both emulator and hardware. Btw don't forget to switch back your original iTunes settings!

JOM
  • 8,139
  • 6
  • 78
  • 111