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
: