System Sound Services Reference
Framework | AudioToolbox/AudioToolbox.h |
Declared in | AudioServices.h |
Overview
System Sound Services provides a C interface for playing short sounds and for invoking vibration on iOS devices that support vibration.
You can use System Sound Services to play short (30 seconds or shorter) sounds. The interface does not provide level, positioning, looping, or timing control, and does not support simultaneous playback: You can play only one sound at a time. You can use System Sound Services to provide audible alerts. On some iOS devices, alerts can include vibration.
For usage information for iOS, refer to “Using Audio” in Multimedia Programming Guide.
Functions by Task
Creating and Disposing of System Sound Objects
- AudioServicesCreateSystemSoundID
- AudioServicesDisposeSystemSoundID
Playing Sounds
- AudioServicesPlayAlertSound
- AudioServicesPlaySystemSound
Adding and Removing System Sound Callbacks
- AudioServicesAddSystemSoundCompletion
- AudioServicesRemoveSystemSoundCompletion
Managing System Sound Services Properties
- AudioServicesGetPropertyInfo
- AudioServicesGetProperty
- AudioServicesSetProperty
例子
SystemSoundID plop_id, batt_id;
CFURLRef plop_url = CFBundleCopyResourceURL (CFBundleGetMainBundle(),
CFSTR ("plop"),
CFSTR ("wav"),
NULL); //plop.wav是添加到bundle的声音文件
// Create a system sound object representing the sound file
AudioServicesCreateSystemSoundID (plop_url, &plop_id);
CFRelease(plop_url);
AudioServicesPlaySystemSound(plop_id); //播放声音
//最后在dealloc中,释放资源
AudioServicesDisposeSystemSoundID (plop_id);