简体   繁体   English

如何玩iPhone点击声音?

[英]How to play iPhone tap sound?

I have a button in my iPhone app that I'd like to have play the default "keyboard tap" sound when it's tapped. 我的iPhone应用程序中有一个按钮,我想在点击时播放默认的“键盘敲击”声音。 I've been able to play my own custom sounds easily enough, but is there any way to play a default system sound like this in my app? 我已经能够轻松地播放我自己的自定义声音,但有没有办法在我的应用程序中播放这样的默认系统声音?

The click sound you want is, I believe, in the sample app called SysSound. 我相信,你想要的咔嗒声是在名为SysSound的示例应用程序中。

http://developer.apple.com/iphone/library/samplecode/SysSound/ http://developer.apple.com/iphone/library/samplecode/SysSound/

usingsystemsounds usingsystemsounds
You must use the System Sound for this.The below might be usefule.Refer Multimedia Programming guide to know more. 您必须使用系统声音。下面可能是usefule.Refer多媒体编程指南了解更多。

CFBundleRef mainbundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef = CFBundleCopyResourceURL
                                     (mainbundle, CFSTR("tap"), CFSTR("aif"), NULL);
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject);

Also you can use the inbuilt system sounds by 您也可以使用内置系统声音

AudioServicesPlaySystemSound(1100);

我找到了这个 ,这听起来像你在找什么。

Nothing public. 什么都不公开。 There's probably an answer if you're willing to dive into private APIs, but this is strongly discouraged (as you will likely break future compatibility, and may get rejected from the app store). 如果您愿意深入私人API,可能会有一个答案,但强烈建议不要这样做(因为您可能会破坏未来的兼容性,并可能会被应用商店拒绝)。

There's an example on the iPhone Dev Center web site for playing short-duration sounds (5 seconds or less), You can use that code to play any sound you want. iPhone开发中心网站上有一个示例,用于播放短时间的声音(5秒或更短),您可以使用该代码播放您想要的任何声音。 Find a click sound doing a google search and use that. 找到点击声音进行谷歌搜索并使用它。 That's all you need. 这就是你所需要的。

http://developer.apple.com/iphone/library/codinghowtos/AudioAndVideo/index.html#PLAY_SHORT_SOUNDS_AND_ALERTS_2 http://developer.apple.com/iphone/library/codinghowtos/AudioAndVideo/index.html#PLAY_SHORT_SOUNDS_AND_ALERTS_2

AudioServicesCreateSystemSoundID (fileURL, soundID);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM