views:

633

answers:

3

Hi,

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

A: 

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.

mahboudz
A: 

You need to set the currentTime of the player to 0 before playing. Calling [player play] when it is already playing has no effect. player.currentTime = 0; [player play];

Dan
A: 

If you plan to use a lof of short sounds, you might want to think about switching to OpenAL. It's not a lot more complicated and you will save yourselve some trouble in more complicated audio settings later on.

There's a tutorial and some useful code available here.

Bersaelor