tags:

views:

1756

answers:

3

I have a list of short wav files. Two of these files do not play on either the simulator or the device itself. All are wav files 1 second long.

This is how I play the files

SystemSoundID soundID;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];

NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
AudioServicesCreateSystemSoundID((CFURLRef)fileUrl, &soundID);
AudioServicesPlaySystemSound(soundID);

Can someone please tell me what the problem could be. Thanks.

P.S. When I view the files in Finder, the files not playing show the default player as QuickTime and the others show the default player as iTunes if that helps in any way.

The solution as Alan suggested is to use AIFF files. To convert wav to AIFF, open the sound file in iTunes. In iTunes, select Preferences->General->Import Settings->Import using AIFF Encoder. Select the sound file and in Advanced menu option select the option "Create AIFF version"

+1  A: 

See this question http://stackoverflow.com/questions/258006/trying-to-play-sound-through-iphone-simulator

I've had a lot more success with .aiff files.

It would be good to know what exactly AudioServicesCreateSystemSoundID is checking when a file is passed to it.

Alan
Thanks. AIF files work. But I still don't understand why some wavs would work and some won't.
lostInTransit
+3  A: 

The iPhone only supports the following codecs:

  • AMR (Adaptive Multi-Rate, a speech codec)
  • iLBC (internet Low Bitrate Codec, also a speech codec)
  • IMA/ADPCM (also known as IMA-4)
  • Linear PCM
  • µLaw and aLaw

Your WAV files may contain audio that is in a different format, so even though the iPhone supports WAV files, it might not support your specific WAV file.

The best option is normally to use the command line program "afconvert" to convert everything to CAF files (which is Apple's default format). e.g.:

afconvert sound1.wav sound1.caf

the full set of conversion options can be listed by running:

afconvert -h

This conversion will be lossless from most formats. The CAF file format is normally the fastest and lowest overhead to use on the iPhone.

Matt Gallagher
A: 

I used AudioServicesPlaySystemSound to play mp3 in my app. I can hear sound in simulator but not in my ipod Touch pls help.......

Hi Hi