Reputation: 43
I am trying to make an app that when you touch a button (actually a .png image that I imported) a sound plays. Does anybody know how to do this? I am using xcode 4.5.2
Upvotes: 2
Views: 8345
Reputation: 363
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"your audio file name" ofType:@"wav"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click play];
Write this code on action of your button click.Also Add AudioToolbox/AudioToolbox.h and AVFoundation/AVFoundation.h frameworks to your class.
Upvotes: 6
Reputation: 3558
Youtube Tutorial explaining the full source code to make a soundboard application. However, next time you post a question you should aim to make it specific to a single problem that you have come across. Stack Overflow isn't your personal research assistant, a simple search on google for "soundboard app tutorial" would turn up plenty of results on showing you how to accomplish your goal.
Upvotes: 0