【发布时间】:2011-10-08 18:31:32
【问题描述】:
我正在制作一个包含吉他音阶教程的 iPhone 应用程序。目标是我的函数播放许多声音,直到音阶完成。
这是一个随机音阶:F G A B C D E。我录制的声音像 C.mp3、D、E、F、G、A、B、C2、D2、E2...2 是较高的音符。这是我使用的代码:
- (IBAction) playScale {
NSLog(@"s: %i", s);
NSLog(@"p: %i", pressed);
[self.player prepareToPlay];
components = [self.scale componentsSeparatedByString:@", "];
ns_NoteToPlay = [components objectAtIndex:s];
NSString *path = [[NSBundle mainBundle] pathForResource:ns_NoteToPlay ofType:@"m4a"];
NSLog(@"Path : %@", path);
self.player.delegate = self;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[self.player play];
mChord.text = ns_NoteToPlay;
NSLog(@"Nombre de notes ds Array : %i", components.count);
if ( s == 0) {
int clean;
clean = components.count + 1;
[NSTimer scheduledTimerWithTimeInterval:clean target:self selector:@selector(cleanDots) userInfo:nil repeats:NO];
}
nsNowPlayingNote = ns_NoteToPlay;
[self instrument];
s = s+1;
if ((s < components.count) && (pressed == 0)) {
[self performSelector:@selector(playScale) withObject:nil afterDelay:0.8];
}
}
这行得通。该函数播放音阶,但我找不到方法来判断何时调用较高的音符 C2。因此,当它播放D然后播放C时,C应该是C2,但仍然调用C,这是更低的。
【问题讨论】:
标签: objective-c ios cocoa-touch audio avaudioplayer