tags:

views:

755

answers:

3

I'm developing an iPhone game and currently using AVAudioPlayer for playing background music and sounds. From what I've been reading, I'm not sure if that's the best way, but other alternatives seem to be overly complex.

Is there any good open source framework that works on the iPhone and I can integrate? I only need to control the volume and trigger sounds based on different game events.

Clarification: AVAudioPlayer meets my needs for playing one sound, but I'd like a wrapper class where I can set up multiple sounds and have them play based on some key.

+3  A: 

It's not clear from your message whether AVAudioPlayer meets your needs. On the one hand you didn't mention any shortcomings you've encountered, but on the other hand your asking for alternatives suggests there are some.

If AVAudioPlayer does meet your needs, why make life difficult?

If AVAudioPlayer does not meet your needs, you need to explain what else you need before anyone can do anything but guess at what you're looking for.

Tom Harrington
AVAudioPlayer does meet my needs, but it's useful only for playing one sound. I'd like a wrapper where I can set up several sounds, and have them play based on different events.Before code it myself, I wondered if there was an alternative.
pgb
+2  A: 

The sound engine that Apple includes in their moon lander sample code application allows for playing multiple sounds at a time and everything.

Ed Marty
This sample code is no longer included in SDK 2.2. Do you know if there's a reason why the pulled it?
pgb
+2  A: 

You can use AVAudioPlayer. Each of your sounds will be a different instance of that class. Hold onto all the sounds (players) in a dictionary or an array. You can then easily play each by indexing off the array or getting with a key from the dict. Each sound can have it's own volume, or you can iterate the array or dict to set all volumes to whatever levels you like.

Couple of points to remember: 1. if you have to play the sounds in a timely manner, then use the -prepareToPlay method right after loading from file. 2. if you stop a sound, then -prepareToPlay is undone. If you pause a sound, then before you play it again, make sure you set the currentTime property to 0 so the sound starts from the beginning.

mahboudz