使用AudioToolbox框架

时间:2011-07-14 06:39:16

标签: objective-c xcode audiotoolbox

我是XCode声音的新手,我正在使用声音效果。我想要一个声音效果,我知道对于声音效果你应该使用音频工具箱框架,代码是什么?我如何编码,变量和属性是什么?

1 个答案:

答案 0 :(得分:1)

首先,将声音转换为lei16 caf。 Here's a good write up解释了为什么要使用这种格式。

afconvert -d LEI16 -f caff /path/to/mp3-or-wav-or-whatever

以下是播放它的代码。

// I usually store "mySound" in an instance variable in the view
// controller init
CFURLRef mySoundUrl = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("my_sound"), CFSTR("caf"), NULL);
SystemSoundID mySound;
AudioServicesCreateSystemSoundID(mySoundUrl, &mySound);
CFRelease(mySoundUrl);

// Plays the sound.
AudioServicesPlaySystemSound(mySound);
相关问题