R – AVAudioPlayer to play short sounds on the iPhone

audioavaudioplayeriphone

I want to use AVAudioPlayer to play short sounds… because I have more control than System Sound.

I have several buttons which are hooked up to play several different short sounds.
Each sound file is about 1.5 – 2.0 seconds.

Everything works fine …except …I have to wait for the sound to stop before I can press the button and the sound will play again.

Currently the individual AVAudioPlayers are created on viewDidLoad … and the sounds are called to play when the buttons are pressed

I tried creating the players when the button is pressed… this solves the above problem… but after a while the app crashes… all sound stops working.

Any ideas?
Thanks
Jonathan

Best Answer

If AVAudioPlayer stops playing sounds, it is usually because there are too many player instances created, usually leaked. You should make sure you release some after you are done.

Related Topic