Objective c Xcode 6-按下按钮播放声音
寻找一些帮助,试图让我的按钮播放声音。我查阅了50多篇教程,但都是过时的,不能使用新的Xcode。有人有好的学习资源吗?对于Objective-C来说,这是一个相当新的概念。我已经查阅了苹果的音频框架文档,我的脑细胞自杀了。如有任何正确方向的帮助或指示,将不胜感激。在viewController.h中 进口 进口 和viewController.mObjective c Xcode 6-按下按钮播放声音,objective-c,xcode,button,avfoundation,audiotoolbox,Objective C,Xcode,Button,Avfoundation,Audiotoolbox,寻找一些帮助,试图让我的按钮播放声音。我查阅了50多篇教程,但都是过时的,不能使用新的Xcode。有人有好的学习资源吗?对于Objective-C来说,这是一个相当新的概念。我已经查阅了苹果的音频框架文档,我的脑细胞自杀了。如有任何正确方向的帮助或指示,将不胜感激。在viewController.h中 进口 进口 和viewController.m @interface viewController : UIViewController @property (strong, nonatomic)
@interface viewController : UIViewController
@property (strong, nonatomic) AVAudioPlayer *player;
@end
-(void)yourButtonDidTap {
NSString *soundFilePath = [NSString stringWithFormat:@"%@/%@.mp3",
[[NSBundle mainBundle] resourcePath], soundName];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
error:nil];
_player.numberOfLoops = 0;
[_player play];
}