How hard is it to do that? Someone told me that it’s incredible hard playing audio on the iPhone. Can’t really believe it. But he said playing one is hard, but playing two or three at same time is incredible hard. Sounded scary. What can you guys say about this?
What I want to do: I have about 10 CAF files with little blips and beeps and button press sounds. Nothing really special. Now I want to play these files every time something happens. And several things could happen at same time. So it could happen that playbacks overlap.
Maybe there’s a framework I can use for doing this?
Playing small blips, beeps, etc (sounds less than 30 seconds) is actually pretty easy – this is exactly what AudioServices is meant to do. You need to first obtain an ID for each sound, using something like this:
You’ll then hold onto that ID until you need to use it, and then you can play the sound simply using this line:
There’s also
AudioServicesPlayAlertSound()that will behave slightly differently depending on the device’s capability, such as vibrating an iPhone if the device is configured to by the user. You should read Apple’s notes in the docs for a more complete explanation.Note that you have minimal control over the playback of sounds using AudioServices – you can’t stop them, control the volume, etc. AudioServices is only meant for alert sounds and other such short beeps and blips. There is, of course, AVAudioPlayer but its a bit more heavyweight than what you need in this case. You’re probably better off sticking with AudioServices unless one of its constraints makes it unusable.
You need to link AudioToolbox.framework in order to use these functions.
P.S. Welcome to Stack Overflow! Don’t forget to read the FAQ and mark accepted answers for your questions (if they’re good answers worth accepting, of course).