I'm using AVAudioPlayer for music... and systemsound for sound effects... what happens sometimes is, the sound effects stop working while music is playing... seems to happen when I start my game... I notice that when I drop the volume on my iphone completely down to 0... then raise it up, the sound effects work for a second, then stop working again... Anyone else experience this? Appreciate any help. Thanks.
I've battled this as well. Here's what I think happens: The volume of a SystemSoundId effect is relative to the system (ringer) volume you had your phone at before starting the app. This means, in the extreme case of having the ringer all the way down for ex., that the volume switch wont affect SystemSoundId volume at all while your app is running. The AVAudioPlayer on the other hand is independent of the ringer volume and will have the full range of volume mapped to the volume switch. I haven't found any way around this and will notify my costumers to put the ringer volume up before launching the app.
Thanks dromsynt! That is very helpful. I wouldn't have figured it out on my own. At least now I know what's happening. I'll do the same thing, and probably put a message in my app description for the customers.
I ended up using SoundEngine.cpp from the CrashLanding app. Solved this problem plus removed a lot of lag time...
Watch out though with using SoundEngine.cpp, there are some memory leaks in it, which is why apple discourages developers from using it.
If your music is just a background track playing, AVAudioPlayer is good for just that. If you want music to change dynamically, I would recommend AudioQueues or AudioUnits. With the lag of AVAudioPlayer I wouldn't recommend it for sound effects. I've had good results with openAL, the openAL implementation is based on AudioUnits, so it has low latency and a low system usage. OpenAL is also well documented on the web, there are many tutorials to get you going.
Thanks. Is there a tutorial you'd recommend? I've seen a lot of openal stuff, but I've been a bit overwhelmed by it...
Some good tutorials: iPhone specific implementation. For a general understanding, the devmaster series. A few tips in the apple QA. I would advice to get your implementation working with wav files first and then switch to IMA4 or compressed formats. You can use AudioFileReadPackets to get the raw data (PCM) from a compressed file.