Does anyone have a snippet that uses the AudioToolBox framework that can be used to play a short sound? I would be grateful if you shared it with me and the rest of the community. Everywhere else I have looked doesn't seem to be too clear with their code.
Thanks!
Source: AudioServices - iPhone Developer Wiki
The AudioService sounds are irrespective of the the device volume controller. Even if the phone is in silent mode the Audio service sounds will be played. These sounds can only be muted by going Settings -> Sounds -> Ringer and Alerts.
Custom system sounds can be played by the following code:
Invoking the vibration in iPhone
Playing inbuilt system sounds.
I wrote a simple Objective-C wrapper around
AudioServicesPlaySystemSound
and friends:Lives here. For other sound options see this question.
Here is an easy example using the AVAudioPlayer:
This assumes a file called "click.caf" available in the main bundle. As I play this sound a lot, I actually keep it around to play it later instead of releasing it.