我想创建一个类似吉他英雄游戏的应用程序。所以,我有六个按钮,名为a1,a2,a3,a4,a5,a6,播放声音。然后,我播放由吉他乐器弦组成的音乐。
我的问题是如何根据播放的音乐创建音色功能?
@Derek:我很抱歉我的英语不好。
现在,我用IB创建了六个按钮,每个按钮都有不同的声音。我使用IBAction创建按钮并使用AVAudioPlayer播放声音。这是我的代码: `
in .h
.................{
AVAudioPlayer *av1, *av2, *av3, *av4, *av5, *av6;
}
@property (nonatomic, retain) AVAudioPlayer *av1, *av2, *av3, *av4, *av5, *av6;
-(IBAction)one:(id)sender;
-(IBAction)two:(id)sender;
-(IBAction)three:(id)sender;
-(IBAction)four:(id)sender;
-(IBAction)five:(id)sender;
-(IBAction)six:(id)sender;
-(IBAction)play:(id)sender;
in.m
- (void)viewDidLoad {
[super viewDidLoad];
//load file audio dan persiapkan untuk play
//saron1
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"sp1" ofType:@"wav"];
av1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path1] error:NULL];
av1.delegate = self;
[av1 setVolume:1.0];
[av1 prepareToPlay];
//saron2
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"sp2" ofType:@"wav"];
av2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path2] error:NULL];
av2.delegate = self;
[av2 setVolume:1.0];
[av2 prepareToPlay];
//saron3
NSString *path3 = [[NSBundle mainBundle] pathForResource:@"sp3" ofType:@"wav"];
av3 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path3] error:NULL];
av3.delegate = self;
[av3 setVolume:1.0];
[av3 prepareToPlay];
//saron4
NSString *path4 = [[NSBundle mainBundle] pathForResource:@"sp4" ofType:@"wav"];
av4 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path4] error:NULL];
av4.delegate = self;
[av4 setVolume:1.0];
[av4 prepareToPlay];
//saron5
NSString *path5 = [[NSBundle mainBundle] pathForResource:@"sp5" ofType:@"wav"];
av5 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path5] error:NULL];
av5.delegate = self;
[av5 setVolume:1.0];
[av5 prepareToPlay];
//saron6
NSString *path6 = [[NSBundle mainBundle] pathForResource:@"sp6" ofType:@"wav"];
av6 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path6] error:NULL];
av6.delegate = self;
[av6 setVolume:1.0];
[av6 prepareToPlay];
}
- (IBAction)one:(id)sender{
[av1 play];
}
- (IBAction)two:(id)sender{
[av2 play];
}
- (IBAction)three:(id)sender{
[av3 play];
}
- (IBAction)four:(id)sender{
[av4 play];
}
- (IBAction)five:(id)sender{
[av5 play];
}
- (IBAction)six:(id)sender{
[av6 play];
}
av1-av5是吉他弦,av6是吉他音乐(30秒播放)。从该代码开始,当音乐播放时,如何让PlayButton按照其他按钮六到六?