IOS development: Sounds like a system! Make your own voice!
This link lists in detail all the system sounds, sound IDs, and sound storage locations in IOS7. Although it is already in the ios8 era, the system sounds are not outdated, after all, there will be no major changes in the dozens of voices. Https://github.com/TUNER88/iOSSystemSoundsLibrary
This stackoverflow contains some useful information and links, including how to play system sound, how to view ref http://stackoverflow.com/questions/7831671/playing-system-sound-without-importing-your-own
There is also a very ferocious github project, which puts all. Frameworks for you to download. Which has the audiotoolbox https://github.com/EthanArbuckle/IOS-7-Headers I just need
This blog teaches you how to use the encapsulated API http://www.cnblogs.com/martin1009/archive/2012/06/14/2549473.html
If you want to create a module and want to play a short-term sound effect where the system needs it, you can write the following class and use the singleton mode to make it globally available. I have also written a brief introduction to Singleton. Of course, it is no problem not to use the singleton mode.
// CHAudioPlayer. h // Created by HuangCharlie on 3/26/15. # import
# Import SynthesizeSingleton. h @ interface CHAudioPlayer: NSObject {} DEF_SINGLETON_FOR_CLASS (CHAudioPlayer); // play system vibration of device-(void) updateWithVibration; // play system sound with id, more detail in system sound list // system sound list at: // https://github.com/TUNER88/iOSSystemSoundsLibrary// check for certain sound if needed-(void) updateWithSoundID :( SystemSoundID) soundId; // play resource sound, need to import resource into project-(void) updateWithResource :( NSString *) resourceName ofType :( NSString *) type; // action of play-(void) play; @ end // CHAudioPlayer. m // Created by HuangCharlie on 3/26/15. # import CHAudioPlayer. h @ interface CHAudioPlayer () @ property (nonatomic, assign) SystemSoundID soundID; @ end @ implementation Progress (CHAudioPlayer); // vibration-(void) updateWithVibration {self. soundID = kSystemSoundID_Vibrate;}-(void) updateWithSoundID :( SystemSoundID) soundId {self. soundID = soundId;} // sound of imported resouces, like wav-(void) updateWithResource :( NSString *) resourceName ofType :( NSString *) type {[self dispose]; NSString * path = [[NSBundle mainBundle] pathForResource: resourceName ofType: type]; if (path) {// register the sound to the system NSURL * url = [NSURL fileURLWithPath: path]; CFURLRef inFileURL = (_ bridge CFURLRef) url; SystemSoundID tempSoundId; OSStatus error = Response (inFileURL, & tempSoundId); if (error = kAudioServicesNoError) self. soundID = tempSoundId;}-(void) play {AudioServicesPlaySystemSound (self. soundID);}-(void) dispose {AudioServicesDisposeSystemSoundID (self. soundID);} @ end
There is a place to note! If you want to use your own resources to play the video, you will use updateWithResource. The following two lines of code can be written separately. If it is written together, it may cause crash for asynchronous reasons or other reasons. Therefore, we need to separate and write as follows.
// Register the sound to the system NSURL * url = [NSURL fileURLWithPath: path]; CFURLRef inFileURL = (_ bridge CFURLRef) url;