한 화면에 10 개의 사운드가 있습니다. 그리고 그들은 모두 연주하지만 한 번에 하나의 사운드 만 재생할 수 있습니다. 나는 당신이 연주하고 싶은 소리를 두들 기울 수 있기를 원하고 동시에 모두 연주한다. 그러나 연주하는 소리를 누를 때 다른 소리를 누르면 이전에 소리가 멈 춥니 다.iOS 기기에서 동시에 사운드 재생
는 여기에 내가 소리
- (IBAction)oneSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"wav"];
if (theAudio) [theAudio release];
NSError *error = nil;
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
theAudio.delegate = self;
[theAudio play];
}
- (IBAction)twoSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"wav"];
if (theAudio) [theAudio release];
NSError *error = nil;
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
theAudio.delegate = self;
[theAudio play];
}
- (IBAction)threeSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"wav"];
if (theAudio) [theAudio release];
NSError *error = nil;
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
theAudio.delegate = self;
[theAudio play];
}
덕분에 사용한 코드입니다!
어떻게하면 그 – LAA