IOS sound effects, ios sound plug-in
// AudioToolbox. framework is a set of C-language-based frameworks that use it to play Sound effects. Its essence is to register short audio into the System Sound Service. // System Sound Service restrictions: // 1. the audio playback time cannot exceed 30 s // 2. the data must be in PCM or IMA4 format. // The audio can also be played)
Method for playing audio:
/*** Callback function for playback completion ** @ param soundID system sound ID * @ param clientData data transferred during callback */void soundCompleteCallback (SystemSoundID soundID, void * clientData) {NSLog (@ "playback completed... ");}/*** play audio file ** @ param name audio file name */-(void) playSoundEffect :( NSString *) name {NSString * audioFile = [[NSBundle mainBundle] pathForResource: name ofType: nil]; NSLog (@ "% @", audioFile); NSURL * fileUrl = [NSURL fileURLWithPath: audioFile]; // 1. obtain the system sound ID SystemSoundID soundID = 0;/*** inFileUrl: Audio File url * outSystemSoundID: sound id (this function will add the sound file to the system audio service and return a long integer ID) */AudioServicesCreateSystemSoundID (_ bridge CFURLRef) (fileUrl), & soundID ); // if you need to perform some operations after playing, you can call the following method to register a callback function AudioServicesAddSystemSoundCompletion (soundID, NULL, NULL, soundCompleteCallback, NULL); // 2. play audio AudioServicesPlaySystemSound (soundID); // play audio // AudioServicesPlayAlertSound (soundID); // play audio and vibrate}