NSSound在iPhone上

问题描述:

我一直在寻找了一段时间如何在iPhone上播放声音,我认为这是沿着线的东西:NSSound在iPhone上

[[NSSound soundNamed:@"cat.mp3"] play]; 

但NSSound是上了AppKit ...有什么建议么 ?我知道这是一个非常简单的答案,但今天我的搜索没有呈现任何结果...

新AVFoundation类播放声音在iPhone上最简单的方法,但它仅用于固件2.2:

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
[audioPlayer play]; 

你只需要这个进口在使用它的类:

#import <AVFoundation/AVAudioPlayer.h> 
+0

非常好,今晚我会试试这个的 – webclimber 2008-12-23 19:43:04

音频工具箱系统的声音非常适合短暂的异步播放。

// 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与AudioServicesPlaySystemSound一起使用。但它完美地播放AIF文件。