2012年8月27日 星期一

Simple iOS audio playback

http://gregheo.com/blog/ios/simple-audio/


說來慚愧

寫了一段時間的IOS了  現在才大概知道怎麼撥簡短的聲音+震動

XD


// need this include file and the AudioToolbox framework
#import <AudioToolbox/AudioToolbox.h>

// also need an instance variable like so:
// SystemSoundID sound1;

NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"sample"
                                          withExtension:@"caf"];
AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &sound1);
AudioServicesAddSystemSoundCompletion(sound1, NULL, NULL, systemAudioCallback, NULL);
AudioServicesPlaySystemSound(sound1); // or...
AudioServicesPlayAlertSound(sound1);
void systemAudioCallback(SystemSoundID soundId, void *clientData)
{
    NSLog(@"System sound finished playing!");
}
AudioServicesRemoveSystemSoundCompletion(sound1);    
AudioServicesDisposeSystemSoundID(sound1);

沒有留言:

張貼留言