System sound & amp; warning sound & amp; vibration, menghua system sound

Source: Internet
Author: User

System sound & warning sound & vibration, menghua system sound

In order to attract the user's attention when issuing a warning, it is often accompanied by a prompt sound vibration. the system audio service provides an interface for playing audio files of no more than 30 seconds. The supported formats include CAF, AIF, and WAV.

IOS uses this API to support three types of notifications:

Sound: play a simple sound file immediately. If the phone is muted, the user cannot hear anything.

Reminder: the audio file is played. If the mobile phone is set to mute or vibrate, the user will be notified through vibrate.

Shake: Shake the phone. Do not consider other settings.

 

First, import the framework: AudioToolbox. import the framework file in the file as an excuse: # import <AudioToolbox/AudioToolbox. h>

Add three buttons to the xib file to implement the above three functions. Put the audio file in WAV format

// Sound

-(IBAction) buttonClick :( UIButton *) sender {// The warning sound is generally short. // declare the variable soundid to introduce the SystemSoundID soundid of the music file; // obtain the audio file path NSString * soundfile = [[NSBundle mainBundle] pathForResource: @ "soundeffect" ofType: @ "wav"]; // 1. the CFURLRef pointing to the file location. 2. pointer // _ bridge. convert the C language structure to the OC language object AudioServicesCreateSystemSoundID (_ bridge CFURLRef) [NSURL fileURLWithPath: soundfile], & soundid); // play the warning audio AudioServicesPlaySystemSound (soundid );}

// Reminder

-(IBAction) alertButtonClick :( UIButton *) sender {SystemSoundID soundid; NSString * soundfile = [[NSBundle mainBundle] pathForResource: @ "soundeffect" ofType: @ "wav"]; translate (_ bridge CFURLRef) [NSURL fileURLWithPath: soundfile], & soundid); // warning tone. When the user changes to mute, AudioServicesPlayAlertSound (soundid );}

// Vibrate

// Vibration-(IBAction) shakeButtonClick :( UIButton *) sender {SystemSoundID soundid; // no matter the mobile phone status, only the vibration AudioServicesPlaySystemSound (soundid );}

 

 

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.