tags:

views:

419

answers:

1

I have the following simple code that plays a sound

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
    player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: soundPath] error:nil];
    player.volume = 1;
    player.numberOfLoops = 0;
[player prepareToPlay];
     [player play];

For some reason this code only plays in the simulator but not the device, any ideas?


Update: Actually I installed AvTouch, a sample app from Apple onto 3.0 and that doens't work either. Is something wrong with AVAudioPlayer?

+1  A: 

This can happen when the codec used by the audio file is available on OS X, but not the iPhone. It is also caused when the extension doesn't match the actual content of the file. Step through with the debugger and watch the debug console for codec errors or reconvert your file to a supported format with afconvert.

rpetrich
wouldn't the extension problem also exist for the simulator?
erotsppa
The simulator actually uses Mac OS's CoreAudio.framework rather than the reduced feature version available on the iPhone OS. This is the case with all frameworks that exist on both Mac OS and iPhone OS (CoreFoundation and Foundation are two other good examples)
rpetrich