我一直在寻找如何在iphone上播放声音,我想大概是这样的:
[[NSSound soundNamed:@"cat.mp3"] play];但是NSSound在AppKit上...有什么建议吗?我知道有一个非常简单的答案,但今天我的搜索没有呈现任何结果……
发布于 2008-12-23 09:37:51
新的AVFoundation类是在iPhone上播放声音的最简单方法,尽管它仅适用于固件2.2:
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play]; 您只需要在使用它的类中使用这个导入:
#import <AVFoundation/AVAudioPlayer.h>发布于 2008-12-23 04:48:21
音频工具箱系统的声音是伟大的短异步回放。
// 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);我还没有让MP3s和AudioServicesPlaySystemSound一起工作。但它可以完美地播放AIF文件。
https://stackoverflow.com/questions/388192
复制相似问题