1. AudioToolbox Overview
Through the AudioToolbox framework, you can register a short sound to the system sound service. The sound registered to the system sound service is called system sounds. It must meet the following conditions.
(1). the playback time cannot exceed 30 seconds
(2) the data must be in PCM or IMA4 stream format.
(3). It must be packaged into one of the following three formats: Core Audio Format (. caf), Waveform audio (.wav), or Audio Interchange File (. aiff)
Sound files must be placed under the Local folder of the device. Use the AudioServicesCreateSystemSoundID method to register this sound file.
2. Use AudioToolbox
#import
- (SystemSoundID)loadSound:(NSString *)name{ NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil]; NSURL *url = [NSURL fileURLWithPath:path]; SystemSoundID soundID; AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID); return soundID;}
_ ClickID = [self loadSound: @ "click the button. aiff"]; AudioServicesPlaySystemSound (_ clickID); // vibrate AudioServicesPlaySystemSound (kSystemSoundID_Vibrate );