首页 > 代码库 > System Sounds: Alerts and Sound Effects
System Sounds: Alerts and Sound Effects
#include <AudioToolbox/AudioToolbox.h>#include <CoreFoundation/CoreFoundation.h> // Define a callback to be called when the sound is finished// playing. Useful when you need to free memory after playing.static void MyCompletionCallback ( SystemSoundID mySSID, void * myURLRef) { AudioServicesDisposeSystemSoundID (mySSID); CFRelease (myURLRef); CFRunLoopStop (CFRunLoopGetCurrent());} int main (int argc, const char * argv[]) { // Set up the pieces needed to play a sound. SystemSoundID mySSID; CFURLRef myURLRef; myURLRef = CFURLCreateWithFileSystemPath ( kCFAllocatorDefault, CFSTR ("../../ComedyHorns.aif"), kCFURLPOSIXPathStyle, FALSE ); // create a system sound ID to represent the sound file OSStatus error = AudioServicesCreateSystemSoundID (myURLRef, &mySSID); // Register the sound completion callback. // Again, useful when you need to free memory after playing. AudioServicesAddSystemSoundCompletion ( mySSID, NULL, NULL, MyCompletionCallback, (void *) myURLRef ); // Play the sound file. AudioServicesPlaySystemSound (mySSID); // Invoke a run loop on the current thread to keep the application // running long enough for the sound to play; the sound completion // callback later stops this run loop. CFRunLoopRun (); return 0;}
System Sounds: Alerts and Sound Effects
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。