views:

139

answers:

3

I'm using an AVAudioPlayer to play a mono AIFF file from my app's Documents directory.

On the simulator, [player play] returns YES and I hear the file playing. On the device the play method returns NO and nothing happens. I grabbed the file via the Organizer - it plays back fine on my Mac and seems to be well-formed. I realize the simulator can access codecs that aren't available on the iPhone, but that shouldn't matter in this case, should it?

I'm at a loss as to how to debug this. Any suggestions?

A: 

Create a delegate to the audio player, and override -audioPlayerDecodeErrorDidOccur:error: to see if any error happens.

KennyTM
I should have mentioned that I already did this. It never gets called. Since [player play] is returning 0 I suspect it never even gets that far.
Calhoun
A: 

Make sure you do not use an absolute path to the audio file. When you move to device, the paths change. You need to get the path to the documents folder using the standard methods and then add the relative path to your audio file. That way you get a correct path regardless of the hardware or other changes.

TechZen
Thanks for your suggestion. But I am indeed getting the path dynamically. The file was recorded (using the Audio Queue API) by the app, and I've confirmed that the paths used for recording and playback are identical.
Calhoun
A: 

I asked this question on Apple's forum and someone there asked if I had activated an Audio Session. I hadn't, and doing so fixed my problem.

Calhoun