在iOS中按一个按钮播放声音

use*_*826 2 audio objective-c playback ios

我正在尝试创建一个应用程序,当您触摸按钮(实际上是我导入的.png图像)时,会播放声音.有人知道怎么做这个吗?我正在使用xcode 4.5.2

ank*_*dav 6

NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"your audio file name" ofType:@"wav"]];
AVAudioPlayer *click  = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile  error:nil];
[click play];
Run Code Online (Sandbox Code Playgroud)

在单击按钮的操作上编写此代码.还要将AudioToolbox/AudioToolbox.h和AVFoundation/AVFoundation.h框架添加到您的班级.