Have few short <strong>sound effect</strong> samples, which play <strong>just fine in emulator, but not at all in real iPhone</strong> 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?
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
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.
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
Found an easier solution: <strong>use AIF sound files</strong>:
<li>Click iTunes > Preferences</li>
<li>Click on "General" tab</li>
<li>Click "Import Settings" button</li>
<li>In "Import Using" dropdown, choose "AIFF Encoder"</li>
<li>Save your changes</li>
<li>Select your sound files and choose "Create AIFF version"</li>
Here's code I'm using, together with SoundEffect.h and SoundEffect.m from <strong>Apple sample BubbleLevel:</strong>
NSBundle *mainBundle = [NSBundle mainBundle]; buzzerSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"buzzerSound" ofType:@"aif"]]; [buzzerSound play];
Now same code - and sound effects - <strong>work in both emulator and hardware</strong>. Btw don't forget to switch back your original iTunes settings!