首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >苹果手机上的NSSound

苹果手机上的NSSound
EN

Stack Overflow用户
提问于 2008-12-23 04:44:39
回答 2查看 4.2K关注 0票数 4

我一直在寻找如何在iphone上播放声音,我想大概是这样的:

代码语言:javascript
复制
[[NSSound soundNamed:@"cat.mp3"] play];

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2008-12-23 09:37:51

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

代码语言:javascript
复制
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];  
[audioPlayer play]; 

您只需要在使用它的类中使用这个导入:

代码语言:javascript
复制
#import <AVFoundation/AVAudioPlayer.h>
票数 10
EN

Stack Overflow用户

发布于 2008-12-23 04:48:21

音频工具箱系统的声音是伟大的短异步回放。

代码语言:javascript
复制
// 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文件。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/388192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档