单击按钮时播放iPhone相机快门声

时间:2011-03-25 10:00:49

标签: iphone ios camera avfoundation

单击按钮时如何从iPhone播放快门声?

4 个答案:

答案 0 :(得分:11)

您可以使用AudioToolbox和纯魔法数字1108,如下所示:

夫特:

import AudioToolbox
AudioServicesPlaySystemSound(1108)

目标-C:

#import <AudioToolbox/AudioToolbox.h>
AudioServicesPlaySystemSound(1108);

这是full list of these pure magical ids

答案 1 :(得分:7)

1)在线搜索相机快门波形文件。如果使用.wav编辑器有点长,你可以修剪这个 http://www.freesound.org/people/Nathan_Lomeli/sounds/79190/

2)将它命名为shutter.wav并将其与您的其他资源一起放入您的开发目录。

3)在视图的.h文件中定义声音

@interface  myViewController : UIViewController {
    SystemSoundID SoundID;
}

4)在View的“viewDidLoad”事件中加载文件:

  //load a sound wav file to use for the shutter
NSURL *buttonURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"shutter" ofType:@"wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)buttonURL, &SoundID);

5)在你的button_click事件中:

   //play then shutter.wav sound
AudioServicesPlaySystemSound(SoundID);

答案 2 :(得分:0)

您没有指定编程语言,但我们现在假设ObjC而不是Monotouch或任何其他第三方框架。

来自AV框架的AVAudioPlayer是你的朋友。

请参阅Apple的documentation

或者在这里搜索AVAudioPlayer,你会发现很多例子。 不过,您必须从某个地方获取快门声音文件,但您可以使用在Google上找到的任何公共快门WAV。

如果您真的想使用相机,拍摄照片时会自动播放快门声,但我怀疑这是您想要的。

答案 3 :(得分:0)

有些声音可以选择这些位置:/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds /系统/库/声音

相关问题