tags:

views:

24

answers:

1

Hello.

I want to play a sound in my application. Nothing special, just a little WAV file. The file exists in the device in my main bundle, and I've got both the AVFoundation and AudioToolbox frameworks added. I have alternately tried using both of them, testing out every bit of sample code on the net for playing this sound. It won't work. So what else could be wrong, given that the file exists and the code snippet probably isn't the problem?

  1. Is it to do with imports? I import the necessary .h files for the frameworks at the top of the file.
  2. I've noticed that one of the methods requires there to be a delegate that implements a particular protocol. Is this necessary? Some examples require it, others don't. What do I need to implement for this?
  3. This fails to play the sound both on the device and the simulator. HAve I overlooked antyhing else?
+2  A: 
Is it to do with imports? 

No. Problems with imports will be apparent at build time.

I've noticed that one of the methods requires there to be a delegate that implements a particular protocol. Is this necessary?

No. The AVAudioPlayer delegate is optional.

This fails to play the sound both on the device and the simulator. HAve I overlooked antyhing else?

The most likely explanation is that the file is not being properly referenced. Alternatively, the file may be in a non-standard format for and the player chokes on it silently. Try testing with another file type.

TechZen
Oh god, an mp3 file worked. I guess the WAV is just encoded in a not-nice way or something.Bloody silent choking. Why can't they splutter loudly like everyone else! Thanks!
mtc06
Silent failures are evil. In this case, the player most likely interpreted the file as being empty owing to the file having improper offset value for the data block. Since its not illegal to have an empty data block, the player didn't complain.
TechZen