views:

338

answers:

2

Hey everyone. The following is the code that I am using to play random sounds on the iPhone simulator. Some of the 30 or so sounds won't play and after some investigating I found out that the ones that weren't playing were longer than five seconds. Does anyone know why this is? Thanks in advance for your help!

NSString *path = [[NSBundle mainBundle] pathForResource:sound ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound (soundID);
+3  A: 

I believe there is a limit of 5 seconds (although some versions of the documentation claim 30 seconds) for sound being played using AudioServicesPlaySystemSound.

Alternatives are openAL, and Audio Queues. There's a useful tutorial on openAL here: http://benbritten.com/blog/2008/11/06/openal-sound-on-the-iphone/

Tom
+2  A: 

The limitation should be only in the iPhone Simulator, not on the device. On the device, AudioServicesPlaySystemSound should play the sounds up to 30 seconds.

I believe the sound format/compression is what causes the 'artificial' 5 second limit. Use afconvert on the Terminal to convert the sounds to the Apple suggested formats.

Dylan