IOS development: use of system sound services in audio

Source: Internet
Author: User

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.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.