IOS sound effects, ios sound plug-in

Source: Internet
Author: User
Tags file url

IOS sound effects, ios sound plug-in

// AudioToolbox. framework is a set of C-language-based frameworks that use it to play Sound effects. Its essence is to register short audio into the System Sound Service. // System Sound Service restrictions: // 1. the audio playback time cannot exceed 30 s // 2. the data must be in PCM or IMA4 format. // The audio can also be played)

Method for playing audio:

/*** Callback function for playback completion ** @ param soundID system sound ID * @ param clientData data transferred during callback */void soundCompleteCallback (SystemSoundID soundID, void * clientData) {NSLog (@ "playback completed... ");}/*** play audio file ** @ param name audio file name */-(void) playSoundEffect :( NSString *) name {NSString * audioFile = [[NSBundle mainBundle] pathForResource: name ofType: nil]; NSLog (@ "% @", audioFile); NSURL * fileUrl = [NSURL fileURLWithPath: audioFile]; // 1. obtain the system sound ID SystemSoundID soundID = 0;/*** inFileUrl: Audio File url * outSystemSoundID: sound id (this function will add the sound file to the system audio service and return a long integer ID) */AudioServicesCreateSystemSoundID (_ bridge CFURLRef) (fileUrl), & 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); // 2. play audio AudioServicesPlaySystemSound (soundID); // play audio // AudioServicesPlayAlertSound (soundID); // play audio and vibrate}

 

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.