I would like to make a sound play when a button is pressed. Also, there is more than one sound. I am using Xcode 4.4.1 and Storyboard.
In the .h file
{
IBOutlet UIButton *playSound;
}
I would like to make a sound play when a button is pressed. Also, there is more than one sound. I am using Xcode 4.4.1 and Storyboard.
In the .h file
{
IBOutlet UIButton *playSound;
}
I have found this way, and it works for me
*Note
ClickSoundFile : Sound file name FileTypemp3 : file type mp3
I thought it would be fun to write this type example so I wrote it. It demonstrates how to play different random sound when button is pressed:
Explanation:
Add four sounds in Your project: sound1.caf, sound2.caf, sound3.caf and sound4.caf.
Import AudioToolbox framework to Your project. And include in .h
#import <AudioToolbox/AudioToolbox.h>
.Don't forget to connect Your button to buttonPressedWithSound via
IBAction
.