user1839826
user1839826

Reputation: 43

Make a button play a sound in iOS

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

Answers (3)

ankit yadav
ankit yadav

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

signal
signal

Reputation: 225

you can set button touchevent to play

Upvotes: 0

WhoaItsAFactorial
WhoaItsAFactorial

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

Related Questions