레코드를 기록 할 때 두 개의 NSMutableArrays를 만들고 비울 수 있습니다. 또한 NSTimer와 int가 필요합니다. 그래서 머리글에 :
NSTimer *recordTimer;
NSTimer *playTimer;
int incrementation;
NSMutableArray *timeHit;
NSMutableArray *noteHit;
헤더에 공백과 IBActions 등을 모두 포함하십시오.
사운드 버튼의 고유 한 태그가 다르게 설정하십시오.
다음 주 파일에
: (이 코드는 완벽 의심) 하구의 조금으로
-(void)viewDidLoad {
timeHit = [[NSMutableArray alloc] init];
noteHit = [[NSMutableArray alloc] init];
}
-(IBAction)record {
recordTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(timerSelector) userInfo:nil repeats:YES];
[timeHit removeAllObjects];
[noteHit removeAllObjects];
incrementation = 0;
}
-(void)timerSelector {
incrementation += 1;
}
-(IBAction)hitSoundButton:(id)sender {
int note = [sender tag];
int time = incrementation;
[timeHit addObject:[NSNumber numberWithInt:time]];
[noteHit addObject:[NSNumber numberWithInt:note]];
[self playNote:note];
}
-(IBAction)stop {
if ([recordTimer isRunning]) {
[recordTimer invalidate];
} else if ([playTimer isRunning]) {
[playTimer invalidate];
}
}
-(IBAction)playSounds {
playTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(playback) userInfo:nil repeats:YES];
incrementation = 0;
}
-(void)playback {
incrementation += 1;
if ([timeHit containsObject:[NSNumber numberWithInt:incrementation]]) {
int index = [timeHit indexOfObject:[NSNumber numberWithInt:incrementation]];
int note = [[noteHit objectAtIndex:index] intValue];
[self playNote:note];
}
}
-(void)playNote:(int)note {
//These notes would correspond to the tags of the buttons they are played by.
if (note == 1) {
//Play your first note
} else if (note == 2) {
//Play second note
} else if (note == 3) {
//And so on
} else if (note == 4) {
//etc.
}
}
, 당신은이 작업을 얻을 수 있습니다. 당신이 아마 당신이 그 중 하나를 치면 재생/녹음 버튼이 비활성화되기를 원할 것입니다. 행운을 빕니다!
연구를 수행 한 적이 있습니까? –
http://stackoverflow.com/questions/4215180/record-and-play-audio-simultaneously의 가능한 복제본 | Apple의 aurioTouch 샘플 애플리케이션에서 예제 코드를 확인하십시오. –