The problem with how the app is now is the first time you press any of the buttons there is a 5 second delay. After that no problem
Code:
.h File for View
#import <UIKit/UIKit.h>
#import<AVFoundation/AVAudioPlayer.h>
@interface buttonSoundViewController : UIViewController <AVAudioPlayerDelegate> {
}
-(IBAction) button1:(id)sender;
-(IBAction) button2:(id)sender;
-(IBAction) button3:(id)sender;
-(IBAction) button4:(id)sender;
-(IBAction) button5:(id)sender;
-(IBAction) button6:(id)sender;
-(IBAction) button7:(id)sender;
@end
Code:
.M File
-(IBAction) button1:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
-(IBAction) button2:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound2" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
-(IBAction) button3:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound3" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
-(IBAction) button4:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound4" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
-(IBAction) button5:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound5" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
-(IBAction) button6:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound6" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
-(IBAction) button7:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound7" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}