In ios development, sometimes we need to play a certain kind of sound frequently, such as refreshing prompts on Weibo and QQ messages. For these short and frequently-played audios, it is best to add it to system sound. Note: The audio file to be played cannot exceed 30 seconds. It must be in IMA/ADPCM format [in linear PCM or IMA4 (IMA/ADPCM) format. caf. aif. wav file 1. Custom system sound copy code // the audio file address NSString * urlPath = [[NSBundle mainBundle] pathForResource: @ "end_refreshing" ofType: @ "wav"]; NSURL * url = [NSURL fileURLWithPath: urlPath]; // declare the ID of the audio file to be played [unsigned long] SystemSoundID; // create a system sound, returns an ID AudioServicesCreateSystemSoundID (_ bridge CFURLRef) (url), & ID); copy the code 2. Play the custom system sound Based on the ID passed in when the custom system sound is defined. // play the custom system sound AudioServicesPlaySystemSound (ID) based on the ID ); 3. Sometimes we need to do something when playing the video, for example, continue to play the next audio or remind the user, or decide not to use the audio ID any more, you can remove the audio ID copy code from the following function // The operation performed after the playback is complete/** parameter description: * 1. the ID of the custom system sound has just been played * 2. run Loop executed by the callback function (playFinished, NULL indicates the main run loop * 3. The run loop mode where the callback function is executed. NULL indicates the default run loop mode * 4. The function to be called * 5. input parameters, this parameter will be passed into the callback function */AudioServicesAddSystemSoundCompletion (ID, NULL, NULL, & p LayFinished, (_ bridge void *) (self);} @ implementation and @ interface external customization of a function, and then input the void playFinished (SystemSoundID ssID, void * clientData) {unsigned long ID = ssID; // The ssID cannot be printed directly as a parameter. An NSLog (@ "playback completed-input ID is-% lu, the passed parameter is % @ ", ID, clientData); // The AudioServicesRemoveSystemSoundCompletion (ID) function executed after the removal is complete ); // release the custom system sound AudioServicesDisposeSystemSoundID (ID) according to the ID;} copy the code to call the pre-defined function playfini after the playback is complete. Shed (), continue to do something you want, but don't forget that C language functions in ARC need to manage the memory by yourself. So here, we need to remove the newly added operation after callback is complete, and make sure that when you no longer need to play the audio of this ID, clear all resources corresponding to the audio of this ID. 4. After completing the above steps, you can simply use the custom system sound to play simple and frequent audio files. Note: 1> You must wait until the playback is complete to clear all resources corresponding to the ID. That is to say, if you do not want to use the audio, you can call the playFinished function after the completion) to clear resources, as shown in the preceding example. But in general, since most of the information added to the system sound is frequently used, it can be cleared when the program ends or a controller is destroyed. 2> if you call AudioServicesDisposeSystemSoundID (ID) immediately after AudioServicesPlaySystemSound (ID), you will not be able to hear any sound and will not call the function after playback. This is because, all operations of system audio playback are performed outside the main thread. When the main thread cleans up the audio, the audio cannot be found if it tries to play the audio corresponding to the ID.