iphone上的声音
我一直在寻找如何在iphone上播放声音,我认为这是一个大致的思路:iphone上的声音,iphone,cocoa-touch,core-audio,Iphone,Cocoa Touch,Core Audio,我一直在寻找如何在iphone上播放声音,我认为这是一个大致的思路: [[NSSound soundNamed:@"cat.mp3"] play]; 但是NSSound在应用程序包上。。。有什么建议吗?我知道有一个非常简单的答案,但今天我的搜索没有呈现任何结果…音频工具箱系统的声音非常适合短时间异步播放 // Initialize CFBundleRef mainBundle; mainBundle = CFBundleGetMainBundle (); // Init each sound
[[NSSound soundNamed:@"cat.mp3"] play];
但是NSSound在应用程序包上。。。有什么建议吗?我知道有一个非常简单的答案,但今天我的搜索没有呈现任何结果…音频工具箱系统的声音非常适合短时间异步播放
// Initialize
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();
// Init each sound
CFURLRef tapURL;
SystemSoundID tapSound;
tapURL = CFBundleCopyResourceURL(mainBundle, CFSTR("tap"), CFSTR("aif"), NULL);
AudioServicesCreateSystemSoundID(tapURL, &tapSound);
// Play the sound async
AudioServicesPlaySystemSound(tapSound);
我还没有得到MP3来使用
音频服务SplaySystemSound
。但是它可以完美地播放AIF文件。新的AVFoundation类是在iPhone上播放声音的最简单方法,尽管它仅适用于固件2.2:
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
您只需要在使用该导入的类中使用它:
#import <AVFoundation/AVAudioPlayer.h>
#导入
太好了,我今晚就试试这个