When developing an application, you sometimes want to add a sound to the application, such as a key tone or a drop-down menu sound, or increase the vibration. It is most convenient to use system sound services to play these short-term sounds.
Enter the topic.
Step 1: Overall understanding
1) required framework: audiotoolbox. Framework
2) related documents: multimedia programming guide
Step 2: Usage
1) create a systemsoundid object
Nsstring * Path = [[nsbundlemainbundle] pathforresource: @ "win"
Oftype: @ "WAV"];
Systemsoundid soundid;
Audioservicescreatesystemsoundid (
(_ Bridgecfurlref) [nsurlfileurlwithpath: path], & soundid );
2) play audio
Audioservicesplayalertsound (soundid); // play audio and vibrate
Audioservicesplaysystemsound (soundid); // only play audio
Step 3: Key Points Analysis
1) only play Vibration
Audioservicesplaysystemsound (ksystemsoundid_vibrate );
2) About _ Bridge
Apple uses the core foundation framework to provide APIs for many common components, such as URLs, arrays, and strings, this allows developers to directly write C code to implement relevant functions without using objective-C. Therefore, the cfurlref shown above is functionally equivalent to the nsurl pointer. From ios5, when using arc, by adding _ bridge to a specific name, the developer prompts the compiler to pass an objective-C object to an object under the c api. That's it.