IOS sound effects, ios sound effects

Source: Internet
Author: User

IOS sound effects, ios sound effects
IOS sound effects

Sound effects can also be short audios. Generally, the playback time in the program is 1 ~ 2 seconds.

Embellish the app to improve the overall user experience

The audio file only needs to be loaded once.

Sample Code:

/// ViewController. m // CX sound effect /// Created by ma c on 16/4/15. // Copyright©2016 bjsxt. all rights reserved. // # import "ViewController. h "# import <AVFoundation/AVFoundation. h> @ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad];}-(void) touchesBegan :( NSSet <UITouch *> *) touches withEvent :( UIEvent *) event {// obtain the full path NSURL * url of the audio file = [[NSBundle mainBundle] URLForResource: @ "cx.wav" withExtension: nil]; // load the sound file and create the sound ID (SoundID, one ID corresponds to one sound file) SystemSoundID soundID = 0; AudioServicesCreateSystemSoundID (_ bridge CFURLRef) url, & soundID ); // play the audio file // both of the following functions can be used to play the audio file. The first function is accompanied by a vibrating AudioServicesPlayAlertSound (soundID); // AudioServicesPlaySystemSound (soundID) // pass the ID of the audio file to be destroyed to it. // AudioServicesDisposeSystemSoundID (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);} void soundCompleteCallback (SystemSoundID soundID, void * clientData) {NSLog (@ "playback completed... ");} @ end

:

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.